diff --git a/libs/libks/src/include/ks_threadmutex.h b/libs/libks/src/include/ks_threadmutex.h index fea6184200..1be750eb37 100644 --- a/libs/libks/src/include/ks_threadmutex.h +++ b/libs/libks/src/include/ks_threadmutex.h @@ -78,6 +78,7 @@ struct ks_thread { ks_thread_state_t state; uint8_t priority; void *return_data; + uint8_t joined; }; typedef enum { diff --git a/libs/libks/src/include/ks_types.h b/libs/libks/src/include/ks_types.h index e50dc5aa21..201ea3f7f6 100644 --- a/libs/libks/src/include/ks_types.h +++ b/libs/libks/src/include/ks_types.h @@ -89,6 +89,7 @@ KS_BEGIN_EXTERN_C KS_STATUS_GENERR, KS_STATUS_INACTIVE, KS_STATUS_TIMEOUT, + KS_STATUS_DUPLICATE_OPERATION, /* Memory pool errors */ KS_STATUS_REFS_EXIST, /* references exist */ KS_STATUS_ARG_NULL, /* function argument is null */ diff --git a/libs/libks/src/ks_thread.c b/libs/libks/src/ks_thread.c index 25b08184a6..92c608bd27 100644 --- a/libs/libks/src/ks_thread.c +++ b/libs/libks/src/ks_thread.c @@ -197,12 +197,20 @@ KS_DECLARE(uint8_t) ks_thread_priority(ks_thread_t *thread) { } KS_DECLARE(ks_status_t) ks_thread_join(ks_thread_t *thread) { + + if (thread->joined) { + return KS_STATUS_DUPLICATE_OPERATION; + } + #ifdef WIN32 WaitForSingleObject(thread->handle, INFINITE); #else void *ret; pthread_join(thread->handle, &ret); #endif + + thread->joined++; + return KS_STATUS_SUCCESS; }