source: trunk/src/platform/ps3/threadbase.h @ 1097

Last change on this file since 1097 was 1097, checked in by sam, 9 years ago

ps3: start implementing the PS3 threading system, and port the new
Mandelbrot shader code to Cg.

  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11//
12// The ThreadBase class
13// --------------------
14//
15
16#if !defined __LOL_THREADBASE_H__
17#define __LOL_THREADBASE_H__
18
19#include <sys/ppu_thread.h>
20#include <sys/event.h>
21
22namespace lol
23{
24
25class MutexBase
26{
27public:
28    MutexBase()
29    {
30        sys_lwmutex_attribute_t attr;
31        sys_lwmutex_attribute_initialize(attr);
32        sys_lwmutex_create(&m_mutex, &attr);
33    }
34
35    ~MutexBase()
36    {
37        while (sys_lwmutex_destroy(&m_mutex) == EBUSY)
38            ;
39    }
40
41    void Lock()
42    {
43        sys_lwmutex_lock(&m_mutex, 0);
44    }
45
46    void Unlock()
47    {
48        sys_lwmutex_unlock(&m_mutex);
49    }
50
51private:
52    sys_lwmutex_t m_mutex;
53};
54
55class ConditionBase
56{
57public:
58    ConditionBase()
59    {
60    }
61
62    ~ConditionBase()
63    {
64    }
65
66    void Acquire()
67    {
68    }
69
70    void Release()
71    {
72    }
73
74    void Wait()
75    {
76    }
77
78    void Notify()
79    {
80    }
81
82private:
83};
84
85class ThreadBase
86{
87public:
88    ThreadBase(void *(*fn)(void *), void *data)
89    {
90        /* FIXME: choose priority more wisely */
91        sys_ppu_thread_create(&m_thread, (void (*)(uint64_t))fn,
92                              (uint64_t)data, 1000, 0, 0, "new thread");
93    }
94
95    virtual ~ThreadBase()
96    {
97        sys_ppu_thread_join(m_thread, NULL);
98    }
99
100private:
101    sys_ppu_thread_t m_thread;
102};
103
104} /* namespace lol */
105
106#endif // __LOL_THREADBASE_H__
107
Note: See TracBrowser for help on using the repository browser.