Wrapper around std::thread to prive more abstractions.
More...
#include <Thread.h>
|
| enum | YieldPolicy { YP_ANY_THREAD_ANY_PROCESSOR = 0
, YP_ANY_THREAD_SAME_PROCESSOR
} |
| |
|
| static void | sleep (const unsigned int millis) |
| |
| static void | yield (YieldPolicy yp=YP_ANY_THREAD_SAME_PROCESSOR) |
| |
| constexpr static unsigned | getMinimunSleepTime () |
| |
Wrapper around std::thread to prive more abstractions.
- Warning
- Some of these features may not be present on certain platforms, or may have specific requirements.
◆ Thread()
template<class F >
| mel::core::Thread::Thread |
( |
F && |
f | ) |
|
Starts the main thread routine.
- Parameters
-
| [in] | f | funtion with signature void f() |
◆ getAffinity()
| uint64_t mel::core::Thread::getAffinity |
( |
| ) |
const |
Get thread state
- Returns
- the thread's current state returns if a terminate request is done (mEnd == true)
◆ getMinimunSleepTime()
| constexpr static unsigned mel::core::Thread::getMinimunSleepTime |
( |
| ) |
|
|
inlinestaticconstexpr |
return minimun time(msecs) the system will wait with accuracy. it depends on underlying OS and hardware, but traditionally it's about 10-15 msecs
◆ getPriority()
Query thread's current priority.
- Returns
- the priority of the thread
◆ getThreadId()
| std::thread::id mel::core::Thread::getThreadId |
( |
| ) |
const |
|
inline |
return handle for this thread
◆ join()
| bool mel::core::Thread::join |
( |
unsigned int |
millis = 0xFFFFFFFF | ) |
|
Forces the caller to wait for thread completion. Calling this method will cause the calling thread to be wait until Thread:run finishes or the timeout expires.
- Parameters
-
| millis | maximum milliseconds to wait for the thread. |
- Returns
- true if the thread finished. false if timeout
◆ setAffinity()
| bool mel::core::Thread::setAffinity |
( |
uint64_t |
| ) |
|
◆ setPriority()
Changes thread priority. May not be available in some platforms.
- Parameters
-
| tp | the new priority to be set. |
◆ sleep()
| static void mel::core::Thread::sleep |
( |
const unsigned int |
millis | ) |
|
|
static |
Forces the calling thread to sleep. Calling this method ensures the OS will schedule some CPU for any pending processes and threads that need attention.
NOTE: on some platforms, calling sleep(0) may cause the call to be completely ignored.
- Parameters
-
| millis | the number of milliseconds to sleep for. The actual sleep time may depend on each platform, but you can expect a granularity not finer than 10ms, meaning sleep(1) will make the thread sleep for almost the same time as sleep(10). |
◆ terminate()
| void mel::core::Thread::terminate |
( |
unsigned int |
exitCode = 0 | ) |
|
Forces thread termination Use with extreme caution; this method exists but it should rarely be used; it's always safer to invoke terminatRequest and wait for the Thread to terminate "naturally", instead of forcing it to quite.
- Parameters
-
| exitCode | the exit code for the terminated thread. |
◆ yield()
| static void mel::core::Thread::yield |
( |
YieldPolicy |
yp = YP_ANY_THREAD_SAME_PROCESSOR | ) |
|
|
static |
Forces the calling thread to yield execution. This may have slight different effects depending on the platform, but theoretically the execution is yielded only to threads in the same process as the caller.
Calling this method may not force the OS to schedule any CPU time for any pending processes different that the caller.
The documentation for this class was generated from the following file:
- /github/workspace/mel/include/core/Thread.h