TEST(IThread, Test1) { class ThreadHandle: public IThread { public: ThreadHandle():num(1) {} virtual ~ThreadHandle() {} private: public: virtual void run() { ASSERT_EQ(num, 1u); num = 2; } public: size_t num; }; { ThreadHandle thr; thr.start(); thr.join(); ASSERT_EQ(thr.num, 2u); } { IThread* ptr = new ThreadHandle(); ptr->start(); ptr->join(); delete ptr; } }
bool Thread::interrupted() { ThreadHandle handle = currentThread(); if(!handle.is_null()) { return handle->consumeInterruptionSync(); } else { return false; } };
/** * Determine if the current thread has locked this mutex. This is a * debug-only method meant for assert() calls, and is not available * in optimised builds. */ gcc_pure bool IsLockedByCurrent() const { debug_mutex.Lock(); bool result = locked && owner.IsInside(); debug_mutex.Unlock(); return result; }
void LeaveDrawThread() { assert(InMainThread()); assert(draw_thread_handle.IsInside()); draw_thread_handle = zero_thread_handle; }
bool InDrawThread() { #ifdef ENABLE_OPENGL return InMainThread() && draw_thread_handle.IsInside(); #else return draw_thread != nullptr && draw_thread->IsInside(); #endif }
/** * Unlocks the Mutex */ void Unlock() { #ifndef NDEBUG debug_mutex.lock(); assert(locked); assert(owner.IsInside()); locked = false; debug_mutex.unlock(); #endif mutex.unlock(); }
/** * Unlocks the Mutex */ void Unlock() { #ifndef NDEBUG debug_mutex.Lock(); assert(locked); assert(owner.IsInside()); locked = false; debug_mutex.Unlock(); #endif mutex.Unlock(); #ifndef NDEBUG --thread_locks_held; #endif }
OVUM_API size_t VM_GetArgValues(ThreadHandle thread, size_t destLength, Value dest[]) { return thread->GetVM()->GetArgValues(destLength, dest); }
OVUM_API size_t VM_GetArgs(ThreadHandle thread, size_t destLength, String *dest[]) { return thread->GetVM()->GetArgs(destLength, dest); }
OVUM_API size_t VM_GetArgCount(ThreadHandle thread) { return thread->GetVM()->GetArgCount(); }
void WakeUp() { if (!thread.IsInside()) event_pipe.Signal(); }
/** * Returns the monotonic clock in microseconds. This method is only * available in the main thread. */ gcc_pure uint64_t ClockUS() const { assert(thread.IsInside()); return now_us; }
bool InMainThread() { return main_thread.IsInside(); }