summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcarlos <caiosignor@gmail.com>2020-04-02 09:23:14 -0300
committerJoão Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>2020-04-29 12:13:38 -0300
commit3bd220796fa5df25942136eb26045b71f9c3fb0e (patch)
tree5d404f898ebcd5ab4e0ead47d32523b42eca2bf3
parent8666e10639cf12484f1f7d351f607e97f1ae315b (diff)
aplying review from coquinho
-rw-r--r--src/lib/eina/eina_thread.c25
-rw-r--r--src/lib/eina/eina_thread_posix.c12
-rw-r--r--src/lib/eina/eina_thread_win32.c37
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 @@
33 33
34#include "eina_debug_private.h" 34#include "eina_debug_private.h"
35 35
36
37#include <errno.h> 36#include <errno.h>
38#ifndef _WIN32 37#ifndef _WIN32
39# include <signal.h> 38# include <signal.h>
@@ -105,12 +104,7 @@ eina_thread_name_set(Eina_Thread t, const char *name)
105 buf[15] = 0; 104 buf[15] = 0;
106 } 105 }
107 else buf[0] = 0; 106 else buf[0] = 0;
108#ifndef __linux__ 107 if (_eina_thread_set_name(t, buf) == 0) return EINA_TRUE;
109
110 return _eina_thread_set_name_win32(t, buf);
111#else
112 if (pthread_setname_np((pthread_t)t, buf) == 0) return EINA_TRUE;
113#endif
114#else 108#else
115 (void)t; 109 (void)t;
116 (void)name; 110 (void)name;
@@ -122,7 +116,7 @@ EAPI Eina_Bool
122eina_thread_cancel(Eina_Thread t) 116eina_thread_cancel(Eina_Thread t)
123{ 117{
124 if (!t) return EINA_FALSE; 118 if (!t) return EINA_FALSE;
125 return _eina_thread_cancel(t); 119 return _eina_thread_cancel(t) == 0;
126} 120}
127 121
128EAPI Eina_Bool 122EAPI Eina_Bool
@@ -174,10 +168,8 @@ eina_thread_cancellable_run(Eina_Thread_Cancellable_Run_Cb cb, Eina_Free_Cb clea
174 return ret; 168 return ret;
175} 169}
176 170
177
178EAPI const void *EINA_THREAD_JOIN_CANCELED = EINA_THREAD_CANCELED; 171EAPI const void *EINA_THREAD_JOIN_CANCELED = EINA_THREAD_CANCELED;
179 172
180
181Eina_Bool 173Eina_Bool
182eina_thread_init(void) 174eina_thread_init(void)
183{ 175{
@@ -194,11 +186,8 @@ static void *_eina_internal_call(void *context)
194{ 186{
195 Eina_Thread_Call *c = context; 187 Eina_Thread_Call *c = context;
196 void *r; 188 void *r;
197 #ifdef _WIN32 189 Eina_Thread self;
198 HANDLE self; 190
199 #else
200 pthread_t self;
201 #endif
202 191
203 // Default this thread to not cancellable as per Eina documentation 192 // Default this thread to not cancellable as per Eina documentation
204 eina_thread_cancellable_set(EINA_FALSE, NULL); 193 eina_thread_cancellable_set(EINA_FALSE, NULL);
@@ -209,11 +198,7 @@ static void *_eina_internal_call(void *context)
209 eina_sched_prio_drop(); 198 eina_sched_prio_drop();
210 199
211 200
212 #ifdef _WIN32 201 self = eina_thread_self();
213 self = GetCurrentThread();
214 #else
215 self = pthread_self();
216 #endif
217 202
218 _eina_debug_thread_add(&self); 203 _eina_debug_thread_add(&self);
219 EINA_THREAD_CLEANUP_PUSH(_eina_debug_thread_del, &self); 204 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)
55 return NULL; 55 return NULL;
56} 56}
57 57
58Eina_Bool _eina_thread_set_name(Eina_Thread thread, char *buf)
59{
60 #ifndef __linux__
61 pthread_set_name_np((pthread_t)t, buf)
62 return EINA_TRUE;
63 #else
64 return pthread_setname_np((pthread_t)thread, buf);
65 #endif
66}
67
58inline Eina_Bool 68inline Eina_Bool
59_eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), void *data) 69_eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), void *data)
60{ 70{
@@ -111,7 +121,7 @@ _eina_thread_equal(Eina_Thread t1, Eina_Thread t2)
111 121
112Eina_Bool _eina_thread_cancel(Eina_Thread thread) 122Eina_Bool _eina_thread_cancel(Eina_Thread thread)
113{ 123{
114 return pthread_cancel((pthread_t)thread) == 0; 124 return pthread_cancel((pthread_t)thread);
115} 125}
116 126
117inline Eina_Thread 127inline 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)
67 67
68 int ret = (int)WaitForSingleObject(t, INFINITE); 68 int ret = (int)WaitForSingleObject(t, INFINITE);
69 69
70 if (ret != 0) return ret; 70 if (ret != 0)
71 return ret;
71 return NULL; 72 return NULL;
72} 73}
73 74
@@ -82,7 +83,7 @@ void _eina_thread_set_priority(Eina_Thread_Priority prio, Eina_Thread *t)
82 int nPriority; 83 int nPriority;
83 84
84 switch (prio) 85 switch (prio)
85 { 86 {
86 case EINA_THREAD_URGENT: 87 case EINA_THREAD_URGENT:
87 nPriority = THREAD_PRIORITY_HIGHEST; 88 nPriority = THREAD_PRIORITY_HIGHEST;
88 case EINA_THREAD_NORMAL: 89 case EINA_THREAD_NORMAL:
@@ -91,7 +92,7 @@ void _eina_thread_set_priority(Eina_Thread_Priority prio, Eina_Thread *t)
91 nPriority = THREAD_PRIORITY_BELOW_NORMAL; 92 nPriority = THREAD_PRIORITY_BELOW_NORMAL;
92 case EINA_THREAD_IDLE: 93 case EINA_THREAD_IDLE:
93 nPriority = THREAD_PRIORITY_IDLE; 94 nPriority = THREAD_PRIORITY_IDLE;
94 } 95 }
95 96
96 SetThreadPriority((HANDLE)*t, nPriority); 97 SetThreadPriority((HANDLE)*t, nPriority);
97} 98}
@@ -128,7 +129,7 @@ _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), voi
128 ret = (*t != NULL) ? EINA_TRUE : EINA_FALSE; 129 ret = (*t != NULL) ? EINA_TRUE : EINA_FALSE;
129 130
130 if (affinity >= 0 && ret) 131 if (affinity >= 0 && ret)
131 { 132 {
132#ifdef EINA_HAVE_PTHREAD_AFFINITY 133#ifdef EINA_HAVE_PTHREAD_AFFINITY
133 cpu_set_t cpu; 134 cpu_set_t cpu;
134 CPU_ZERO(&cpu); 135 CPU_ZERO(&cpu);
@@ -137,7 +138,7 @@ _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), voi
137#else 138#else
138 SetThreadAffinityMask(*t, (DWORD_PTR *)&affinity); 139 SetThreadAffinityMask(*t, (DWORD_PTR *)&affinity);
139#endif 140#endif
140 } 141 }
141 142
142 return ret; 143 return ret;
143} 144}
@@ -157,18 +158,18 @@ _eina_thread_self(void)
157 return (Eina_Thread)GetCurrentThread(); 158 return (Eina_Thread)GetCurrentThread();
158} 159}
159 160
160HRESULT _eina_thread_set_name_win32(Eina_Thread thread, char *buf) 161Eina_Bool _eina_thread_set_name(Eina_Thread thread, char *buf)
161{ 162{
162 return SetThreadDescription((HANDLE)thread, (PCWSTR)buf); 163 HRESULT res = SetThreadDescription((HANDLE)thread, (PCWSTR)buf);
164 return HRESULT_CODE(res);
163} 165}
164 166
165Eina_Bool _eina_thread_cancel(Eina_Thread thread) 167Eina_Bool _eina_thread_cancel(Eina_Thread thread)
166{ 168{
167 LPDWORD lpExitCode; 169 LPDWORD lpExitCode;
168 Eina_Bool success = GetExitCodeThread((HANDLE)thread, lpExitCode); 170 Eina_Bool success = GetExitCodeThread((HANDLE)thread, lpExitCode);
169
170 ExitThread(*lpExitCode); 171 ExitThread(*lpExitCode);
171 return success; 172 return !success;
172} 173}
173 174
174inline void _eina_sched_prio_drop(void) 175inline void _eina_sched_prio_drop(void)
@@ -181,19 +182,19 @@ inline void _eina_sched_prio_drop(void)
181 sched_priority = GetThreadPriority((HANDLE)pthread_id); 182 sched_priority = GetThreadPriority((HANDLE)pthread_id);
182 183
183 if (EINA_UNLIKELY(sched_priority == THREAD_PRIORITY_TIME_CRITICAL)) 184 if (EINA_UNLIKELY(sched_priority == THREAD_PRIORITY_TIME_CRITICAL))
184 { 185 {
185 sched_priority -= RTNICENESS; 186 sched_priority -= RTNICENESS;
186 187
187 /* We don't change the policy */ 188 /* We don't change the policy */
188 if (sched_priority < 1) 189 if (sched_priority < 1)
189 { 190 {
190 EINA_LOG_INFO("RT prio < 1, setting to 1 instead"); 191 EINA_LOG_INFO("RT prio < 1, setting to 1 instead");
191 sched_priority = 1; 192 sched_priority = 1;
192 } 193 }
193 if (!SetThreadPriority((HANDLE)pthread_id, sched_priority)) 194 if (!SetThreadPriority((HANDLE)pthread_id, sched_priority))
194 { 195 {
195 EINA_LOG_ERR("Unable to query sched parameters"); 196 EINA_LOG_ERR("Unable to query sched parameters");
196 } 197 }
197 } 198 }
198 else 199 else
199 { 200 {
@@ -201,13 +202,13 @@ inline void _eina_sched_prio_drop(void)
201 202
202 /* We don't change the policy */ 203 /* We don't change the policy */
203 if (sched_priority > THREAD_PRIORITY_TIME_CRITICAL) 204 if (sched_priority > THREAD_PRIORITY_TIME_CRITICAL)
204 { 205 {
205 EINA_LOG_INFO("Max niceness reached; keeping max (THREAD_PRIORITY_TIME_CRITICAL)"); 206 EINA_LOG_INFO("Max niceness reached; keeping max (THREAD_PRIORITY_TIME_CRITICAL)");
206 sched_priority = THREAD_PRIORITY_TIME_CRITICAL; 207 sched_priority = THREAD_PRIORITY_TIME_CRITICAL;
207 } 208 }
208 if (!SetThreadPriority((HANDLE)pthread_id, sched_priority)) 209 if (!SetThreadPriority((HANDLE)pthread_id, sched_priority))
209 { 210 {
210 EINA_LOG_ERR("Unable to query sched parameters"); 211 EINA_LOG_ERR("Unable to query sched parameters");
211 } 212 }
212 } 213 }
213} 214}