From 76d23923fc6e26f46da9ef723aa4ba2267d46897 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 2 Jul 2010 09:34:55 -0700 Subject: [PATCH] thread: force stacksize to be multiple of page size; clean up Signed-off-by: Sage Weil --- src/common/Thread.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/Thread.h b/src/common/Thread.h index 8922fe64768c0..a567d2dbac4c3 100644 --- a/src/common/Thread.h +++ b/src/common/Thread.h @@ -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) { -- 2.39.5