[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "workqueue" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Mon Apr 18 16:14:00 CDT 2011
branch "workqueue" has been updated
via 4c34a2ae84137864c55e7e62d72b83ed8faf9acc (commit)
from 124bbd1334c58303bfacd7b420473deb80adcd37 (commit)
Summary of changes:
ThreadPool/src/CMakeLists.txt | 1 +
ThreadPool/src/ThreadPool.cpp | 82 ----------------------------
ThreadPool/src/WorkerThread.cpp | 113 +++++++++++++++++++++++++++++++++++++++
3 files changed, 114 insertions(+), 82 deletions(-)
create mode 100644 ThreadPool/src/WorkerThread.cpp
- Log -----------------------------------------------------------------
commit 4c34a2ae84137864c55e7e62d72b83ed8faf9acc
Author: Mark Michelson <mmichelson at digium.com>
Date: Mon Apr 18 16:13:19 2011 -0500
Separate WorkerThread code into its own source file.
I think this helps readability a LOT.
diff --git a/ThreadPool/src/CMakeLists.txt b/ThreadPool/src/CMakeLists.txt
index 110e410..ed3a64c 100644
--- a/ThreadPool/src/CMakeLists.txt
+++ b/ThreadPool/src/CMakeLists.txt
@@ -19,6 +19,7 @@ asterisk_scf_component_add_file(ThreadPool
asterisk_scf_component_add_file(ThreadPool
../include/AsteriskSCF/WorkerThread.h)
asterisk_scf_component_add_file(ThreadPool ThreadPool.cpp)
+asterisk_scf_component_add_file(ThreadPool WorkerThread.cpp)
asterisk_scf_component_add_boost_libraries(ThreadPool thread)
asterisk_scf_component_build_library(ThreadPool)
diff --git a/ThreadPool/src/ThreadPool.cpp b/ThreadPool/src/ThreadPool.cpp
index cc8542f..f8b55fb 100644
--- a/ThreadPool/src/ThreadPool.cpp
+++ b/ThreadPool/src/ThreadPool.cpp
@@ -29,88 +29,6 @@ namespace ThreadPool
using namespace AsteriskSCF::System::ThreadPool::V1;
using namespace AsteriskSCF::System::WorkQueue::V1;
-class WorkerThreadPriv
-{
-public:
- WorkerThreadPriv(const QueuePtr& workQueue, WorkerThreadListener *listener,
- WorkerThread *workerThread)
- : mState(Active), mListener(listener), mQueue(workQueue), mWorkerThread(workerThread),
- mThread(boost::bind(&WorkerThreadPriv::active, this)) { }
-
- void active()
- {
- while (mState == Active)
- {
- if (!mQueue->executeWork())
- {
- idle();
- }
- }
-
- // Reaching this portion means the thread is
- // on death's door. It may have been killed while
- // it was idle, in which case it can just die
- // peacefully. If it's a zombie, though, then
- // it needs to let the ThreadPoolImpl know so
- // that the thread can be removed from the
- // vector of zombie threads.
- if (mState == Zombie)
- {
- mListener->zombieThreadDead(mWorkerThread);
- }
- }
-
- void idle()
- {
- {
- boost::unique_lock<boost::mutex> lock(mLock);
- // If we've been turned into a zombie while we
- // were active, then just go ahead and return.
- if (mState == Zombie)
- {
- return;
- }
-
- // Otherwise, we'll set ourselves idle and wait
- // for a poke
- mState = Idle;
- }
-
- mListener->activeThreadIdle(mWorkerThread);
-
- {
- boost::unique_lock<boost::mutex> lock(mLock);
- while (mState == Idle)
- {
- mCond.wait(lock);
- }
- }
- }
-
- ThreadState mState;
- WorkerThreadListener *mListener;
- QueuePtr mQueue;
- WorkerThread *mWorkerThread;
- boost::condition_variable mCond;
- boost::mutex mLock;
- boost::thread mThread;
-};
-
-WorkerThread::WorkerThread(const QueuePtr& workQueue, WorkerThreadListener *listener)
- : mPriv(new WorkerThreadPriv(workQueue, listener, this)) { }
-
-void WorkerThread::poke(ThreadState newState)
-{
- boost::unique_lock<boost::mutex> lock(mPriv->mLock);
- mPriv->mState = newState;
- mPriv->mCond.notify_one();
-}
-
-void WorkerThread::join()
-{
- mPriv->mThread.join();
-}
-
class ThreadQueueListener;
typedef std::vector<WorkerThread*> ThreadContainer;
diff --git a/ThreadPool/src/WorkerThread.cpp b/ThreadPool/src/WorkerThread.cpp
new file mode 100644
index 0000000..b65a355
--- /dev/null
+++ b/ThreadPool/src/WorkerThread.cpp
@@ -0,0 +1,113 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#include <boost/thread.hpp>
+
+#include <AsteriskSCF/System/WorkQueue/WorkQueueIf.h>
+#include <AsteriskSCF/WorkerThread.h>
+
+namespace AsteriskSCF
+{
+namespace ThreadPool
+{
+
+using namespace AsteriskSCF::System::ThreadPool::V1;
+using namespace AsteriskSCF::System::WorkQueue::V1;
+
+class WorkerThreadPriv
+{
+public:
+ WorkerThreadPriv(const QueuePtr& workQueue, WorkerThreadListener *listener,
+ WorkerThread *workerThread)
+ : mState(Active), mListener(listener), mQueue(workQueue), mWorkerThread(workerThread),
+ mThread(boost::bind(&WorkerThreadPriv::active, this)) { }
+
+ void active()
+ {
+ while (mState == Active)
+ {
+ if (!mQueue->executeWork())
+ {
+ idle();
+ }
+ }
+
+ // Reaching this portion means the thread is
+ // on death's door. It may have been killed while
+ // it was idle, in which case it can just die
+ // peacefully. If it's a zombie, though, then
+ // it needs to let the ThreadPoolImpl know so
+ // that the thread can be removed from the
+ // vector of zombie threads.
+ if (mState == Zombie)
+ {
+ mListener->zombieThreadDead(mWorkerThread);
+ }
+ }
+
+ void idle()
+ {
+ {
+ boost::unique_lock<boost::mutex> lock(mLock);
+ // If we've been turned into a zombie while we
+ // were active, then just go ahead and return.
+ if (mState == Zombie)
+ {
+ return;
+ }
+
+ // Otherwise, we'll set ourselves idle and wait
+ // for a poke
+ mState = Idle;
+ }
+
+ mListener->activeThreadIdle(mWorkerThread);
+
+ {
+ boost::unique_lock<boost::mutex> lock(mLock);
+ while (mState == Idle)
+ {
+ mCond.wait(lock);
+ }
+ }
+ }
+
+ ThreadState mState;
+ WorkerThreadListener *mListener;
+ QueuePtr mQueue;
+ WorkerThread *mWorkerThread;
+ boost::condition_variable mCond;
+ boost::mutex mLock;
+ boost::thread mThread;
+};
+
+WorkerThread::WorkerThread(const QueuePtr& workQueue, WorkerThreadListener *listener)
+ : mPriv(new WorkerThreadPriv(workQueue, listener, this)) { }
+
+void WorkerThread::poke(ThreadState newState)
+{
+ boost::unique_lock<boost::mutex> lock(mPriv->mLock);
+ mPriv->mState = newState;
+ mPriv->mCond.notify_one();
+}
+
+void WorkerThread::join()
+{
+ mPriv->mThread.join();
+}
+
+}; //end namespace ThreadPool
+}; //end namespace AsteriskSCF
-----------------------------------------------------------------------
--
asterisk-scf/integration/ice-util-cpp.git
More information about the asterisk-scf-commits
mailing list