summaryrefslogtreecommitdiffstats
path: root/src/ThreadPool.h
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2011-01-12 07:29:49 -0800
committerGlenn Kasten <gkasten@google.com>2011-01-12 09:25:01 -0800
commit262059f71a68edc5e510427c63f5f1623d3672a8 (patch)
tree4a9ac2c5e7fe14051e75be499dd9804adf4354e2 /src/ThreadPool.h
parent6b158877242b43a0c0f63b56b035c74207b71a34 (diff)
downloadandroid_frameworks_wilhelm-262059f71a68edc5e510427c63f5f1623d3672a8.tar.gz
android_frameworks_wilhelm-262059f71a68edc5e510427c63f5f1623d3672a8.tar.bz2
android_frameworks_wilhelm-262059f71a68edc5e510427c63f5f1623d3672a8.zip
Directory re-organization
Change-Id: I8e3f12a22e765d36ddefd87edf204735b25474f6
Diffstat (limited to 'src/ThreadPool.h')
-rw-r--r--src/ThreadPool.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/ThreadPool.h b/src/ThreadPool.h
new file mode 100644
index 0000000..2641ed0
--- /dev/null
+++ b/src/ThreadPool.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/** \file ThreadPool.h ThreadPool interface */
+
+/** \brief Closure represents a deferred computation */
+
+typedef struct {
+ void (*mHandler)(void *, int);
+ void *mContext;
+ int mParameter;
+} Closure;
+
+/** \brief ThreadPool manages a pool of worker threads that execute Closures */
+
+typedef struct {
+ unsigned mInitialized; ///< Indicates which of the following 3 fields are initialized
+ pthread_mutex_t mMutex;
+ pthread_cond_t mCondNotFull; ///< Signalled when a client thread could be unblocked
+ pthread_cond_t mCondNotEmpty; ///< Signalled when a worker thread could be unblocked
+ SLboolean mShutdown; ///< Whether shutdown of thread pool has been requested
+ unsigned mWaitingNotFull; ///< Number of client threads waiting to enqueue
+ unsigned mWaitingNotEmpty; ///< Number of worker threads waiting to dequeue
+ unsigned mMaxClosures; ///< Number of slots in circular buffer for closures, not counting spare
+ unsigned mMaxThreads; ///< Number of worker threads
+ Closure **mClosureArray; ///< The circular buffer of closures
+ Closure **mClosureFront, **mClosureRear;
+ /// Saves a malloc in the typical case
+#define CLOSURE_TYPICAL 15
+ Closure *mClosureTypical[CLOSURE_TYPICAL+1];
+ pthread_t *mThreadArray; ///< The worker threads
+#ifdef ANDROID
+#define THREAD_TYPICAL 0
+#else
+#define THREAD_TYPICAL 4
+#endif
+ pthread_t mThreadTypical[THREAD_TYPICAL];
+} ThreadPool;
+
+extern SLresult ThreadPool_init(ThreadPool *tp, unsigned maxClosures, unsigned maxThreads);
+extern void ThreadPool_deinit(ThreadPool *tp);
+extern SLresult ThreadPool_add(ThreadPool *tp, void (*handler)(void *, int), void *context,
+ int parameter);
+extern Closure *ThreadPool_remove(ThreadPool *tp);