]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
*** empty log message ***
authorsbrandt <sbrandt@29311d96-e01e-0410-9327-a35deaab8ce9>
Wed, 22 Jun 2005 03:37:10 +0000 (03:37 +0000)
committersbrandt <sbrandt@29311d96-e01e-0410-9327-a35deaab8ce9>
Wed, 22 Jun 2005 03:37:10 +0000 (03:37 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@331 29311d96-e01e-0410-9327-a35deaab8ce9

ceph/osd/ThreadPool.h
ceph/osd/tp.cc

index 99c1bc48d99917408738cb0ed2d349f8f19e8041..70e7610b6ca15fbbe8df140fb9a21e02a3089b16 100644 (file)
@@ -4,6 +4,7 @@
 #include <queue>
 #include<semaphore.h>
 #include <pthread.h>
+#include <common/Mutex.h>
 
 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<T *> 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();
   }
 
 };
index c95a6465061f0e43726adf1156915dbd57835b1e..e817e26ed1cd2c269eba55f39257fa14eab9f397 100644 (file)
@@ -7,7 +7,6 @@ using namespace std;
 
 #include "common/Mutex.h"
 #include "osd/ThreadPool.h"
-#include <thread.h>
 
 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);
 }