From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- mpeglib/lib/util/abstract/threadQueue.cpp | 108 ++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 mpeglib/lib/util/abstract/threadQueue.cpp (limited to 'mpeglib/lib/util/abstract/threadQueue.cpp') diff --git a/mpeglib/lib/util/abstract/threadQueue.cpp b/mpeglib/lib/util/abstract/threadQueue.cpp new file mode 100644 index 00000000..1b130ba9 --- /dev/null +++ b/mpeglib/lib/util/abstract/threadQueue.cpp @@ -0,0 +1,108 @@ +/* + fifo waitqueue for threads.(Multi-in, single out) + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + +#include "threadQueue.h" + +#define _MAX_THREAD_IN_QUEUE 5 + +#include + +using namespace std; + +// +// WaitThreadEntry class [START] +// + +WaitThreadEntry::WaitThreadEntry() { + abs_thread_cond_init(&waitCond); +} + + +WaitThreadEntry::~WaitThreadEntry() { + abs_thread_cond_destroy(&waitCond); +} + +// +// WaitThreadEntry class [END] +// + + +ThreadQueue::ThreadQueue() { + waitThreadEntries=new WaitThreadEntry* [_MAX_THREAD_IN_QUEUE]; + int i; + for(i=0;i<_MAX_THREAD_IN_QUEUE;i++) { + waitThreadEntries[i]=new WaitThreadEntry(); + } + abs_thread_mutex_init(&queueMut); + insertPos=0; + removePos=0; + size=0; +} + + +ThreadQueue::~ThreadQueue() { + abs_thread_mutex_lock(&queueMut); + if (size != 0) { + cout << "Aieee! Make sure that all threads are out of ThreadQueue"<waitCond); + insertPos++; + // wrap counter + if (insertPos == _MAX_THREAD_IN_QUEUE) { + insertPos=0; + } + abs_thread_cond_wait(waitCond,&queueMut); + abs_thread_mutex_unlock(&queueMut); +} + + +void ThreadQueue::releaseExclusiveAccess() { + abs_thread_mutex_lock(&queueMut); + if (size == 0) { + abs_thread_mutex_unlock(&queueMut); + return; + } + // wake up next thread + abs_thread_cond_t* waitCond=&(waitThreadEntries[removePos]->waitCond); + removePos++; + // wrap counter + if (removePos == _MAX_THREAD_IN_QUEUE) { + removePos=0; + } + size--; + abs_thread_cond_signal(waitCond); + abs_thread_mutex_unlock(&queueMut); +} + -- cgit v1.2.1