diff options
author | Vincent Torri <vincent.torri@gmail.com> | 2012-08-27 06:04:16 +0000 |
---|---|---|
committer | Vincent Torri <vincent.torri@gmail.com> | 2012-08-27 06:04:16 +0000 |
commit | b20f37ef58ed295e8898551abd51a68fa96c206f (patch) | |
tree | 9582c872eb21a469a44d8f1d44188343e8e6387f /legacy/ecore/src/lib/ecore/ecore_thread.c | |
parent | 3faee27bd87d56814cb657e94146eb4b8b7fde55 (diff) |
Ecore: fix seg fault in ecore_thread on Windows
PHS() was returning a wrong value. Thanks to Cedric for the help
SVN revision: 75720
Diffstat (limited to '')
-rw-r--r-- | legacy/ecore/src/lib/ecore/ecore_thread.c | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/legacy/ecore/src/lib/ecore/ecore_thread.c b/legacy/ecore/src/lib/ecore/ecore_thread.c index 275be5d510..d2499487a2 100644 --- a/legacy/ecore/src/lib/ecore/ecore_thread.c +++ b/legacy/ecore/src/lib/ecore/ecore_thread.c | |||
@@ -66,44 +66,79 @@ typedef struct | |||
66 | void *val; | 66 | void *val; |
67 | } win32_thread; | 67 | } win32_thread; |
68 | 68 | ||
69 | static Eina_List *_ecore_thread_win32_threads = NULL; | ||
70 | static Eina_Lock _ecore_thread_win32_lock; | ||
71 | |||
69 | # define PH(x) win32_thread * x | 72 | # define PH(x) win32_thread * x |
70 | # define PHE(x, y) ((x) == (y)) | 73 | # define PHE(x, y) ((x) == (y)) |
71 | # define PHS() (HANDLE)GetCurrentThreadId() | ||
72 | 74 | ||
73 | int | 75 | static 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 | { | ||
84 | printf("thread self : %p %p\n", t, t->thread); | ||
85 | if (t->thread == GetCurrentThread()) | ||
86 | { | ||
87 | LKU(_ecore_thread_win32_lock); | ||
88 | return t; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | LKU(_ecore_thread_win32_lock); | ||
93 | return NULL; | ||
94 | } | ||
95 | |||
96 | # define PHS() _ecore_thread_win32_self() | ||
97 | |||
98 | static int | ||
74 | _ecore_thread_win32_create(win32_thread **x, | 99 | _ecore_thread_win32_create(win32_thread **x, |
75 | LPTHREAD_START_ROUTINE f, | 100 | LPTHREAD_START_ROUTINE f, |
76 | void *d) | 101 | void *d) |
77 | { | 102 | { |
78 | win32_thread *t; | 103 | win32_thread *t; |
104 | |||
79 | t = (win32_thread *)calloc(1, sizeof(win32_thread)); | 105 | t = (win32_thread *)calloc(1, sizeof(win32_thread)); |
80 | if (!t) | 106 | if (!t) |
81 | return -1; | 107 | return -1; |
82 | 108 | ||
109 | LKL(_ecore_thread_win32_lock); | ||
83 | (t)->thread = CreateThread(NULL, 0, f, d, 0, NULL); | 110 | (t)->thread = CreateThread(NULL, 0, f, d, 0, NULL); |
84 | if (!t->thread) | 111 | if (!t->thread) |
85 | { | 112 | { |
86 | free(t); | 113 | free(t); |
114 | LKU(_ecore_thread_win32_lock); | ||
87 | return -1; | 115 | return -1; |
88 | } | 116 | } |
89 | t->val = d; | 117 | t->val = d; |
90 | *x = t; | 118 | *x = t; |
119 | _ecore_thread_win32_threads = eina_list_append(_ecore_thread_win32_threads, t); | ||
120 | LKU(_ecore_thread_win32_lock); | ||
121 | printf(" * thread create 1: %p\n", t); | ||
122 | printf(" * thread create 2: %p\n", t->thread); | ||
91 | 123 | ||
92 | return 0; | 124 | return 0; |
93 | } | 125 | } |
94 | 126 | ||
95 | # define PHC(x, f, d) _ecore_thread_win32_create(&(x), (LPTHREAD_START_ROUTINE)f, d) | 127 | # define PHC(x, f, d) _ecore_thread_win32_create(&(x), (LPTHREAD_START_ROUTINE)f, d) |
96 | 128 | ||
97 | int | 129 | static int |
98 | _ecore_thread_win32_join(win32_thread *x, | 130 | _ecore_thread_win32_join(win32_thread *x, |
99 | void **res) | 131 | void **res) |
100 | { | 132 | { |
133 | printf(" * thread join 1 : %p\n", x); | ||
101 | if (!PHE(x, PHS())) | 134 | if (!PHE(x, PHS())) |
102 | { | 135 | { |
136 | printf(" * thread join 2 : %p\n", x->thread); | ||
103 | WaitForSingleObject(x->thread, INFINITE); | 137 | WaitForSingleObject(x->thread, INFINITE); |
104 | CloseHandle(x->thread); | 138 | CloseHandle(x->thread); |
105 | } | 139 | } |
106 | if (res) *res = x->val; | 140 | if (res) *res = x->val; |
141 | _ecore_thread_win32_threads = eina_list_remove(_ecore_thread_win32_threads, x); | ||
107 | free(x); | 142 | free(x); |
108 | 143 | ||
109 | return 0; | 144 | return 0; |
@@ -597,6 +632,9 @@ _ecore_thread_init(void) | |||
597 | _ecore_thread_count_max = 1; | 632 | _ecore_thread_count_max = 1; |
598 | 633 | ||
599 | #ifdef EFL_HAVE_THREADS | 634 | #ifdef EFL_HAVE_THREADS |
635 | # ifdef EFL_HAVE_WIN32_THREADS | ||
636 | LKI(_ecore_thread_win32_lock); | ||
637 | # endif | ||
600 | LKI(_ecore_pending_job_threads_mutex); | 638 | LKI(_ecore_pending_job_threads_mutex); |
601 | LRWKI(_ecore_thread_global_hash_lock); | 639 | LRWKI(_ecore_thread_global_hash_lock); |
602 | LKI(_ecore_thread_global_hash_mutex); | 640 | LKI(_ecore_thread_global_hash_mutex); |
@@ -675,6 +713,9 @@ _ecore_thread_shutdown(void) | |||
675 | LKD(_ecore_thread_global_hash_mutex); | 713 | LKD(_ecore_thread_global_hash_mutex); |
676 | LKD(_ecore_running_job_mutex); | 714 | LKD(_ecore_running_job_mutex); |
677 | CDD(_ecore_thread_global_hash_cond); | 715 | CDD(_ecore_thread_global_hash_cond); |
716 | # ifdef EFL_HAVE_WIN32_THREADS | ||
717 | LKU(_ecore_thread_win32_lock); | ||
718 | # endif | ||
678 | #endif | 719 | #endif |
679 | } | 720 | } |
680 | 721 | ||