summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore/ecore_thread.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2012-10-19 05:49:48 +0000
committerCedric BAIL <cedric.bail@free.fr>2012-10-19 05:49:48 +0000
commite882b9443486bb5ea8a4f8de9beffc0112d0e1ae (patch)
tree4927b06cf4e2c9491ed59d865dcfe563c3463703 /legacy/ecore/src/lib/ecore/ecore_thread.c
parent52cf5dce93582d83a07d1f7e8a7df3b677ee08e6 (diff)
ecore: use Eina_Thread in Ecore_Thread.
SVN revision: 78227
Diffstat (limited to '')
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_thread.c112
1 files changed, 7 insertions, 105 deletions
diff --git a/legacy/ecore/src/lib/ecore/ecore_thread.c b/legacy/ecore/src/lib/ecore/ecore_thread.c
index 5c6880bcbf..0d56b26897 100644
--- a/legacy/ecore/src/lib/ecore/ecore_thread.c
+++ b/legacy/ecore/src/lib/ecore/ecore_thread.c
@@ -37,6 +37,12 @@
37# define LRWKRL(x) eina_rwlock_take_read(&(x)); 37# define LRWKRL(x) eina_rwlock_take_read(&(x));
38# define LRWKU(x) eina_rwlock_release(&(x)); 38# define LRWKU(x) eina_rwlock_release(&(x));
39 39
40# define PH(x) Eina_Thread x
41# define PHE(x, y) eina_thread_equal(x, y)
42# define PHS() eina_thread_self()
43# define PHC(x, f, d) eina_thread_create(&(x), EINA_THREAD_BACKGROUND, EINA_TRUE, (void *)f, d)
44# define PHJ(x) eina_thread_join(x)
45
40# ifdef EFL_HAVE_POSIX_THREADS 46# ifdef EFL_HAVE_POSIX_THREADS
41# include <pthread.h> 47# include <pthread.h>
42# ifdef __linux__ 48# ifdef __linux__
@@ -47,99 +53,12 @@
47# include <errno.h> 53# include <errno.h>
48# endif 54# endif
49 55
50# define PH(x) pthread_t x
51# define PHE(x, y) pthread_equal(x, y)
52# define PHS() pthread_self()
53# define PHC(x, f, d) pthread_create(&(x), NULL, (void *)f, d)
54# define PHJ(x) pthread_join(x, NULL)
55# define PHA(x) pthread_cancel(x)
56
57# else /* EFL_HAVE_WIN32_THREADS */ 56# else /* EFL_HAVE_WIN32_THREADS */
58 57
59# define WIN32_LEAN_AND_MEAN 58# define WIN32_LEAN_AND_MEAN
60# include <windows.h> 59# include <windows.h>
61# undef WIN32_LEAN_AND_MEAN 60# undef WIN32_LEAN_AND_MEAN
62 61
63typedef struct
64{
65 HANDLE thread;
66 void *val;
67} win32_thread;
68
69static Eina_List *_ecore_thread_win32_threads = NULL;
70static Eina_Lock _ecore_thread_win32_lock;
71
72# define PH(x) win32_thread * x
73# define PHE(x, y) ((x) == (y))
74
75static win32_thread *
76_ecore_thread_win32_self()
77{
78 win32_thread *t;
79 Eina_List *l;
80
81 LKL(_ecore_thread_win32_lock);
82 EINA_LIST_FOREACH(_ecore_thread_win32_threads, l, t)
83 if (t->thread == GetCurrentThread())
84 {
85 LKU(_ecore_thread_win32_lock);
86 return t;
87 }
88
89 LKU(_ecore_thread_win32_lock);
90 return NULL;
91}
92
93# define PHS() _ecore_thread_win32_self()
94
95static int
96_ecore_thread_win32_create(win32_thread **x,
97 LPTHREAD_START_ROUTINE f,
98 void *d)
99{
100 win32_thread *t;
101
102 t = (win32_thread *)calloc(1, sizeof(win32_thread));
103 if (!t)
104 return -1;
105
106 LKL(_ecore_thread_win32_lock);
107 (t)->thread = CreateThread(NULL, 0, f, d, 0, NULL);
108 if (!t->thread)
109 {
110 free(t);
111 LKU(_ecore_thread_win32_lock);
112 return -1;
113 }
114 t->val = d;
115 *x = t;
116 _ecore_thread_win32_threads = eina_list_append(_ecore_thread_win32_threads, t);
117 LKU(_ecore_thread_win32_lock);
118
119 return 0;
120}
121
122# define PHC(x, f, d) _ecore_thread_win32_create(&(x), (LPTHREAD_START_ROUTINE)f, d)
123
124static int
125_ecore_thread_win32_join(win32_thread *x,
126 void **res)
127{
128 if (!PHE(x, PHS()))
129 {
130 WaitForSingleObject(x->thread, INFINITE);
131 CloseHandle(x->thread);
132 }
133 if (res) *res = x->val;
134 _ecore_thread_win32_threads = eina_list_remove(_ecore_thread_win32_threads, x);
135 free(x);
136
137 return 0;
138}
139
140# define PHJ(x) _ecore_thread_win32_join(x, NULL)
141# define PHA(x) TerminateThread(x->thread, 0)
142
143# endif 62# endif
144 63
145#endif 64#endif
@@ -524,13 +443,6 @@ _ecore_feedback_job(PH(thread))
524static void * 443static void *
525_ecore_direct_worker(Ecore_Pthread_Worker *work) 444_ecore_direct_worker(Ecore_Pthread_Worker *work)
526{ 445{
527#ifdef EFL_POSIX_THREADS
528 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
529 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
530#endif
531
532 eina_sched_prio_drop();
533
534 work->self = PHS(); 446 work->self = PHS();
535 if (work->message_run) 447 if (work->message_run)
536 work->u.message_run.func_main((void *) work->data, (Ecore_Thread *) work); 448 work->u.message_run.func_main((void *) work->data, (Ecore_Thread *) work);
@@ -548,13 +460,6 @@ _ecore_direct_worker(Ecore_Pthread_Worker *work)
548static void * 460static void *
549_ecore_thread_worker(void *data __UNUSED__) 461_ecore_thread_worker(void *data __UNUSED__)
550{ 462{
551#ifdef EFL_POSIX_THREADS
552 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
553 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
554#endif
555
556 eina_sched_prio_drop();
557
558restart: 463restart:
559 _ecore_short_job(PHS()); 464 _ecore_short_job(PHS());
560 _ecore_feedback_job(PHS()); 465 _ecore_feedback_job(PHS());
@@ -788,10 +693,7 @@ ecore_thread_run(Ecore_Thread_Cb func_blocking,
788 if (work->func_cancel) 693 if (work->func_cancel)
789 work->func_cancel((void *) work->data, (Ecore_Thread *) work); 694 work->func_cancel((void *) work->data, (Ecore_Thread *) work);
790 695
791 CDD(work->cond); 696 _ecore_thread_worker_free(work);
792 LKD(work->mutex);
793 LKD(work->cancel_mutex);
794 free(work);
795 work = NULL; 697 work = NULL;
796 } 698 }
797 LKU(_ecore_pending_job_threads_mutex); 699 LKU(_ecore_pending_job_threads_mutex);