]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Thread: remove globals. Thread create must succeed
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 10 Jun 2011 01:26:58 +0000 (18:26 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 10 Jun 2011 01:32:32 +0000 (18:32 -0700)
Remove the references to global variables from Thread.h. They are really
unecessary. In every case, the printout is followed by an assert which
will deliver the exact same information.

Assert that thread creation succeeds. Nobody was checking the return
value of Thread::create() previously. Added a new function,
Thread::try_create(), which programmers can use if they do want to check
the value of Thread::create() and handle it appropriately.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/Thread.h

index 3fc4bc2048c876c74c5346a1df2edc59a6fd1d67..7bd51b1b7897fc569f510be8ab938e3cccd6aefe 100644 (file)
@@ -18,8 +18,6 @@
 
 #include "common/code_environment.h"
 #include "common/signal.h"
-#include "common/config.h"
-#include "include/atomic.h"
 
 #include <errno.h>
 #include <pthread.h>
@@ -55,8 +53,7 @@ class Thread {
     else
       return -EINVAL;
   }
-  int create(size_t stacksize = 0) {
-
+  int try_create(size_t stacksize) {
     pthread_attr_t *thread_attr = NULL;
     stacksize &= PAGE_MASK;  // must be multiple of page
     if (stacksize) {
@@ -84,41 +81,22 @@ class Thread {
 
     if (thread_attr) 
       free(thread_attr);
-
-    if (r) {
-      char buf[80];
-      generic_dout(0) << "pthread_create failed with message: " << strerror_r(r, buf, sizeof(buf)) << dendl;
-    } else {
-      generic_dout(10) << "thread " << thread_id << " start" << dendl;
-    }
     return r;
   }
+
+  void create(size_t stacksize = 0) {
+    int ret = try_create(stacksize);
+    assert(ret == 0);
+  }
+
   int join(void **prval = 0) {
     if (thread_id == 0) {
-      generic_dout(0) << "WARNING: join on thread that was never started" << dendl;
-      assert(0);
-      return -EINVAL;   // never started.
+      assert("join on thread that was never started" == 0);
+      return -EINVAL;
     }
 
     int status = pthread_join(thread_id, prval);
-    if (status != 0) {
-      switch (status) {
-      case -EINVAL:
-       generic_dout(0) << "thread " << thread_id << " join status = EINVAL" << dendl;
-       break;
-      case -ESRCH:
-       generic_dout(0) << "thread " << thread_id << " join status = ESRCH" << dendl;
-       assert(0);
-       break;
-      case -EDEADLK:
-       generic_dout(0) << "thread " << thread_id << " join status = EDEADLK" << dendl;
-       break;
-      default:
-       generic_dout(0) << "thread " << thread_id << " join status = " << status << dendl;
-      }
-      assert(0); // none of these should happen.
-    }
-    generic_dout(10) << "thread " << thread_id << " stop" << dendl;
+    assert(status == 0);
     thread_id = 0;
     return status;
   }