summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrique Dante de Almeida <hdante@profusion.mobi>2013-01-25 11:01:56 -0200
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2013-02-26 10:17:28 -0300
commit2ca0be9316d63da11d88a1b2c85606e020790911 (patch)
tree3575c6e0a261d26fea1059a3d271fa12c5951cc9
parentf5d4ae70bd1ff8fba17ebd3e2eb6c65f354185d4 (diff)
ecore: Fix _ecore_glib_select
This fixes a mutex allocated on stack, a race on GCond initialization and use of deprecated functions: g_mutex_new() and friends were deprecated in glib 2.32.
-rw-r--r--src/lib/ecore/ecore_glib.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/lib/ecore/ecore_glib.c b/src/lib/ecore/ecore_glib.c
index 5b73180951..1a4dd55bfa 100644
--- a/src/lib/ecore/ecore_glib.c
+++ b/src/lib/ecore/ecore_glib.c
@@ -13,12 +13,13 @@
13 13
14static Eina_Bool _ecore_glib_active = EINA_FALSE; 14static Eina_Bool _ecore_glib_active = EINA_FALSE;
15static Ecore_Select_Function _ecore_glib_select_original; 15static Ecore_Select_Function _ecore_glib_select_original;
16static GCond *_ecore_glib_cond = NULL;
17static GPollFD *_ecore_glib_fds = NULL; 16static GPollFD *_ecore_glib_fds = NULL;
18static size_t _ecore_glib_fds_size = 0; 17static size_t _ecore_glib_fds_size = 0;
19static const size_t ECORE_GLIB_FDS_INITIAL = 128; 18static const size_t ECORE_GLIB_FDS_INITIAL = 128;
20static const size_t ECORE_GLIB_FDS_STEP = 8; 19static const size_t ECORE_GLIB_FDS_STEP = 8;
21static const size_t ECORE_GLIB_FDS_MAX_FREE = 256; 20static const size_t ECORE_GLIB_FDS_MAX_FREE = 256;
21static GMutex *_ecore_glib_select_lock;
22static GCond *_ecore_glib_select_cond;
22 23
23static Eina_Bool 24static Eina_Bool
24_ecore_glib_fds_resize(size_t size) 25_ecore_glib_fds_resize(size_t size)
@@ -184,34 +185,27 @@ _ecore_glib_select(int ecore_fds,
184 fd_set *efds, 185 fd_set *efds,
185 struct timeval *ecore_timeout) 186 struct timeval *ecore_timeout)
186{ 187{
187 GStaticMutex lock;
188 GMutex *mutex;
189 GMainContext *ctx; 188 GMainContext *ctx;
190 int ret; 189 int ret;
191 190
192 g_static_mutex_init(&lock);
193 mutex = g_static_mutex_get_mutex(&lock);
194 ctx = g_main_context_default(); 191 ctx = g_main_context_default();
195 192
196 if (g_main_context_acquire(ctx)) 193 if (g_main_context_acquire(ctx))
197 { 194 {
198 if (mutex) g_mutex_lock(mutex); 195 g_mutex_lock(_ecore_glib_select_lock);
199 } 196 }
200 else 197 else
201 { 198 {
202 if (!_ecore_glib_cond) 199 while (!g_main_context_wait(ctx, _ecore_glib_select_cond,
203 _ecore_glib_cond = g_cond_new(); 200 _ecore_glib_select_lock))
204
205 while (!g_main_context_wait(ctx, _ecore_glib_cond, mutex))
206 g_thread_yield(); 201 g_thread_yield();
207 } 202 }
208 203
209 ret = _ecore_glib_select__locked 204 ret = _ecore_glib_select__locked
210 (ctx, ecore_fds, rfds, wfds, efds, ecore_timeout); 205 (ctx, ecore_fds, rfds, wfds, efds, ecore_timeout);
211 206
212 if (mutex) g_mutex_unlock(mutex); 207 g_mutex_unlock(_ecore_glib_select_lock);
213 g_main_context_release(ctx); 208 g_main_context_release(ctx);
214 g_static_mutex_free(&lock);
215 209
216 return ret; 210 return ret;
217} 211}
@@ -221,6 +215,17 @@ _ecore_glib_select(int ecore_fds,
221void 215void
222_ecore_glib_init(void) 216_ecore_glib_init(void)
223{ 217{
218#ifdef HAVE_GLIB
219#if GLIB_CHECK_VERSION(2,32,0)
220 _ecore_glib_select_lock = malloc(sizeof(GMutex));
221 g_mutex_init(_ecore_glib_select_lock);
222 _ecore_glib_select_cond = malloc(sizeof(GCond));
223 g_cond_init(_ecore_glib_select_cond);
224#else
225 _ecore_glib_select_lock = g_mutex_new();
226 _ecore_glib_select_cond = g_cond_new();
227#endif
228#endif
224} 229}
225 230
226void 231void
@@ -240,11 +245,19 @@ _ecore_glib_shutdown(void)
240 } 245 }
241 _ecore_glib_fds_size = 0; 246 _ecore_glib_fds_size = 0;
242 247
243 if (_ecore_glib_cond) 248#if GLIB_CHECK_VERSION(2,32,0)
244 { 249 g_mutex_clear(_ecore_glib_select_lock);
245 g_cond_free(_ecore_glib_cond); 250 free(_ecore_glib_select_lock);
246 _ecore_glib_cond = NULL; 251 _ecore_glib_select_lock = NULL;
247 } 252 g_cond_clear(_ecore_glib_select_cond);
253 free(_ecore_glib_select_cond);
254 _ecore_glib_select_cond = NULL;
255#else
256 g_mutex_free(_ecore_glib_select_lock);
257 _ecore_glib_select_lock = NULL;
258 g_cond_free(_ecore_glib_select_cond);
259 _ecore_glib_select_cond = NULL;
260#endif
248#endif 261#endif
249} 262}
250 263