#include "common/code_environment.h"
#include "common/debug.h"
#include "common/signal.h"
+#include "common/io_priority.h"
#include <dirent.h>
#include <errno.h>
Thread::Thread()
- : thread_id(0)
+ : thread_id(0),
+ pid(0),
+ ioprio_class(-1),
+ ioprio_priority(-1)
{
}
}
void *Thread::_entry_func(void *arg) {
- void *r = ((Thread*)arg)->entry();
+ void *r = ((Thread*)arg)->entry_wrapper();
return r;
}
+void *Thread::entry_wrapper()
+{
+ int p = ceph_gettid(); // may return -ENOSYS on other platforms
+ if (p > 0)
+ pid = p;
+ if (ioprio_class >= 0 &&
+ ioprio_priority >= 0) {
+ ceph_ioprio_set(IOPRIO_WHO_PROCESS,
+ pid,
+ IOPRIO_PRIO_VALUE(ioprio_class, ioprio_priority));
+ }
+ return entry();
+}
+
const pthread_t &Thread::get_thread_id()
{
return thread_id;
{
return pthread_detach(thread_id);
}
+
+int Thread::set_ioprio(int cls, int prio)
+{
+ // fixme, maybe: this can race with create()
+ ioprio_class = cls;
+ ioprio_priority = prio;
+ if (pid && cls >= 0 && prio >= 0)
+ return ceph_ioprio_set(IOPRIO_WHO_PROCESS,
+ pid,
+ IOPRIO_PRIO_VALUE(cls, prio));
+ return 0;
+}
class Thread {
private:
pthread_t thread_id;
+ pid_t pid;
+ int ioprio_class, ioprio_priority;
+
+ void *entry_wrapper();
public:
Thread(const Thread& other);
void create(size_t stacksize = 0);
int join(void **prval = 0);
int detach();
+ int set_ioprio(int cls, int prio);
};
#endif