Commit 62c77d0a by Marcus Winter

base_c: added function to set thread priority, implemented for windows only for now

parent 9bbf0e67
......@@ -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
......
......@@ -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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment