-rw-r--r-- | noncore/multimedia/opieplayer2/threadutil.cpp | 17 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/threadutil.h | 6 |
2 files changed, 11 insertions, 12 deletions
diff --git a/noncore/multimedia/opieplayer2/threadutil.cpp b/noncore/multimedia/opieplayer2/threadutil.cpp index 7a9e1a4..ff38b1e 100644 --- a/noncore/multimedia/opieplayer2/threadutil.cpp +++ b/noncore/multimedia/opieplayer2/threadutil.cpp | |||
@@ -130,12 +130,16 @@ struct Thread::Data | |||
130 | 130 | ||
131 | pthread_t self; | 131 | pthread_t self; |
132 | Mutex guard; | 132 | Mutex guard; |
133 | bool isRunning; | 133 | bool isRunning; |
134 | 134 | ||
135 | WaitCondition finishCondition; | 135 | WaitCondition finishCondition; |
136 | |||
137 | Thread *thr; | ||
138 | |||
139 | void run() { thr->run(); } | ||
136 | }; | 140 | }; |
137 | 141 | ||
138 | extern "C" | 142 | extern "C" |
139 | { | 143 | { |
140 | 144 | ||
141 | static void terminate_thread( void *arg ) | 145 | static void terminate_thread( void *arg ) |
@@ -146,32 +150,33 @@ static void terminate_thread( void *arg ) | |||
146 | 150 | ||
147 | AutoLock locker( data->guard ); | 151 | AutoLock locker( data->guard ); |
148 | data->isRunning = false; | 152 | data->isRunning = false; |
149 | data->finishCondition.wakeAll(); | 153 | data->finishCondition.wakeAll(); |
150 | } | 154 | } |
151 | 155 | ||
152 | void *_threadutil_start_thread( void *arg ) | 156 | static void *start_thread( void *arg ) |
153 | { | 157 | { |
154 | Thread *thr = ( Thread* )arg; | 158 | Thread::Data *data = ( Thread::Data* )arg; |
155 | 159 | ||
156 | pthread_cleanup_push( terminate_thread, thr->d ); | 160 | pthread_cleanup_push( terminate_thread, data ); |
157 | 161 | ||
158 | thr->d->isRunning = true; | 162 | data->isRunning = true; |
159 | thr->run(); | 163 | data->run(); |
160 | 164 | ||
161 | pthread_cleanup_pop( true ); | 165 | pthread_cleanup_pop( true ); |
162 | 166 | ||
163 | Thread::exit(); | 167 | Thread::exit(); |
164 | return 0; // never reached | 168 | return 0; // never reached |
165 | } | 169 | } |
166 | 170 | ||
167 | } | 171 | } |
168 | 172 | ||
169 | Thread::Thread() | 173 | Thread::Thread() |
170 | : d( new Data ) | 174 | : d( new Data ) |
171 | { | 175 | { |
176 | d->thr = this; | ||
172 | } | 177 | } |
173 | 178 | ||
174 | Thread::~Thread() | 179 | Thread::~Thread() |
175 | { | 180 | { |
176 | assert( d->isRunning == false ); | 181 | assert( d->isRunning == false ); |
177 | delete d; | 182 | delete d; |
@@ -186,13 +191,13 @@ void Thread::start() | |||
186 | return; | 191 | return; |
187 | } | 192 | } |
188 | 193 | ||
189 | pthread_attr_t attributes; | 194 | pthread_attr_t attributes; |
190 | pthread_attr_init( &attributes ); | 195 | pthread_attr_init( &attributes ); |
191 | pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM ); | 196 | pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM ); |
192 | int err = pthread_create( &d->self, &attributes, _threadutil_start_thread, ( void* )this ); | 197 | int err = pthread_create( &d->self, &attributes, start_thread, ( void* )d ); |
193 | if ( err != 0 ) { | 198 | if ( err != 0 ) { |
194 | qDebug( "ThreadUtil::Thread::start() : can't create thread: %s", strerror( err ) ); | 199 | qDebug( "ThreadUtil::Thread::start() : can't create thread: %s", strerror( err ) ); |
195 | pthread_attr_destroy( &attributes ); | 200 | pthread_attr_destroy( &attributes ); |
196 | return; | 201 | return; |
197 | } | 202 | } |
198 | pthread_attr_destroy( &attributes ); | 203 | pthread_attr_destroy( &attributes ); |
diff --git a/noncore/multimedia/opieplayer2/threadutil.h b/noncore/multimedia/opieplayer2/threadutil.h index 21ae6b2..2fd0c68 100644 --- a/noncore/multimedia/opieplayer2/threadutil.h +++ b/noncore/multimedia/opieplayer2/threadutil.h | |||
@@ -23,17 +23,12 @@ | |||
23 | #include <qvaluelist.h> | 23 | #include <qvaluelist.h> |
24 | #include <qobject.h> | 24 | #include <qobject.h> |
25 | #include <qguardedptr.h> | 25 | #include <qguardedptr.h> |
26 | 26 | ||
27 | class QSocketNotifier; | 27 | class QSocketNotifier; |
28 | 28 | ||
29 | extern "C" | ||
30 | { | ||
31 | void *_threadutil_start_thread( void* ); | ||
32 | } | ||
33 | |||
34 | namespace ThreadUtil | 29 | namespace ThreadUtil |
35 | { | 30 | { |
36 | 31 | ||
37 | class Mutex | 32 | class Mutex |
38 | { | 33 | { |
39 | friend class WaitCondition; | 34 | friend class WaitCondition; |
@@ -85,13 +80,12 @@ namespace ThreadUtil | |||
85 | WaitCondition( const WaitCondition & ); | 80 | WaitCondition( const WaitCondition & ); |
86 | WaitCondition &operator=( const WaitCondition & ); | 81 | WaitCondition &operator=( const WaitCondition & ); |
87 | }; | 82 | }; |
88 | 83 | ||
89 | class Thread | 84 | class Thread |
90 | { | 85 | { |
91 | friend void *::_threadutil_start_thread( void* ); | ||
92 | public: | 86 | public: |
93 | struct Data; | 87 | struct Data; |
94 | 88 | ||
95 | Thread(); | 89 | Thread(); |
96 | virtual ~Thread(); | 90 | virtual ~Thread(); |
97 | 91 | ||