summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Watkins <noahwatkins@gmail.com>2013-07-20 18:41:41 -0700
committerNoah Watkins <noahwatkins@gmail.com>2013-09-17 10:41:18 -0700
commit80a7e3fbd57b0fee8f774edef946ce63537781e9 (patch)
tree1fc867a3bd6b40ae55a8918c3a31619e3ab5401c
parent88cf1e7760d392e6f1710744e6fc6c0bbf91a279 (diff)
downloadceph-80a7e3fbd57b0fee8f774edef946ce63537781e9.tar.gz
rados_sync: use pthread features for thread-local
OSX doesn't seem to like __thread way of setting thread local data. But the same thing can be accomplished with pthread_get/setspecific. Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
-rw-r--r--src/tools/rados/rados_sync.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/tools/rados/rados_sync.cc b/src/tools/rados/rados_sync.cc
index 03293d3402a..be96be6f085 100644
--- a/src/tools/rados/rados_sync.cc
+++ b/src/tools/rados/rados_sync.cc
@@ -236,7 +236,13 @@ int DirHolder::opendir(const char *dir_name) {
return 0;
}
-static __thread int t_iod_idx = -1;
+static pthread_key_t iod_idx_key;
+static pthread_once_t iod_idx_key_once = PTHREAD_ONCE_INIT;
+
+static void init_iod_idx_key(void)
+{
+ pthread_key_create(&iod_idx_key, NULL);
+}
static pthread_mutex_t io_ctx_distributor_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -277,15 +283,21 @@ void IoCtxDistributor::clear() {
}
IoCtx& IoCtxDistributor::get_ioctx() {
- if (t_iod_idx == -1) {
- t_iod_idx = m_highest_iod_idx.inc() - 1;
+
+ pthread_once(&iod_idx_key_once, init_iod_idx_key);
+
+ int *t_iod_idx = (int*)pthread_getspecific(iod_idx_key);
+ if (!t_iod_idx) {
+ t_iod_idx = (int*)malloc(sizeof(*t_iod_idx));
+ *t_iod_idx = m_highest_iod_idx.inc() - 1;
+ pthread_setspecific(iod_idx_key, t_iod_idx);
}
- if (m_io_ctxes.size() <= (unsigned int)t_iod_idx) {
+ if (m_io_ctxes.size() <= (unsigned int)*t_iod_idx) {
cerr << ERR_PREFIX << "IoCtxDistributor: logic error on line "
<< __LINE__ << std::endl;
_exit(1);
}
- return m_io_ctxes[t_iod_idx];
+ return m_io_ctxes[*t_iod_idx];
}
IoCtxDistributor *IoCtxDistributor::s_instance = NULL;