diff --git a/base_c/include/embb/base/c/thread.h b/base_c/include/embb/base/c/thread.h index 1d7ea11..98f84ab 100644 --- a/base_c/include/embb/base/c/thread.h +++ b/base_c/include/embb/base/c/thread.h @@ -56,6 +56,16 @@ extern "C" { typedef opaque_type embb_thread_t; #endif /* DOXYGEN */ +typedef enum { + EMBB_THREAD_PRIORITY_IDLE, + EMBB_THREAD_PRIORITY_LOWEST, + EMBB_THREAD_PRIORITY_BELOW_NORMAL, + EMBB_THREAD_PRIORITY_NORMAL, + EMBB_THREAD_PRIORITY_ABOVE_NORMAL, + EMBB_THREAD_PRIORITY_HIGHEST, + EMBB_THREAD_PRIORITY_TIME_CRITICAL +} embb_thread_priority_t; + /** * Thread start function pointer type. * @@ -180,6 +190,11 @@ int embb_thread_equal( /**< [IN] Second thread (right-hand side of equality sign) */ ); +int embb_thread_set_priority( + embb_thread_t* thread, + embb_thread_priority_t priority + ); + #ifdef __cplusplus } /* Close extern "C" { */ #endif diff --git a/base_c/src/thread.c b/base_c/src/thread.c index f88b2ab..1c99304 100644 --- a/base_c/src/thread.c +++ b/base_c/src/thread.c @@ -164,6 +164,43 @@ int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) { return 0; } +int embb_thread_set_priority( + embb_thread_t* thread, + embb_thread_priority_t priority +) { + int internal_priority; + switch (priority) { + case EMBB_THREAD_PRIORITY_IDLE: + internal_priority = THREAD_PRIORITY_IDLE; + break; + case EMBB_THREAD_PRIORITY_LOWEST: + internal_priority = THREAD_PRIORITY_LOWEST; + break; + case EMBB_THREAD_PRIORITY_BELOW_NORMAL: + internal_priority = THREAD_PRIORITY_BELOW_NORMAL; + break; + case EMBB_THREAD_PRIORITY_ABOVE_NORMAL: + internal_priority = THREAD_PRIORITY_ABOVE_NORMAL; + break; + case EMBB_THREAD_PRIORITY_HIGHEST: + internal_priority = THREAD_PRIORITY_HIGHEST; + break; + case EMBB_THREAD_PRIORITY_TIME_CRITICAL: + internal_priority = THREAD_PRIORITY_TIME_CRITICAL; + break; + case EMBB_THREAD_PRIORITY_NORMAL: + default: + internal_priority = THREAD_PRIORITY_NORMAL; + break; + } + BOOL result = SetThreadPriority(thread->embb_internal_handle, internal_priority); + if (result != 0) { + return EMBB_SUCCESS; + } else { + return EMBB_ERROR; + } +} + #endif /* EMBB_PLATFORM_THREADING_WINTHREADS */ #ifdef EMBB_PLATFORM_THREADING_POSIXTHREADS @@ -299,4 +336,12 @@ int embb_thread_equal(const embb_thread_t* lhs, const embb_thread_t* rhs) { return pthread_equal(lhs->embb_internal_handle, rhs->embb_internal_handle); } +int embb_thread_set_priority( + embb_thread_t* /*thread*/, + embb_thread_priority_t /*priority*/ +) { + // not implemented yet + return EMBB_ERROR; +} + #endif /* EMBB_PLATFORM_THREADING_POSIXTHREADS */