common/common_init.cc \
common/buffer.cc \
common/signal.cc \
+ common/Thread.cc \
include/ceph_fs.cc \
include/ceph_hash.cc \
include/ceph_strings.cc \
--- /dev/null
+ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#include <dirent.h>
+#include <errno.h>
+#include <iostream>
+#include <sstream>
+#include <string.h>
+#include <sys/types.h>
+
+#include "common/debug.h"
+#include "common/Thread.h"
+
+int Thread::get_num_threads(void)
+{
+ std::ostringstream oss;
+ oss << "/proc/" << getpid() << "/task";
+ DIR *dir = opendir(oss.str().c_str());
+ if (!dir) {
+ int err = errno;
+ generic_dout(-1) << "is_multithreaded: failed to open '"
+ << oss.str() << "'" << dendl;
+ return -err;
+ }
+ int num_entries = 0;
+ while (true) {
+ struct dirent *e = readdir(dir);
+ if (!e)
+ break;
+ if ((strcmp(e->d_name, ".") == 0) ||
+ (strcmp(e->d_name, "..") == 0))
+ continue;
+ num_entries++;
+ }
+ ::closedir(dir);
+ if (num_entries == 0) {
+ // Shouldn't happen.
+ generic_dout(-1) << "is_multithreaded: no entries found in '"
+ << oss.str() << "'" << dendl;
+ return -EINVAL;
+ }
+ return num_entries;
+}
#define CEPH_THREAD_H
#include "common/signal.h"
+#include "config.h"
#include "include/atomic.h"
#include <errno.h>
#include <pthread.h>
#include <signal.h>
-extern atomic_t _num_threads; // hack: in config.cc
-
class Thread {
private:
pthread_t thread_id;
private:
static void *_entry_func(void *arg) {
void *r = ((Thread*)arg)->entry();
- _num_threads.dec();
return r;
}
public:
+ static int get_num_threads(void);
+
pthread_t &get_thread_id() { return thread_id; }
bool is_started() { return thread_id != 0; }
bool am_self() { return (pthread_self() == thread_id); }
- static int get_num_threads() { return _num_threads.read(); }
-
int kill(int signal) {
if (thread_id)
return pthread_kill(thread_id, signal);
char buf[80];
generic_dout(0) << "pthread_create failed with message: " << strerror_r(r, buf, sizeof(buf)) << dendl;
} else {
- _num_threads.inc();
generic_dout(10) << "thread " << thread_id << " start" << dendl;
}
return r;
/* These should be moved into md_config_t eventually, grrr */
static ConfFile *cf = NULL;
-atomic_t _num_threads(0);
-
// file layouts
struct ceph_file_layout g_default_file_layout = {
fl_stripe_unit: init_le32(1<<22),
// daemonize?
if (g_conf.daemonize && !nodaemon) {
- if (Thread::get_num_threads() > 0) {
- derr << "messenger.start BUG: there are " << Thread::get_num_threads()
+ int num_threads = Thread::get_num_threads();
+ if (num_threads > 0) {
+ derr << "messenger.start BUG: there are " << num_threads << " threads"
<< " already started that will now die! call messenger.start() sooner."
<< dendl;
}