Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / common / Thread.h
1  // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2004-2011 New Dream Network
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation.  See file COPYING.
12  *
13  */
14
15
16 #ifndef CEPH_THREAD_H
17 #define CEPH_THREAD_H
18
19 #include <pthread.h>
20 #include <sys/types.h>
21
22 class Thread {
23  private:
24   pthread_t thread_id;
25   pid_t pid;
26   int ioprio_class, ioprio_priority;
27   int cpuid;
28   const char *thread_name;
29
30   void *entry_wrapper();
31
32  public:
33   Thread(const Thread&) = delete;
34   Thread& operator=(const Thread&) = delete;
35
36   Thread();
37   virtual ~Thread();
38
39  protected:
40   virtual void *entry() = 0;
41
42  private:
43   static void *_entry_func(void *arg);
44
45  public:
46   const pthread_t &get_thread_id() const;
47   pid_t get_pid() const { return pid; }
48   bool is_started() const;
49   bool am_self() const;
50   int kill(int signal);
51   int try_create(size_t stacksize);
52   void create(const char *name, size_t stacksize = 0);
53   int join(void **prval = 0);
54   int detach();
55   int set_ioprio(int cls, int prio);
56   int set_affinity(int cpuid);
57 };
58
59 #endif