| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
- */
- #ifndef BX_THREAD_H_HEADER_GUARD
- #define BX_THREAD_H_HEADER_GUARD
- #include "allocator.h"
- #include "mpscqueue.h"
- namespace bx
- {
- ///
- typedef int32_t (*ThreadFn)(class Thread* _self, void* _userData);
- ///
- class Thread
- {
- BX_CLASS(Thread
- , NO_COPY
- , NO_ASSIGNMENT
- );
- public:
- ///
- Thread();
- ///
- virtual ~Thread();
- ///
- void init(ThreadFn _fn, void* _userData = NULL, uint32_t _stackSize = 0, const char* _name = NULL);
- ///
- void shutdown();
- ///
- bool isRunning() const;
- ///
- int32_t getExitCode() const;
- ///
- void setThreadName(const char* _name);
- ///
- void push(void* _ptr);
- ///
- void* pop();
- private:
- friend struct ThreadInternal;
- int32_t entry();
- BX_ALIGN_DECL(16, uint8_t) m_internal[64];
- ThreadFn m_fn;
- void* m_userData;
- MpScUnboundedBlockingQueue<void> m_queue;
- Semaphore m_sem;
- uint32_t m_stackSize;
- int32_t m_exitCode;
- bool m_running;
- };
- ///
- class TlsData
- {
- public:
- ///
- TlsData();
- ///
- ~TlsData();
- ///
- void* get() const;
- ///
- void set(void* _ptr);
- private:
- BX_ALIGN_DECL(16, uint8_t) m_internal[64];
- };
- } // namespace bx
- #endif // BX_THREAD_H_HEADER_GUARD
|