summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2018-01-17 17:31:51 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2018-01-17 17:37:03 +0900
commit910f318ad9bf39af19d583876afcb25be2cfaafa (patch)
tree80c6dd23037b2100abe8892f546834708851c513
parent1a39e2d4291fdd3b298910f8d3512193b76c27f5 (diff)
examples: Simplify & fix thread example
This fixes the example for Windows, where apparently it ran into a lot of errors with spinlock. Note that on Linux we have such errors too (both before and after the patch): EINA ERROR: 'Invalid argument' on lock 0x7ffd218af410 EINA ERROR: 'Invalid argument' on unlock 0x7ffd218af410 Patch by @vtorri
-rw-r--r--src/examples/ecore/ecore_thread_example.c66
1 files changed, 27 insertions, 39 deletions
diff --git a/src/examples/ecore/ecore_thread_example.c b/src/examples/ecore/ecore_thread_example.c
index 0c7f7309e4..aac7643734 100644
--- a/src/examples/ecore/ecore_thread_example.c
+++ b/src/examples/ecore/ecore_thread_example.c
@@ -3,7 +3,6 @@
3 */ 3 */
4#include <stdio.h> 4#include <stdio.h>
5#include <stdlib.h> 5#include <stdlib.h>
6#include <dirent.h>
7#include <unistd.h> 6#include <unistd.h>
8 7
9#include <Ecore.h> 8#include <Ecore.h>
@@ -91,13 +90,9 @@ _feedback_job(void *data EINA_UNUSED, Ecore_Thread *th)
91 time_t t; 90 time_t t;
92 int i, count; 91 int i, count;
93 Feedback_Thread_Data *ftd = NULL; 92 Feedback_Thread_Data *ftd = NULL;
94#ifdef _WIN32 93 Eina_Iterator *it;
95 HANDLE h;
96 WIN32_FIND_DATA fd;
97#else
98 DIR *dir;
99#endif
100 App_Msg *msg; 94 App_Msg *msg;
95 char *name;
101 96
102 count = (int)(uintptr_t)ecore_thread_global_data_find("count"); 97 count = (int)(uintptr_t)ecore_thread_global_data_find("count");
103 for (i = 0; i < count; i++) 98 for (i = 0; i < count; i++)
@@ -115,45 +110,26 @@ _feedback_job(void *data EINA_UNUSED, Ecore_Thread *th)
115 if (!ftd) 110 if (!ftd)
116 return; 111 return;
117 112
118#ifdef _WIN32 113 it = eina_file_ls(ftd->base);
119 h = FindFirstFile(ftd->base, &fd); 114 if (!it)
120 if (h == INVALID_HANDLE_VALUE)
121 goto the_end; 115 goto the_end;
122#else
123 dir = opendir(ftd->base);
124 if (!dir)
125 goto the_end;
126#endif
127 116
128 msg = calloc(1, sizeof(App_Msg)); 117 msg = calloc(1, sizeof(App_Msg));
129 118
130 t = time(NULL); 119 t = time(NULL);
131 while (time(NULL) < t + 2) 120 EINA_ITERATOR_FOREACH(it, name)
132 { 121 {
133#ifdef _WIN32 122 if (time(NULL) >= (t + 2))
134 if (strlen(fd.cFileName) >= 10) 123 {
135 msg->list = eina_list_append(msg->list, 124 eina_stringshare_del(name);
136 strdup(fd.cFileName)); 125 break;
137 FindNextFile(h, &fd); 126 }
138#else 127 if (eina_stringshare_strlen(name) >= 10)
139 struct dirent entry, *result; 128 msg->list = eina_list_append(msg->list, strdup(name));
140 129 eina_stringshare_del(name);
141 if (readdir_r(dir, &entry, &result))
142 break;
143 if (!result)
144 break;
145
146 if (strlen(result->d_name) >= 10)
147 msg->list = eina_list_append(msg->list,
148 strdup(result->d_name));
149#endif
150 } 130 }
151 131
152#ifdef _WIN32 132 eina_iterator_free(it);
153 FindClose(h);
154#else
155 closedir(dir);
156#endif
157 ecore_thread_feedback(th, msg); 133 ecore_thread_feedback(th, msg);
158 134
159the_end: 135the_end:
@@ -350,17 +326,29 @@ main(int argc, char *argv[])
350 ecore_thread_global_data_add("count", (void *)3, NULL, EINA_FALSE); 326 ecore_thread_global_data_add("count", (void *)3, NULL, EINA_FALSE);
351 ftd = calloc(1, sizeof(Feedback_Thread_Data)); 327 ftd = calloc(1, sizeof(Feedback_Thread_Data));
352 ftd->name = strdup("data0"); 328 ftd->name = strdup("data0");
329#ifdef _WIN32
330 ftd->base = strdup("c:/windows/System32");
331#else
353 ftd->base = strdup("/usr/bin"); 332 ftd->base = strdup("/usr/bin");
333#endif
354 eina_lock_new(&ftd->mutex); 334 eina_lock_new(&ftd->mutex);
355 ecore_thread_global_data_add(ftd->name, ftd, NULL, EINA_TRUE); 335 ecore_thread_global_data_add(ftd->name, ftd, NULL, EINA_TRUE);
356 ftd = calloc(1, sizeof(Feedback_Thread_Data)); 336 ftd = calloc(1, sizeof(Feedback_Thread_Data));
357 ftd->name = strdup("data1"); 337 ftd->name = strdup("data1");
338#ifdef _WIN32
339 ftd->base = strdup("c:/windows/Fonts");
340#else
358 ftd->base = strdup("/usr/lib"); 341 ftd->base = strdup("/usr/lib");
342#endif
359 eina_lock_new(&ftd->mutex); 343 eina_lock_new(&ftd->mutex);
360 ecore_thread_global_data_add(ftd->name, ftd, NULL, EINA_TRUE); 344 ecore_thread_global_data_add(ftd->name, ftd, NULL, EINA_TRUE);
361 ftd = calloc(1, sizeof(Feedback_Thread_Data)); 345 ftd = calloc(1, sizeof(Feedback_Thread_Data));
362 ftd->name = strdup("data2"); 346 ftd->name = strdup("data2");
363 ftd->base = strdup("/usr/share"); 347#ifdef _WIN32
348 ftd->base = strdup("c:/windows/Help");
349#else
350 ftd->base = strdup("/usr/lib");
351#endif
364 eina_lock_new(&ftd->mutex); 352 eina_lock_new(&ftd->mutex);
365 ecore_thread_global_data_add(ftd->name, ftd, NULL, EINA_TRUE); 353 ecore_thread_global_data_add(ftd->name, ftd, NULL, EINA_TRUE);
366 } 354 }