- overhaul of thread processing, especially in the menus, things now freeze much less and should be more reliable

This commit is contained in:
Mark Vejvoda
2011-01-02 06:46:48 +00:00
parent 9150701e70
commit 2b1732e27e
17 changed files with 435 additions and 507 deletions

View File

@@ -31,13 +31,21 @@ protected:
Mutex mutexRunning;
Mutex mutexQuit;
Mutex mutexBeginExecution;
Mutex mutexDeleteSelfOnExecutionDone;
Mutex mutexThreadObjectAccessor;
Mutex mutexExecutingTask;
bool executingTask;
bool quit;
bool running;
string uniqueID;
bool hasBeginExecution;
bool deleteSelfOnExecutionDone;
virtual void setQuitStatus(bool value);
void deleteSelfIfRequired();
public:
BaseThread();
@@ -47,17 +55,26 @@ public:
virtual void signalQuit();
virtual bool getQuitStatus();
virtual bool getRunningStatus();
virtual bool getHasBeginExecution();
virtual void setHasBeginExecution(bool value);
static bool shutdownAndWait(BaseThread *ppThread);
virtual bool shutdownAndWait();
virtual bool canShutdown() { return true; }
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed=false);
virtual bool getDeleteSelfOnExecutionDone();
virtual void setDeleteSelfOnExecutionDone(bool value);
void setUniqueID(string value) { uniqueID = value; }
string getUniqueID() { return uniqueID; }
virtual void setRunningStatus(bool value);
void setExecutingTask(bool value);
bool getExecutingTask();
Mutex * getMutexThreadObjectAccessor() { return &mutexThreadObjectAccessor; }
};
class RunningStatusSafeWrapper {
@@ -85,6 +102,32 @@ public:
}
};
class ExecutingTaskSafeWrapper {
protected:
BaseThread *thread;
public:
ExecutingTaskSafeWrapper(BaseThread *thread) {
this->thread = thread;
Enable();
}
~ExecutingTaskSafeWrapper() {
Disable();
}
void Enable() {
if(this->thread != NULL) {
this->thread->setExecutingTask(true);
}
}
void Disable() {
if(this->thread != NULL) {
this->thread->setExecutingTask(false);
}
}
};
}}//end namespace
#endif

View File

@@ -48,7 +48,7 @@ public:
//
class SimpleTaskCallbackInterface {
public:
virtual void simpleTask() = 0;
virtual void simpleTask(BaseThread *callingThread) = 0;
};
class SimpleTaskThread : public BaseThread
@@ -63,9 +63,6 @@ protected:
bool taskSignalled;
bool needTaskSignal;
Mutex mutexExecutingTask;
bool executingTask;
public:
SimpleTaskThread();
SimpleTaskThread(SimpleTaskCallbackInterface *simpleTaskInterface,
@@ -73,12 +70,10 @@ public:
unsigned int millisecsBetweenExecutions=0,
bool needTaskSignal = false);
virtual void execute();
virtual bool canShutdown();
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed=false);
void setTaskSignalled(bool value);
bool getTaskSignalled();
void setExecutingTask(bool value);
bool getExecutingTask();
};
// =====================================================

View File

@@ -121,7 +121,7 @@ public:
Socket();
virtual ~Socket();
virtual void simpleTask();
virtual void simpleTask(BaseThread *callingThread);
static int getBroadCastPort() { return broadcast_portno; }
static void setBroadCastPort(int value) { broadcast_portno = value; }