1 //=============================================================================
2 //
3 // Adventure Game Studio (AGS)
4 //
5 // Copyright (C) 1999-2011 Chris Jones and 2011-20xx others
6 // The full list of copyright holders can be found in the Copyright.txt
7 // file, which is part of this source code distribution.
8 //
9 // The AGS source code is provided under the Artistic License 2.0.
10 // A copy of this license can be found in the file License.txt and at
11 // http://www.opensource.org/licenses/artistic-license-2.0.php
12 //
13 //=============================================================================
14 
15 #ifndef __AGS_EE_PLATFORM__THREAD_WII_H
16 #define __AGS_EE_PLATFORM__THREAD_WII_H
17 
18 #include <gccore.h>
19 
20 namespace AGS
21 {
22 namespace Engine
23 {
24 
25 
26 class WiiThread : public BaseThread
27 {
28 public:
WiiThread()29   WiiThread()
30   {
31     _running = false;
32   }
33 
~WiiThread()34   ~WiiThread()
35   {
36     Stop();
37   }
38 
Create(AGSThreadEntry entryPoint,bool looping)39   inline bool Create(AGSThreadEntry entryPoint, bool looping)
40   {
41     _looping = looping;
42     _entry = entryPoint;
43 
44     // Thread creation is delayed till the thread is started
45     return true;
46   }
47 
Start()48   inline bool Start()
49   {
50     if (!_running)
51     {
52       _running = (LWP_CreateThread(&_thread, _thread_start, this, 0, 8 * 1024, 64) != 0);
53 
54       return _running;
55     }
56     else
57     {
58       return false;
59     }
60   }
61 
Stop()62   bool Stop()
63   {
64     if (_running)
65     {
66       if (_looping)
67       {
68         _looping = false;
69       }
70 
71       LWP_JoinThread(_thread, NULL);
72 
73       _running = false;
74       return true;
75     }
76     else
77     {
78       return false;
79     }
80   }
81 
82 private:
83   lwp_t     _thread;
84   bool      _running;
85   bool      _looping;
86 
87   AGSThreadEntry _entry;
88 
_thread_start(void * arg)89   static void *_thread_start(void *arg)
90   {
91     AGSThreadEntry entry = ((WiiThread *)arg)->_entry;
92     bool *looping = &((WiiThread *)arg)->_looping;
93 
94     do
95     {
96       entry();
97     }
98     while (*looping);
99 
100     return NULL;
101   }
102 };
103 
104 
105 typedef WiiThread Thread;
106 
107 
108 } // namespace Engine
109 } // namespace AGS
110 
111 #endif // __AGS_EE_PLATFORM__THREAD_WII_H
112