refcount locks to avoid deadlocks; array threadsafety should be good to go now
authordiscomfitor <discomfitor>
Tue, 10 Aug 2010 12:14:59 +0000 (12:14 +0000)
committerdiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 10 Aug 2010 12:14:59 +0000 (12:14 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@50962 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/include/eina_array.h

index d133d66..4d8ec5d 100644 (file)
@@ -107,12 +107,14 @@ eina_array_rdlock(Eina_Array *array)
    if (!array) return EINA_FALSE;
    if (array->threadsafe)
      {
-        int ret;
+        if (!array->lockcount++)
+          {
+             int ret;
 
-        ret = pthread_rwlock_rdlock(&array->lock);
-        if ((ret != 0) && (ret != EDEADLK))
-          return EINA_FALSE;
-        array->lockcount++;
+             ret = pthread_rwlock_rdlock(&array->lock);
+             if ((ret != 0) && (ret != EDEADLK))
+               return EINA_FALSE;
+          }
      }
    return EINA_TRUE;
 }
@@ -123,12 +125,14 @@ eina_array_wrlock(Eina_Array *array)
    if (!array) return EINA_FALSE;
    if (array->threadsafe)
      {
-        int ret;
+        if (!array->lockcount++)
+          {
+             int ret;
 
-        ret = pthread_rwlock_wrlock(&array->lock);
-        if ((ret != 0) && (ret != EDEADLK))
-          return EINA_FALSE;
-        array->lockcount++;
+             ret = pthread_rwlock_wrlock(&array->lock);
+             if ((ret != 0) && (ret != EDEADLK))
+               return EINA_FALSE;
+          }
      }
    return EINA_TRUE;
 }