| 48 | } |
| 49 | |
| 50 | bool Thread::Create(std::unique_ptr<IRoutine> && routine) |
| 51 | { |
| 52 | ASSERT(!m_routine, ("Current implementation doesn't allow to reuse thread")); |
| 53 | std::thread routineThread; |
| 54 | try |
| 55 | { |
| 56 | m_routine.reset(routine.release()); |
| 57 | routineThread = std::thread(&RunRoutine, m_routine); |
| 58 | } |
| 59 | catch (std::exception & e) |
| 60 | { |
| 61 | LOG(LERROR, ("Thread creation failed with error:", e.what())); |
| 62 | m_routine.reset(); |
| 63 | return false; |
| 64 | } |
| 65 | m_thread = std::move(routineThread); |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | void Thread::Cancel() |
| 70 | { |