edit
[c11concurrency-benchmarks.git] / silo / thread.h
1 #ifndef _NDB_THREAD_H_
2 #define _NDB_THREAD_H_
3
4 #include <vector>
5 #include <string>
6 #include <thread>
7
8 #include "macros.h"
9
10 /**
11  * WARNING: This class is DEPRECATED. New code should use std::thread directly
12  *
13  * ndb_thread: threads in NuDB
14  *
15  * Note that ndb_threads are thin wrappers around std::thread.
16  *
17  * There is really no point to use this-- in the past we used this to grab
18  * hooks into threads when they exited. This is no longer necessary, so we
19  * removed the hook code and this exists just for legacy reasons.
20  */
21
22 class ndb_thread {
23 public:
24
25   typedef void (*run_t)(void);
26
27   ndb_thread(bool daemon = false, const std::string &name = "thd")
28     : body_(nullptr), daemon_(daemon), name_(name) {}
29   ndb_thread(run_t body, bool daemon = false, const std::string &name = "thd")
30     : body_(body), daemon_(daemon), name_(name) {}
31
32   ndb_thread(const ndb_thread &) = delete;
33   ndb_thread(ndb_thread &&) = delete;
34   ndb_thread &operator=(const ndb_thread &) = delete;
35
36   virtual ~ndb_thread();
37
38   inline const std::string &
39   get_name() const
40   {
41     return name_;
42   }
43
44   void start();
45   void join();
46   virtual void run();
47
48 private:
49   run_t body_;
50   std::thread thd_;
51   const bool daemon_;
52   const std::string name_;
53 };
54
55 #endif /* _NDB_THREAD_H_ */