should probably make thread functions threadsafe. and compile.
authordiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 21 Jul 2010 08:33:25 +0000 (08:33 +0000)
committerdiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 21 Jul 2010 08:33:25 +0000 (08:33 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@50411 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/ecore/ecore_thread.c

index c8333d8..3f0fe37 100644 (file)
@@ -664,8 +664,12 @@ ecore_thread_notify(Ecore_Thread *thread, const void *data)
 EAPI int
 ecore_thread_active_get(void)
 {
+   int ret;
 #ifdef EFL_HAVE_PTHREAD
-   return _ecore_thread_count;
+   pthread_mutex_lock(&_mutex);
+   ret = _ecore_thread_count;
+   pthread_mutex_unlock(&_mutex);
+   return ret;
 #else
    return 0;
 #endif
@@ -680,8 +684,12 @@ ecore_thread_active_get(void)
 EAPI int
 ecore_thread_pending_get(void)
 {
+   int ret;
 #ifdef EFL_HAVE_PTHREAD
-   return eina_list_count(_ecore_pending_job_threads);
+   pthread_mutex_lock(&_mutex);
+   ret = eina_list_count(_ecore_pending_job_threads);
+   pthread_mutex_unlock(&_mutex);
+   return ret;
 #else
    return 0;
 #endif
@@ -696,8 +704,12 @@ ecore_thread_pending_get(void)
 EAPI int
 ecore_thread_pending_long_get(void)
 {
+   int ret;
 #ifdef EFL_HAVE_PTHREAD
-   return eina_list_count(_ecore_pending_job_threads_long);
+   pthread_mutex_lock(&_mutex);
+   ret = eina_list_count(_ecore_pending_job_threads_long);
+   pthread_mutex_unlock(&_mutex);
+   return ret;
 #else
    return 0;
 #endif
@@ -712,8 +724,12 @@ ecore_thread_pending_long_get(void)
 EAPI int
 ecore_thread_pending_total_get(void)
 {
+   int ret;
 #ifdef EFL_HAVE_PTHREAD
-   return eina_list_count(_ecore_pending_job_threads) + eina_list_count(_ecore_pending_job_threads_long);
+   pthread_mutex_lock(&_mutex);
+   ret = eina_list_count(_ecore_pending_job_threads) + eina_list_count(_ecore_pending_job_threads_long);
+   pthread_mutex_unlock(&_mutex);
+   return ret;
 #else
    return 0;
 #endif
@@ -728,6 +744,11 @@ ecore_thread_pending_total_get(void)
 EAPI int
 ecore_thread_max_get(void)
 {
+   int ret;
+   pthread_mutex_lock(&_mutex);
+   ret = _ecore_thread_count_max;
+   pthread_mutex_unlock(&_mutex);
+
    return _ecore_thread_count_max;
 }
 
@@ -744,7 +765,9 @@ ecore_thread_max_set(int num)
    /* avoid doing something hilarious by blocking dumb users */
    if (num >= (2 * eina_cpu_count())) return;
 
+   pthread_mutex_lock(&_mutex);
    _ecore_thread_count_max = num;
+   pthread_mutex_unlock(&_mutex);
 }
 
 /**
@@ -755,7 +778,9 @@ ecore_thread_max_set(int num)
 EAPI void
 ecore_thread_max_reset(void)
 {
+   pthread_mutex_lock(&_mutex);
    _ecore_thread_count_max = eina_cpu_count();
+   pthread_mutex_unlock(&_mutex);
 }
 
 /**
@@ -768,8 +793,12 @@ ecore_thread_max_reset(void)
 EAPI int
 ecore_thread_available_get(void)
 {
+   int ret;
 #ifdef EFL_HAVE_PTHREAD
-   return _ecore_thread_count_max - _ecore_thread_count);
+   pthread_mutex_lock(&_mutex);
+   ret = _ecore_thread_count_max - _ecore_thread_count;
+   pthread_mutex_unlock(&_mutex);
+   return ret;
 #else
    return 0;
 #endif