#include "include/compat.h"
#include "pthread.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
#include "common/BackTrace.h"
#include "common/debug.h"
#include "common/safe_io.h"
int pipefd[2]; // write to [1], read from [0]
/// to signal shutdown
- bool stop;
+ bool stop = false;
/// for an individual signal
struct safe_handler {
safe_handler *handlers[32] = {nullptr};
/// to protect the handlers array
- Mutex lock;
+ ceph::mutex lock = ceph::make_mutex("SignalHandler::lock");
- SignalHandler()
- : stop(false), lock("SignalHandler::lock")
- {
+ SignalHandler() {
// create signal pipe
int r = pipe_cloexec(pipefd);
ceph_assert(r == 0);
// build fd list
struct pollfd fds[33];
- lock.Lock();
+ lock.lock();
int num_fds = 0;
fds[num_fds].fd = pipefd[0];
fds[num_fds].events = POLLIN | POLLERR;
++num_fds;
}
}
- lock.Unlock();
+ lock.unlock();
// wait for data on any of those pipes
int r = poll(fds, num_fds, -1);
// consume byte from signal socket, if any.
TEMP_FAILURE_RETRY(read(pipefd[0], &v, 1));
- lock.Lock();
+ lock.lock();
for (unsigned signum=0; signum<32; signum++) {
if (handlers[signum]) {
r = read(handlers[signum]->pipefd[0], &v, 1);
}
}
}
- lock.Unlock();
+ lock.unlock();
}
}
return NULL;
ceph_assert(r == 0);
h->handler = handler;
- lock.Lock();
+ lock.lock();
handlers[signum] = h;
- lock.Unlock();
+ lock.unlock();
// signal thread so that it sees our new handler
signal_thread();
signal(signum, SIG_DFL);
// _then_ remove our handlers entry
- lock.Lock();
+ lock.lock();
handlers[signum] = NULL;
- lock.Unlock();
+ lock.unlock();
// this will wake up select() so that worker thread sees our handler is gone
close(h->pipefd[0]);