From: sbrandt Date: Wed, 22 Jun 2005 03:37:10 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: v0.1~2050 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=94ade9d913e28b979ebc378748784acf39860bbe;p=ceph.git *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@331 29311d96-e01e-0410-9327-a35deaab8ce9 --- diff --git a/ceph/osd/ThreadPool.h b/ceph/osd/ThreadPool.h index 99c1bc48d99..70e7610b6ca 100644 --- a/ceph/osd/ThreadPool.h +++ b/ceph/osd/ThreadPool.h @@ -4,6 +4,7 @@ #include #include #include +#include using namespace std; @@ -14,7 +15,7 @@ class Semaphore { public: - Semaphore(int i) { + void init(int i) { sem_init(&sem, 0, i); } @@ -32,8 +33,8 @@ class ThreadPool { private: queue q; - Semaphore q_lock(1); - Semaphore q_sem(0); + Mutex q_lock; + Semaphore q_sem; pthread_t thread[MAX_THREADS]; int num_ops; int num_threads; @@ -64,11 +65,11 @@ class ThreadPool { T* get_op() { T* op; - q_lock.get(); + q_lock.Lock(); op = q.front(); q.pop(); num_ops--; - q_lock.put(); + q_lock.Unlock(); return op; } @@ -84,20 +85,22 @@ class ThreadPool { num_threads = howmany; + q_sem.init(0); + for(int i = 0; i < howmany; i++) { status = pthread_create(&thread[i], NULL, (void*(*)(void *))&ThreadPool::foo, this); } } ~ThreadPool() { - q_lock.get(); + q_lock.Lock(); for(int i = num_ops; i > 0; i--) get_op(); for(int i = 0; i < num_threads; i++) { put_op((T*)NULL); } - q_lock.put(); + q_lock.Unlock(); for(int i = 0; i < num_threads; i++) { cout << "Waiting for thread " << i << " to die\n"; @@ -107,11 +110,11 @@ class ThreadPool { } void put_op(T* op) { - q_lock.get(); + q_lock.Lock(); q.push(op); num_ops++; q_sem.put(); - q_lock.put(); + q_lock.Unlock(); } }; diff --git a/ceph/osd/tp.cc b/ceph/osd/tp.cc index c95a6465061..e817e26ed1c 100644 --- a/ceph/osd/tp.cc +++ b/ceph/osd/tp.cc @@ -7,7 +7,6 @@ using namespace std; #include "common/Mutex.h" #include "osd/ThreadPool.h" -#include class Op { int i; @@ -24,7 +23,7 @@ public: }; void foo(Op *o) { - cout << "Thread "<< thr_self() << ": " << o->get() << "\n"; + cout << "Thread "<< pthread_self() << ": " << o->get() << "\n"; usleep(1); }