Commit 66d70fbf by Marcus Winter

base_c: fixed codesonar warnings

parent d45dc69d
...@@ -80,7 +80,7 @@ void embb_thread_yield() { ...@@ -80,7 +80,7 @@ void embb_thread_yield() {
int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
embb_thread_start_t func, void *arg) { embb_thread_start_t func, void *arg) {
assert(thread != NULL); if (thread == NULL) return EMBB_ERROR;
thread->embb_internal_arg = (embb_internal_thread_arg_t*) thread->embb_internal_arg = (embb_internal_thread_arg_t*)
embb_alloc(sizeof(embb_internal_thread_arg_t)); embb_alloc(sizeof(embb_internal_thread_arg_t));
if (thread->embb_internal_arg == NULL) { if (thread->embb_internal_arg == NULL) {
...@@ -98,6 +98,8 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, ...@@ -98,6 +98,8 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
0, /* no creation arguments */ 0, /* no creation arguments */
0); /* no system thread ID */ 0); /* no system thread ID */
if (thread->embb_internal_handle == NULL) { if (thread->embb_internal_handle == NULL) {
embb_free(thread->embb_internal_arg);
thread->embb_internal_arg = NULL;
return EMBB_ERROR; return EMBB_ERROR;
} }
...@@ -121,6 +123,7 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, ...@@ -121,6 +123,7 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
} }
int embb_thread_join(embb_thread_t* thread, int* result_code) { int embb_thread_join(embb_thread_t* thread, int* result_code) {
if (thread == NULL) return EMBB_ERROR;
BOOL success; BOOL success;
DWORD result; DWORD result;
result = WaitForSingleObject(thread->embb_internal_handle, INFINITE); result = WaitForSingleObject(thread->embb_internal_handle, INFINITE);
...@@ -206,6 +209,7 @@ void embb_thread_yield() { ...@@ -206,6 +209,7 @@ void embb_thread_yield() {
int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
embb_thread_start_t func, void* arg) { embb_thread_start_t func, void* arg) {
if (thread == NULL) return EMBB_ERROR;
pthread_attr_t attr; /* Used to set thread affinities */ pthread_attr_t attr; /* Used to set thread affinities */
int status = pthread_attr_init(&attr); int status = pthread_attr_init(&attr);
if (status != 0) return EMBB_ERROR; if (status != 0) return EMBB_ERROR;
...@@ -226,7 +230,11 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, ...@@ -226,7 +230,11 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
} }
} }
status = pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset); status = pthread_attr_setaffinity_np(&attr, sizeof(cpuset), &cpuset);
if (status != 0) return EMBB_ERROR; if (status != 0) {
thread->embb_internal_arg = NULL;
thread->embb_internal_handle = NULL;
return EMBB_ERROR;
}
#else #else
embb_log_write("base_c", EMBB_LOG_LEVEL_WARNING, "Could not set thread " embb_log_write("base_c", EMBB_LOG_LEVEL_WARNING, "Could not set thread "
"affinity, since no implementation available!\n"); "affinity, since no implementation available!\n");
...@@ -259,11 +267,14 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, ...@@ -259,11 +267,14 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set,
int embb_thread_join(embb_thread_t* thread, int *result_code) { int embb_thread_join(embb_thread_t* thread, int *result_code) {
int status = 0; int status = 0;
if (thread == NULL) return EMBB_ERROR;
status = pthread_join(thread->embb_internal_handle, NULL); status = pthread_join(thread->embb_internal_handle, NULL);
if (result_code != NULL) { if (thread->embb_internal_arg != NULL) {
*result_code = thread->embb_internal_arg->result; if (result_code != NULL) {
*result_code = thread->embb_internal_arg->result;
}
embb_free(thread->embb_internal_arg);
} }
embb_free(thread->embb_internal_arg);
if (status != 0) { if (status != 0) {
return EMBB_ERROR; return EMBB_ERROR;
} }
......
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