evas: don't use EINA_LOCK_INITIALIZER and improve eina_threads call.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 2 May 2011 11:28:47 +0000 (11:28 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 2 May 2011 11:28:47 +0000 (11:28 +0000)
Only call eina_threads_shutdown when thread are dead and not before.

Release and destroy thread lock before calling evas_async_events_process
as you should never have a lock taken in the main loop when calling it.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@59119 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/cache/evas_cache_image.c
src/lib/cache/evas_preload.c

index 85064b7..cec7402 100644 (file)
@@ -31,8 +31,9 @@ struct _Evas_Cache_Preload
    Image_Entry *ie;
 };
 
-static LK(engine_lock) = EINA_LOCK_INITIALIZER; 
-static LK(wakeup) = EINA_LOCK_INITIALIZER;
+static LK(engine_lock);
+static LK(wakeup);
+static int _evas_cache_mutex_init = 0;
 
 static pthread_cond_t cond_wakeup = PTHREAD_COND_INITIALIZER;
 
@@ -553,6 +554,12 @@ evas_cache_image_init(const Evas_Cache_Image_Func *cb)
 {
    Evas_Cache_Image *cache;
 
+   if (_evas_cache_mutex_init++ == 0)
+     {
+        LKI(engine_lock);
+        LKI(wakeup);
+     }
+
    cache = calloc(1, sizeof(Evas_Cache_Image));
    if (!cache) return NULL;
    cache->func = *cb;
@@ -583,13 +590,19 @@ evas_cache_image_shutdown(Evas_Cache_Image *cache)
    LKL(cache->lock);
 #endif
    cache->references--;
-   if (cache->references > 0)
+   if (cache->references != 0)
      {
 #ifdef EVAS_FRAME_QUEUING
         LKU(cache->lock);
 #endif
         return;
      }
+#ifdef EVAS_FRAME_QUEUING
+   /* Release and destroy lock early ! */
+   LKU(cache->lock);
+   LKD(cache->lock);
+#endif
+
 #ifdef BUILD_ASYNC_PRELOAD
    EINA_LIST_FREE(cache->preload, im)
      {
@@ -638,11 +651,13 @@ evas_cache_image_shutdown(Evas_Cache_Image *cache)
 #endif
    eina_hash_free(cache->activ);
    eina_hash_free(cache->inactiv);
-#ifdef EVAS_FRAME_QUEUING
-   LKU(cache->lock);
-   LKD(cache->lock);
-#endif
    free(cache);
+
+   if (--_evas_cache_mutex_init == 0)
+     {
+        LKD(engine_lock);
+        LKD(wakeup);
+     }
 }
 
 EAPI Image_Entry *
index f4b3521..95c723d 100644 (file)
@@ -45,7 +45,7 @@ struct _Evas_Preload_Pthread_Data
 static int _threads_count = 0;
 static Evas_Preload_Pthread_Worker *_workers = NULL;
 
-static LK(_mutex) = EINA_LOCK_INITIALIZER;
+static LK(_mutex);
 
 static void
 _evas_preload_thread_end(void *data)
@@ -54,6 +54,8 @@ _evas_preload_thread_end(void *data)
    Evas_Preload_Pthread_Data *p = NULL;
 
    if (pthread_join(pth->thread, (void **)&p) != 0) free(p);
+
+   eina_threads_shutdown();
 }
 
 static void
@@ -67,7 +69,6 @@ _evas_preload_thread_done(void *target __UNUSED__, Evas_Callback_Type type __UNU
    else
       work->func_end(work->data);
 
-   eina_threads_shutdown();
    free(work);
 }
 
@@ -76,7 +77,7 @@ _evas_preload_thread_worker(void *data)
 {
    Evas_Preload_Pthread_Data *pth = data;
    Evas_Preload_Pthread_Worker *work;
-   
+
    eina_sched_prio_drop();
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
@@ -129,6 +130,8 @@ _evas_preload_thread_init(void)
 {
    _threads_max = eina_cpu_count();
    if (_threads_max < 1) _threads_max = 1;
+
+   LKI(_mutex);
 }
 
 void
@@ -151,6 +154,8 @@ _evas_preload_thread_shutdown(void)
        free(work);
      }
    LKU(_mutex);
+
+   LKD(_mutex);
 #endif
 }