diff options
author | carlos <caiosignor@gmail.com> | 2020-04-02 09:23:14 -0300 |
---|---|---|
committer | João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> | 2020-04-29 12:13:38 -0300 |
commit | 3bd220796fa5df25942136eb26045b71f9c3fb0e (patch) | |
tree | 5d404f898ebcd5ab4e0ead47d32523b42eca2bf3 | |
parent | 8666e10639cf12484f1f7d351f607e97f1ae315b (diff) | |
download | efl-3bd220796fa5df25942136eb26045b71f9c3fb0e.tar.gz |
aplying review from coquinho
-rw-r--r-- | src/lib/eina/eina_thread.c | 25 | ||||
-rw-r--r-- | src/lib/eina/eina_thread_posix.c | 12 | ||||
-rw-r--r-- | src/lib/eina/eina_thread_win32.c | 37 |
3 files changed, 35 insertions, 39 deletions
diff --git a/src/lib/eina/eina_thread.c b/src/lib/eina/eina_thread.c index b4aeb287b8..1c2a307dd8 100644 --- a/src/lib/eina/eina_thread.c +++ b/src/lib/eina/eina_thread.c @@ -33,7 +33,6 @@ #include "eina_debug_private.h" - #include <errno.h> #ifndef _WIN32 # include <signal.h> @@ -105,12 +104,7 @@ eina_thread_name_set(Eina_Thread t, const char *name) buf[15] = 0; } else buf[0] = 0; -#ifndef __linux__ - - return _eina_thread_set_name_win32(t, buf); -#else - if (pthread_setname_np((pthread_t)t, buf) == 0) return EINA_TRUE; -#endif + if (_eina_thread_set_name(t, buf) == 0) return EINA_TRUE; #else (void)t; (void)name; @@ -122,7 +116,7 @@ EAPI Eina_Bool eina_thread_cancel(Eina_Thread t) { if (!t) return EINA_FALSE; - return _eina_thread_cancel(t); + return _eina_thread_cancel(t) == 0; } EAPI Eina_Bool @@ -174,10 +168,8 @@ eina_thread_cancellable_run(Eina_Thread_Cancellable_Run_Cb cb, Eina_Free_Cb clea return ret; } - EAPI const void *EINA_THREAD_JOIN_CANCELED = EINA_THREAD_CANCELED; - Eina_Bool eina_thread_init(void) { @@ -194,11 +186,8 @@ static void *_eina_internal_call(void *context) { Eina_Thread_Call *c = context; void *r; - #ifdef _WIN32 - HANDLE self; - #else - pthread_t self; - #endif + Eina_Thread self; + // Default this thread to not cancellable as per Eina documentation eina_thread_cancellable_set(EINA_FALSE, NULL); @@ -209,11 +198,7 @@ static void *_eina_internal_call(void *context) eina_sched_prio_drop(); - #ifdef _WIN32 - self = GetCurrentThread(); - #else - self = pthread_self(); - #endif + self = eina_thread_self(); _eina_debug_thread_add(&self); EINA_THREAD_CLEANUP_PUSH(_eina_debug_thread_del, &self); diff --git a/src/lib/eina/eina_thread_posix.c b/src/lib/eina/eina_thread_posix.c index 452d3e7ee0..09fc83a288 100644 --- a/src/lib/eina/eina_thread_posix.c +++ b/src/lib/eina/eina_thread_posix.c @@ -55,6 +55,16 @@ _eina_thread_join(Eina_Thread t) return NULL; } +Eina_Bool _eina_thread_set_name(Eina_Thread thread, char *buf) +{ + #ifndef __linux__ + pthread_set_name_np((pthread_t)t, buf) + return EINA_TRUE; + #else + return pthread_setname_np((pthread_t)thread, buf); + #endif +} + inline Eina_Bool _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), void *data) { @@ -111,7 +121,7 @@ _eina_thread_equal(Eina_Thread t1, Eina_Thread t2) Eina_Bool _eina_thread_cancel(Eina_Thread thread) { - return pthread_cancel((pthread_t)thread) == 0; + return pthread_cancel((pthread_t)thread); } inline Eina_Thread diff --git a/src/lib/eina/eina_thread_win32.c b/src/lib/eina/eina_thread_win32.c index f87a12fae9..d274cba394 100644 --- a/src/lib/eina/eina_thread_win32.c +++ b/src/lib/eina/eina_thread_win32.c @@ -67,7 +67,8 @@ _eina_thread_join(Eina_Thread t) int ret = (int)WaitForSingleObject(t, INFINITE); - if (ret != 0) return ret; + if (ret != 0) + return ret; return NULL; } @@ -82,7 +83,7 @@ void _eina_thread_set_priority(Eina_Thread_Priority prio, Eina_Thread *t) int nPriority; switch (prio) - { + { case EINA_THREAD_URGENT: nPriority = THREAD_PRIORITY_HIGHEST; case EINA_THREAD_NORMAL: @@ -91,7 +92,7 @@ void _eina_thread_set_priority(Eina_Thread_Priority prio, Eina_Thread *t) nPriority = THREAD_PRIORITY_BELOW_NORMAL; case EINA_THREAD_IDLE: nPriority = THREAD_PRIORITY_IDLE; - } + } SetThreadPriority((HANDLE)*t, nPriority); } @@ -128,7 +129,7 @@ _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), voi ret = (*t != NULL) ? EINA_TRUE : EINA_FALSE; if (affinity >= 0 && ret) - { + { #ifdef EINA_HAVE_PTHREAD_AFFINITY cpu_set_t cpu; CPU_ZERO(&cpu); @@ -137,7 +138,7 @@ _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), voi #else SetThreadAffinityMask(*t, (DWORD_PTR *)&affinity); #endif - } + } return ret; } @@ -157,18 +158,18 @@ _eina_thread_self(void) return (Eina_Thread)GetCurrentThread(); } -HRESULT _eina_thread_set_name_win32(Eina_Thread thread, char *buf) +Eina_Bool _eina_thread_set_name(Eina_Thread thread, char *buf) { - return SetThreadDescription((HANDLE)thread, (PCWSTR)buf); + HRESULT res = SetThreadDescription((HANDLE)thread, (PCWSTR)buf); + return HRESULT_CODE(res); } Eina_Bool _eina_thread_cancel(Eina_Thread thread) { LPDWORD lpExitCode; Eina_Bool success = GetExitCodeThread((HANDLE)thread, lpExitCode); - ExitThread(*lpExitCode); - return success; + return !success; } inline void _eina_sched_prio_drop(void) @@ -181,19 +182,19 @@ inline void _eina_sched_prio_drop(void) sched_priority = GetThreadPriority((HANDLE)pthread_id); if (EINA_UNLIKELY(sched_priority == THREAD_PRIORITY_TIME_CRITICAL)) - { + { sched_priority -= RTNICENESS; /* We don't change the policy */ if (sched_priority < 1) - { + { EINA_LOG_INFO("RT prio < 1, setting to 1 instead"); sched_priority = 1; - } + } if (!SetThreadPriority((HANDLE)pthread_id, sched_priority)) - { + { EINA_LOG_ERR("Unable to query sched parameters"); - } + } } else { @@ -201,13 +202,13 @@ inline void _eina_sched_prio_drop(void) /* We don't change the policy */ if (sched_priority > THREAD_PRIORITY_TIME_CRITICAL) - { + { EINA_LOG_INFO("Max niceness reached; keeping max (THREAD_PRIORITY_TIME_CRITICAL)"); sched_priority = THREAD_PRIORITY_TIME_CRITICAL; - } + } if (!SetThreadPriority((HANDLE)pthread_id, sched_priority)) - { + { EINA_LOG_ERR("Unable to query sched parameters"); - } + } } } |