summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/Thread.h
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2006-11-29 14:36:08 +0000
committerAlan Conway <aconway@apache.org>2006-11-29 14:36:08 +0000
commitb13e1a24fcca8797b7be5a242f164afbe17ec4f6 (patch)
treeef0362e52c125bc75b07ef3e374dabfa52254e98 /cpp/src/qpid/sys/Thread.h
parent16d818e749462daf5e0e43079b2e48991646c619 (diff)
downloadqpid-python-b13e1a24fcca8797b7be5a242f164afbe17ec4f6.tar.gz
Posix EventChannel implementation using epoll. Placeholder for kevents.
Dynamic thread pool EventChannelThreads to serve EventChannel. Misc cleanup/enhancements. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@480582 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys/Thread.h')
-rw-r--r--cpp/src/qpid/sys/Thread.h42
1 files changed, 39 insertions, 3 deletions
diff --git a/cpp/src/qpid/sys/Thread.h b/cpp/src/qpid/sys/Thread.h
index 2aad7c24d7..37f714dd6c 100644
--- a/cpp/src/qpid/sys/Thread.h
+++ b/cpp/src/qpid/sys/Thread.h
@@ -40,11 +40,17 @@ namespace sys {
class Thread
{
public:
+ inline static Thread current();
+ inline static void yield();
+
inline Thread();
inline explicit Thread(qpid::sys::Runnable*);
+ inline explicit Thread(qpid::sys::Runnable&);
+
inline void join();
- inline static Thread current();
+ inline long id();
+
private:
#ifdef USE_APR
static void* APR_THREAD_FUNC runRunnable(apr_thread_t* thread, void *data);
@@ -68,12 +74,21 @@ Thread::Thread(Runnable* runnable) {
apr_thread_create(&thread, 0, runRunnable, runnable, APRPool::get()));
}
+Thread::Thread(Runnable& runnable) {
+ CHECK_APR_SUCCESS(
+ apr_thread_create(&thread, 0, runRunnable, &runnable, APRPool::get()));
+}
+
void Thread::join(){
apr_status_t status;
if (thread != 0)
CHECK_APR_SUCCESS(apr_thread_join(&status, thread));
}
+long Thread::id() {
+ return long(thread);
+}
+
Thread::Thread(apr_thread_t* t) : thread(t) {}
Thread Thread::current(){
@@ -83,15 +98,29 @@ Thread Thread::current(){
return Thread(thr);
}
+void Thread::yield()
+{
+ apr_thread_yield();
+}
+
+
// POSIX ================================================================
#else
Thread::Thread(Runnable* runnable) {
- CHECK0(pthread_create(&thread, NULL, runRunnable, runnable));
+ QPID_POSIX_THROW_IF(pthread_create(&thread, NULL, runRunnable, runnable));
+}
+
+Thread::Thread(Runnable& runnable) {
+ QPID_POSIX_THROW_IF(pthread_create(&thread, NULL, runRunnable, &runnable));
}
void Thread::join(){
- if (thread != 0) CHECK0(pthread_join(thread, 0));
+ QPID_POSIX_THROW_IF(pthread_join(thread, 0));
+}
+
+long Thread::id() {
+ return long(thread);
}
Thread::Thread(pthread_t thr) : thread(thr) {}
@@ -99,6 +128,13 @@ Thread::Thread(pthread_t thr) : thread(thr) {}
Thread Thread::current() {
return Thread(pthread_self());
}
+
+void Thread::yield()
+{
+ QPID_POSIX_THROW_IF(pthread_yield());
+}
+
+
#endif
}}