* Factory to create thread object and bind them to Runnable * object for execution */
| 32 | * object for execution |
| 33 | */ |
| 34 | class ThreadFactory { |
| 35 | public: |
| 36 | /** |
| 37 | * All threads created by a factory are reference-counted |
| 38 | * via std::shared_ptr. The factory guarantees that threads and the Runnable tasks |
| 39 | * they host will be properly cleaned up once the last strong reference |
| 40 | * to both is given up. |
| 41 | * |
| 42 | * By default threads are not joinable. |
| 43 | */ |
| 44 | ThreadFactory(bool detached = true) : detached_(detached) { } |
| 45 | |
| 46 | virtual ~ThreadFactory() = default; |
| 47 | |
| 48 | /** |
| 49 | * Gets current detached mode |
| 50 | */ |
| 51 | bool isDetached() const { return detached_; } |
| 52 | |
| 53 | /** |
| 54 | * Sets the detached disposition of newly created threads. |
| 55 | */ |
| 56 | void setDetached(bool detached) { detached_ = detached; } |
| 57 | |
| 58 | /** |
| 59 | * Create a new thread. |
| 60 | */ |
| 61 | virtual std::shared_ptr<Thread> newThread(std::shared_ptr<Runnable> runnable) const; |
| 62 | |
| 63 | /** |
| 64 | * Gets the current thread id or unknown_thread_id if the current thread is not a thrift thread |
| 65 | */ |
| 66 | Thread::id_t getCurrentThreadId() const; |
| 67 | |
| 68 | private: |
| 69 | bool detached_; |
| 70 | }; |
| 71 | |
| 72 | } |
| 73 | } |
no outgoing calls