bazaar: Alternative Multithreading update (Mindtraveller)

git-svn-id: svn://ultimatepp.org/upp/trunk@2046 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
ndrew2k 2010-02-09 23:30:08 +00:00
parent e2a65573b1
commit 4b943c2a2b

View file

@ -13,10 +13,11 @@ dword rdtsc();
class CallbackQueue : private NoCopy
{
public:
CallbackQueue(int _id = 0)
CallbackQueue(int _maxQueueLength = 100000, int _id = 0)
:shuttingDown(false)
,started(false)
,id(_id)
,maxQueueLength(_maxQueueLength)
{
Vector<CallbackQueue *> &q = queues.GetAdd(id);
q << this;
@ -40,10 +41,17 @@ public:
}
#define LOCK_ADD_UNLOCK \
bool addSem = true; \
qMutex.Enter(); \
if (queue.GetCount() >= maxQueueLength) \
{ \
queue.DropHead(); \
addSem = false; \
} \
queue.AddTail(e); \
qMutex.Leave(); \
qSemaphore.Release();
if (addSem) \
qSemaphore.Release();
void ClearQueue()
{
@ -169,6 +177,7 @@ public:
}
}
void SetMaxQueueLength(int mql) {qMutex.Enter(); maxQueueLength = mql; while (queue.GetCount() >= mql) queue.DropHead(); qMutex.Leave();}
int GetTasksCount() {qMutex.Enter(); int out=queue.GetCount(); qMutex.Leave(); return out;}
bool IsShutdown() {return shuttingDown;}
@ -323,12 +332,13 @@ private:
bool shuttingDown;
bool started;
int id;
int maxQueueLength;
};
class CallbackThread : public CallbackQueue, protected Thread
{
public:
CallbackThread(int id = 0) :CallbackQueue(id) {}
CallbackThread(int maxQueueLength = 100000, int id = 0) :CallbackQueue(maxQueueLength, id) {}
virtual ~CallbackThread() {Shutdown();}
virtual void Start()