summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2012-10-19 07:12:30 +0000
committerCedric BAIL <cedric.bail@free.fr>2012-10-19 07:12:30 +0000
commit6bde75188d3e55fd4ea50750ed432a297f00184e (patch)
tree6990daec561df977e461551e573e18c8f6c89cc4 /legacy
parente882b9443486bb5ea8a4f8de9beffc0112d0e1ae (diff)
eina: change API a little bit.
SVN revision: 78228
Diffstat (limited to 'legacy')
-rw-r--r--legacy/eina/src/include/eina_thread.h2
-rw-r--r--legacy/eina/src/lib/eina_thread.c54
2 files changed, 44 insertions, 12 deletions
diff --git a/legacy/eina/src/include/eina_thread.h b/legacy/eina/src/include/eina_thread.h
index e615e27c43..85bcb33417 100644
--- a/legacy/eina/src/include/eina_thread.h
+++ b/legacy/eina/src/include/eina_thread.h
@@ -67,7 +67,7 @@ typedef enum _Eina_Thread_Priority
67EAPI Eina_Thread eina_thread_self(void); 67EAPI Eina_Thread eina_thread_self(void);
68EAPI Eina_Bool eina_thread_equal(Eina_Thread t1, Eina_Thread t2); 68EAPI Eina_Bool eina_thread_equal(Eina_Thread t1, Eina_Thread t2);
69EAPI Eina_Bool eina_thread_create(Eina_Thread *t, 69EAPI Eina_Bool eina_thread_create(Eina_Thread *t,
70 Eina_Thread_Priority prio, Eina_Bool affinity, 70 Eina_Thread_Priority prio, int affinity,
71 Eina_Thread_Cb func, const void *data); 71 Eina_Thread_Cb func, const void *data);
72EAPI void *eina_thread_join(Eina_Thread t); 72EAPI void *eina_thread_join(Eina_Thread t);
73 73
diff --git a/legacy/eina/src/lib/eina_thread.c b/legacy/eina/src/lib/eina_thread.c
index e7a5fcdc3d..e0d438fddf 100644
--- a/legacy/eina/src/lib/eina_thread.c
+++ b/legacy/eina/src/lib/eina_thread.c
@@ -101,6 +101,7 @@ _eina_thread_win32_cb(LPVOID lpParam)
101 101
102static Eina_Bool 102static Eina_Bool
103_eina_thread_win32_create(Eina_Thread *t, 103_eina_thread_win32_create(Eina_Thread *t,
104 int affinity,
104 Eina_Thread_Cb func, 105 Eina_Thread_Cb func,
105 const void *data) 106 const void *data)
106{ 107{
@@ -161,10 +162,11 @@ _eina_thread_win32_join(Eina_Thread t)
161 return ret; 162 return ret;
162} 163}
163 164
164# define PHE(x, y) _eina_thread_win32_equal(x, y) 165# define PHE(x, y) _eina_thread_win32_equal(x, y)
165# define PHS() _eina_thread_win32_self() 166# define PHS() _eina_thread_win32_self()
166# define PHC(x, f, d) _eina_thread_win32_create(x, f, d) 167# define PHC(x, a, f, d) _eina_thread_win32_create(x, a, f, d)
167# define PHJ(x) _eina_thread_win32_join(x) 168# define PHJ(x) _eina_thread_win32_join(x)
169# define PHA(a)
168 170
169# else 171# else
170# include <pthread.h> 172# include <pthread.h>
@@ -187,10 +189,40 @@ _eina_thread_join(Eina_Thread t)
187 return NULL; 189 return NULL;
188} 190}
189 191
190# define PHE(x, y) pthread_equal(x, y) 192static Eina_Bool
191# define PHS() pthread_self() 193_eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), void *data)
192# define PHC(x, f, d) pthread_create(x, NULL, (void*) f, d) 194{
193# define PHJ(x) _eina_thread_join(x) 195 Eina_Bool r;
196 pthread_attr_t attr;
197#ifdef EINA_HAVE_PTHREAD_AFFINITY
198 cpu_set_t cpu;
199 int cpunum;
200#endif
201
202 pthread_attr_init(&attr);
203#ifdef EINA_HAVE_PTHREAD_AFFINITY
204 if (affinity >= 0)
205 {
206 cpunum = eina_cpu_count();
207
208 CPU_ZERO(&cpu);
209 CPU_SET(affinity % cpunum, &cpu);
210 pthread_attr_setaffinity_np(&attr, sizeof(cpu), &cpu);
211 }
212#else
213 (void) affinity;
214#endif
215 /* setup initial locks */
216 r = pthread_create(t, &attr, func, data) == 0;
217 pthread_attr_destroy(&attr);
218
219 return r;
220}
221
222# define PHE(x, y) pthread_equal(x, y)
223# define PHS() pthread_self()
224# define PHC(x, a, f, d) _eina_thread_create(x, a, f, d)
225# define PHJ(x) _eina_thread_join(x)
194 226
195# endif 227# endif
196#else 228#else
@@ -204,7 +236,7 @@ struct _Eina_Thread_Call
204 const void *data; 236 const void *data;
205 237
206 Eina_Thread_Priority prio; 238 Eina_Thread_Priority prio;
207 Eina_Bool affinity; 239 int affinity;
208}; 240};
209 241
210#include "eina_thread.h" 242#include "eina_thread.h"
@@ -241,7 +273,7 @@ eina_thread_equal(Eina_Thread t1, Eina_Thread t2)
241 273
242EAPI Eina_Bool 274EAPI Eina_Bool
243eina_thread_create(Eina_Thread *t, 275eina_thread_create(Eina_Thread *t,
244 Eina_Thread_Priority prio, Eina_Bool affinity, 276 Eina_Thread_Priority prio, int affinity,
245 Eina_Thread_Cb func, const void *data) 277 Eina_Thread_Cb func, const void *data)
246{ 278{
247 Eina_Thread_Call *c; 279 Eina_Thread_Call *c;
@@ -254,7 +286,7 @@ eina_thread_create(Eina_Thread *t,
254 c->prio = prio; 286 c->prio = prio;
255 c->affinity = affinity; 287 c->affinity = affinity;
256 288
257 if (PHC(t, _eina_internal_call, c) == 0) 289 if (PHC(t, affinity, _eina_internal_call, c))
258 return EINA_TRUE; 290 return EINA_TRUE;
259 291
260 free(c); 292 free(c);