]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
thread: force stacksize to be multiple of page size; clean up
authorSage Weil <sage@newdream.net>
Fri, 2 Jul 2010 16:34:55 +0000 (09:34 -0700)
committerSage Weil <sage@newdream.net>
Fri, 2 Jul 2010 17:14:41 +0000 (10:14 -0700)
Signed-off-by: Sage Weil <sage@newdream.net>
src/common/Thread.h

index 8922fe64768c0a56a6f00d0cc588be3c0d595b63..a567d2dbac4c33c9065ff67df79b6c3f3c335ff9 100644 (file)
@@ -55,28 +55,31 @@ class Thread {
       return -EINVAL;
   }
   int create(size_t stacksize = 0) {
-    _num_threads.inc();
     // mask signals in child's thread
     sigset_t newmask, oldmask;
     sigfillset(&newmask);
     pthread_sigmask(SIG_BLOCK, &newmask, &oldmask);
+
     pthread_attr_t *thread_attr = NULL;
+    stacksize &= PAGE_MASK;  // must be multiple of page
     if (stacksize) {
       thread_attr = (pthread_attr_t*) malloc(sizeof(pthread_attr_t));
       pthread_attr_init(thread_attr);
       pthread_attr_setstacksize(thread_attr, stacksize);
     }
     int r = pthread_create(&thread_id, thread_attr, _entry_func, (void*)this);
+
     if (thread_attr) 
       free(thread_attr);
     pthread_sigmask(SIG_SETMASK, &oldmask, 0);
+
     if (r) {
       char buf[80];
       generic_derr(0) << "pthread_create failed with message: " << strerror_r(r, buf, sizeof(buf)) << dendl;
-      _num_threads.dec();
-    }
-    else
+    } else {
+      _num_threads.inc();
       generic_dout(10) << "thread " << thread_id << " start" << dendl;
+    }
     return r;
   }
   int join(void **prval = 0) {