A wrapper around a std thread which executes callable object in thread which is attached to JVM Class has the same interface as std::thread
| 77 | /// A wrapper around a std thread which executes callable object in thread which is attached to JVM |
| 78 | /// Class has the same interface as std::thread |
| 79 | class SimpleThread |
| 80 | { |
| 81 | public: |
| 82 | using id = std::thread::id; |
| 83 | using native_handle_type = std::thread::native_handle_type; |
| 84 | |
| 85 | SimpleThread() noexcept {} |
| 86 | SimpleThread(SimpleThread && x) noexcept : m_thread(std::move(x.m_thread)) {} |
| 87 | |
| 88 | template <class Fn, class... Args> |
| 89 | explicit SimpleThread(Fn && fn, Args &&... args) |
| 90 | : m_thread(&SimpleThread::ThreadFunc, std::bind(std::forward<Fn>(fn), std::forward<Args>(args)...)) |
| 91 | {} |
| 92 | |
| 93 | SimpleThread & operator=(SimpleThread && x) noexcept |
| 94 | { |
| 95 | m_thread = std::move(x.m_thread); |
| 96 | return *this; |
| 97 | } |
| 98 | |
| 99 | void detach() { m_thread.detach(); } |
| 100 | id get_id() const noexcept { return m_thread.get_id(); } |
| 101 | void join() { m_thread.join(); } |
| 102 | bool joinable() const noexcept { return m_thread.joinable(); } |
| 103 | native_handle_type native_handle() { return m_thread.native_handle(); } |
| 104 | void swap(SimpleThread & x) noexcept { m_thread.swap(x.m_thread); } |
| 105 | |
| 106 | private: |
| 107 | static void ThreadFunc(std::function<void()> && fn); |
| 108 | |
| 109 | DISALLOW_COPY(SimpleThread); |
| 110 | |
| 111 | std::thread m_thread; |
| 112 | }; |
| 113 | } // namespace threads |
no outgoing calls
no test coverage detected