Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
diff --git a/util/events.cpp b/util/events.cpp
index e80c41b3..d5c8a32e 100644
--- a/util/events.cpp
+++ b/util/events.cpp
@@ -1,61 +1,61 @@
#ifdef USE_SDL
#include <SDL.h>
#endif
#include "events.h"
#include "shutdown_exception.h"
#include "thread.h"
#include "funcs.h"
namespace Util{
EventManager::EventManager(){
}
#ifdef USE_SDL
void EventManager::runSDL(){
SDL_Event event;
while (SDL_PollEvent(&event) == 1){
switch (event.type){
case SDL_QUIT : {
dispatch(CloseWindow);
break;
}
default : {
break;
}
}
}
}
#endif
void EventManager::run(){
#ifdef USE_SDL
runSDL();
#endif
}
/* kill the program if the user requests */
-void EventManager::waitForThread(Thread & thread){
+void EventManager::waitForThread(WaitThread & thread){
while (!thread.isRunning()){
try{
run();
} catch (const ShutdownException & death){
thread.kill();
throw death;
}
Util::rest(10);
}
}
EventManager::~EventManager(){
}
void EventManager::dispatch(Event type){
switch (type){
case CloseWindow : {
throw ShutdownException();
}
}
}
}
diff --git a/util/events.h b/util/events.h
index 3b19da37..26ec130f 100644
--- a/util/events.h
+++ b/util/events.h
@@ -1,34 +1,34 @@
#ifndef _paintown_events_h
#define _paintown_events_h
/* handles global events from the system such as
* window manager events (press X button)
* keyboard/mouse/joystick input (for some backends like SDL)
*/
namespace Util{
-class Thread;
+class WaitThread;
class EventManager{
public:
EventManager();
virtual void run();
- virtual void waitForThread(Thread & thread);
+ virtual void waitForThread(WaitThread & thread);
virtual ~EventManager();
private:
enum Event{
CloseWindow
};
virtual void dispatch(Event type);
#ifdef USE_SDL
virtual void runSDL();
#endif
};
}
#endif
diff --git a/util/thread.cpp b/util/thread.cpp
index 8ab6711b..02facd4e 100644
--- a/util/thread.cpp
+++ b/util/thread.cpp
@@ -1,77 +1,77 @@
#include <pthread.h>
#include "thread.h"
namespace Util{
-Thread::Thread():
+WaitThread::WaitThread():
done(false){
pthread_mutex_init(&doneLock, NULL);
}
-Thread::Thread(void * (*thread)(void*), void * arg){
+WaitThread::WaitThread(void * (*thread)(void*), void * arg){
pthread_mutex_init(&doneLock, NULL);
start(thread, arg);
}
static void * do_thread(void * arg){
- Thread * thread = (Thread *) arg;
+ WaitThread * thread = (WaitThread *) arg;
thread->doRun();
return NULL;
}
-void Thread::doRun(){
+void WaitThread::doRun(){
this->function(this->arg);
pthread_mutex_lock(&doneLock);
this->done = true;
pthread_mutex_unlock(&doneLock);
}
-void Thread::start(void * (*thread)(void *), void * arg){
+void WaitThread::start(void * (*thread)(void *), void * arg){
done = false;
this->arg = arg;
this->function = thread;
pthread_create(&this->thread, NULL, do_thread, this);
}
-bool Thread::isRunning(){
+bool WaitThread::isRunning(){
pthread_mutex_lock(&doneLock);
bool what = done;
pthread_mutex_unlock(&doneLock);
return what;
}
-void Thread::kill(){
+void WaitThread::kill(){
/* FIXME: cancel is not implemented for libogc, find another way.
* thread suspend/resume is there, though.
*/
#if !defined(WII)
pthread_cancel(thread);
#endif
pthread_join(thread, NULL);
}
-Thread::~Thread(){
+WaitThread::~WaitThread(){
/* FIXME: Should we join the thread? */
/* pthread_join(thread); */
}
ThreadBoolean::ThreadBoolean(volatile bool & what, pthread_mutex_t & lock):
what(what),
lock(lock){
}
bool ThreadBoolean::get(){
pthread_mutex_lock(&lock);
bool b = what;
pthread_mutex_unlock(&lock);
return b;
}
void ThreadBoolean::set(bool value){
pthread_mutex_lock(&lock);
what = value;
pthread_mutex_unlock(&lock);
}
}
diff --git a/util/thread.h b/util/thread.h
index 096755b5..0220a52e 100644
--- a/util/thread.h
+++ b/util/thread.h
@@ -1,51 +1,51 @@
#ifndef _paintown_thread_h
#define _paintown_thread_h
#include <pthread.h>
namespace Util{
-class Thread{
+class WaitThread{
public:
/* does not start a new thread yet */
- Thread();
+ WaitThread();
/* starts a thread */
- Thread(void * (*thread)(void*), void * arg);
+ WaitThread(void * (*thread)(void*), void * arg);
/* starts a thread */
void start(void * (*thread)(void *), void * arg);
bool isRunning();
void kill();
- virtual ~Thread();
+ virtual ~WaitThread();
public:
/* actually runs the thread */
void doRun();
protected:
pthread_mutex_t doneLock;
pthread_t thread;
volatile bool done;
void * arg;
void * (*function)(void *);
};
/* wraps a boolean with lock/unlock while checking/setting it */
class ThreadBoolean{
public:
ThreadBoolean(volatile bool & what, pthread_mutex_t & lock);
bool get();
void set(bool value);
protected:
volatile bool & what;
pthread_mutex_t & lock;
};
}
#endif

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 12:33 PM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69052
Default Alt Text
(5 KB)

Event Timeline