forked from enlightenment/efl
parent
cbf7f7b58a
commit
a589a1bcbe
|
@ -19,11 +19,6 @@
|
||||||
#ifndef EINA_INLINE_ARRAY_X_
|
#ifndef EINA_INLINE_ARRAY_X_
|
||||||
#define 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
|
* @cond LOCAL
|
||||||
*/
|
*/
|
||||||
|
@ -61,29 +56,19 @@ eina_array_push(Eina_Array *array, const void *data)
|
||||||
{
|
{
|
||||||
if (!data) return EINA_FALSE;
|
if (!data) return EINA_FALSE;
|
||||||
|
|
||||||
#ifdef EINA_RWLOCKS_ENABLED
|
if (!eina_array_wrlock(array))
|
||||||
if (_eina_array_threadsafety)
|
return EINA_FALSE;
|
||||||
pthread_rwlock_wrlock(&array->lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (EINA_UNLIKELY((array->count + 1) > array->total))
|
if (EINA_UNLIKELY((array->count + 1) > array->total))
|
||||||
if (!eina_array_grow(array))
|
if (!eina_array_grow(array))
|
||||||
{
|
{
|
||||||
|
eina_array_unlock(array);
|
||||||
#ifdef EINA_RWLOCKS_ENABLED
|
|
||||||
if (_eina_array_threadsafety)
|
|
||||||
pthread_rwlock_unlock(&array->lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
array->data[array->count++] = (void*) data;
|
array->data[array->count++] = (void*) data;
|
||||||
|
|
||||||
#ifdef EINA_RWLOCKS_ENABLED
|
eina_array_unlock(array);
|
||||||
if (_eina_array_threadsafety)
|
|
||||||
pthread_rwlock_unlock(&array->lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -105,27 +90,17 @@ eina_array_pop(Eina_Array *array)
|
||||||
{
|
{
|
||||||
void *ret = NULL;
|
void *ret = NULL;
|
||||||
|
|
||||||
#ifdef EINA_RWLOCKS_ENABLED
|
if (!eina_array_wrlock(array))
|
||||||
if (_eina_array_threadsafety)
|
return NULL;
|
||||||
pthread_rwlock_wrlock(&array->lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (array->count <= 0)
|
if (array->count <= 0)
|
||||||
{
|
{
|
||||||
|
eina_array_unlock(array);
|
||||||
#ifdef EINA_RWLOCKS_ENABLED
|
|
||||||
if (_eina_array_threadsafety)
|
|
||||||
pthread_rwlock_unlock(&array->lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ret = array->data[--array->count];
|
ret = array->data[--array->count];
|
||||||
|
|
||||||
#ifdef EINA_RWLOCKS_ENABLED
|
eina_array_unlock(array);
|
||||||
if (_eina_array_threadsafety)
|
|
||||||
pthread_rwlock_unlock(&array->lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -142,23 +117,9 @@ eina_array_pop(Eina_Array *array)
|
||||||
* idx. If it is @c NULL or invalid, the program may crash.
|
* idx. If it is @c NULL or invalid, the program may crash.
|
||||||
*/
|
*/
|
||||||
static inline void *
|
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;
|
return array->data[idx];
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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.
|
* idx. If it is @c NULL or invalid, the program may crash.
|
||||||
*/
|
*/
|
||||||
static inline void
|
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;
|
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.
|
* @c NULL or invalid, the program may crash.
|
||||||
*/
|
*/
|
||||||
static inline unsigned int
|
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;
|
return array->count;
|
||||||
|
|
||||||
#ifdef EINA_RWLOCKS_ENABLED
|
|
||||||
if (_eina_array_threadsafety)
|
|
||||||
pthread_rwlock_unlock(&array->lock);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue