and this too

SVN revision: 50960
This commit is contained in:
Mike Blumenkrantz 2010-08-10 12:00:36 +00:00
parent cbf7f7b58a
commit a589a1bcbe
1 changed files with 12 additions and 71 deletions

View File

@ -19,11 +19,6 @@
#ifndef EINA_INLINE_ARRAY_X_
#define EINA_INLINE_ARRAY_X_
#ifdef EINA_RWLOCKS_ENABLED
# include <pthread.h>
#endif
extern Eina_Bool _eina_array_threadsafety;
/**
* @cond LOCAL
*/
@ -61,29 +56,19 @@ eina_array_push(Eina_Array *array, const void *data)
{
if (!data) return EINA_FALSE;
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_wrlock(&array->lock);
#endif
if (!eina_array_wrlock(array))
return EINA_FALSE;
if (EINA_UNLIKELY((array->count + 1) > array->total))
if (!eina_array_grow(array))
{
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_unlock(&array->lock);
#endif
eina_array_unlock(array);
return EINA_FALSE;
}
array->data[array->count++] = (void*) data;
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_unlock(&array->lock);
#endif
eina_array_unlock(array);
return EINA_TRUE;
}
@ -105,27 +90,17 @@ eina_array_pop(Eina_Array *array)
{
void *ret = NULL;
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_wrlock(&array->lock);
#endif
if (!eina_array_wrlock(array))
return NULL;
if (array->count <= 0)
{
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_unlock(&array->lock);
#endif
eina_array_unlock(array);
return NULL;
}
ret = array->data[--array->count];
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_unlock(&array->lock);
#endif
eina_array_unlock(array);
return ret;
}
@ -142,23 +117,9 @@ eina_array_pop(Eina_Array *array)
* idx. If it is @c NULL or invalid, the program may crash.
*/
static inline void *
eina_array_data_get(Eina_Array *array, unsigned int idx)
eina_array_data_get(const Eina_Array *array, unsigned int idx)
{
void *ret = NULL;
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_rdlock(&array->lock);
#endif
ret = array->data[idx];
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_unlock(&array->lock);
#endif
return ret;
return array->data[idx];
}
/**
@ -173,19 +134,9 @@ eina_array_data_get(Eina_Array *array, unsigned int idx)
* idx. If it is @c NULL or invalid, the program may crash.
*/
static inline void
eina_array_data_set(Eina_Array *array, unsigned int idx, const void *data)
eina_array_data_set(const Eina_Array *array, unsigned int idx, const void *data)
{
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_wrlock(&array->lock);
#endif
array->data[idx] = (void*) data;
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_unlock(&array->lock);
#endif
}
/**
@ -199,19 +150,9 @@ eina_array_data_set(Eina_Array *array, unsigned int idx, const void *data)
* @c NULL or invalid, the program may crash.
*/
static inline unsigned int
eina_array_count_get(Eina_Array *array)
eina_array_count_get(const Eina_Array *array)
{
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_rdlock(&array->lock);
#endif
return array->count;
#ifdef EINA_RWLOCKS_ENABLED
if (_eina_array_threadsafety)
pthread_rwlock_unlock(&array->lock);
#endif
}
/**