1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     os_Task.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev:$
14  *---------------------------------------------------------------------------*/
15 
16 /* Please see man pages for details
17 
18 
19 
20 
21 
22 
23 
24 
25 */
26 
27 #ifndef NN_OS_OS_TASK_H_
28 #define NN_OS_OS_TASK_H_
29 
30 #include <nn/os/os_Synchronization.h>
31 #include <nn/fnd/fnd_Queue.h>
32 #include <nn/util/util_NonCopyable.h>
33 
34 #ifdef __cplusplus
35 
36 namespace nn { namespace os {
37 
38 
39 /*
40 
41 
42 
43 
44 */
45 class ITask
46 {
47 public:
48     virtual void Invoke() = 0;
~ITask()49     virtual ~ITask() {}
50 };
51 
52 /*
53 
54 
55 
56 */
57 class QueueableTask : public nn::fnd::IntrusiveQueue<QueueableTask>::Item, public ITask
58 {
59 public:
60     /*
61 
62 
63 
64      */
65     virtual void Invoke() = 0;
66 };
67 
68 /*
69 
70 
71 
72 */
73 class QueueableWaitTask : private QueueableTask
74 {
75 public:
76     /* Please see man pages for details
77 
78 
79 
80      */
81     virtual nn::os::WaitObject* GetWaitObject() = 0;
82 
AsNonWaitableTask()83     QueueableTask* AsNonWaitableTask() { return this; }
84 
85     friend class IWaitTaskInvoker;
86 };
87 
88 class ITaskInvoker
89 {
90 public:
91     virtual void AddTask(QueueableTask* task) = 0;
~ITaskInvoker()92     virtual ~ITaskInvoker() {}
93     // TODO: Priority settings, etc.
94 };
95 
96 class IWaitTaskInvoker : public ITaskInvoker
97 {
98 public:
99     virtual void AddWaitTask(QueueableWaitTask* task) = 0;
100 protected:
GetWaitTaskPointer(QueueableTask * p)101     static QueueableWaitTask* GetWaitTaskPointer(QueueableTask* p) { return static_cast<QueueableWaitTask*>(p); }
102 };
103 
104 }}
105 
106 #endif
107 
108 #endif // NN_OS_OS_THREADPOOL_H_
109