From: "Sung W. Park" <sungwoo@gmail.com>

"... I've created a resource context per thread using TLS.  Since there is no
TLS support in Eina, I've added 4 APIs for that as well.  Another patch has
been submitted but i'll just include it in here as well. ..."
   


SVN revision: 64120
This commit is contained in:
Sung W. Park 2011-10-17 05:06:01 +00:00 committed by Carsten Haitzler
parent 7c683d0b0c
commit fef1dc318f
6 changed files with 120 additions and 1 deletions

View File

@ -19,3 +19,4 @@ Sebastian Dransfeld <sd@tango.flipp.net>
Myungjae Lee <mjae.lee@samsung.com>
Youness Alaoui <kakaroto@kakaroto.homelinux.net>
billiob (Boris Faure) <billiob@gmail.com>
Sung W. Park <sungwoo@gmail.com>

View File

@ -44,6 +44,7 @@ typedef void (*Eina_Lock_Bt_Func) ();
typedef struct _Eina_Lock Eina_Lock;
typedef struct _Eina_RWLock Eina_RWLock;
typedef struct _Eina_Condition Eina_Condition;
typedef pthread_key_t Eina_TLS;
struct _Eina_Lock
{
@ -477,4 +478,32 @@ eina_rwlock_release(Eina_RWLock *mutex)
return EINA_LOCK_SUCCEED;
}
static inline Eina_Bool
eina_tls_new(Eina_TLS *key)
{
if (pthread_key_create(key, NULL) != 0)
return EINA_FALSE;
return EINA_TRUE;
}
static inline void
eina_tls_free(Eina_TLS key)
{
pthread_key_delete(key);
}
static inline void *
eina_tls_get(Eina_TLS key)
{
return pthread_getspecific(key);
}
static inline Eina_Bool
eina_tls_set(Eina_TLS key, const void *data)
{
if (pthread_setspecific(key, data) != 0)
return EINA_FALSE;
return EINA_TRUE;
}
#endif

View File

@ -215,6 +215,30 @@ eina_rwlock_take_write(Eina_RWLock *mutex EINA_UNUSED)
return EINA_LOCK_FAIL;
}
static inline Eina_Bool
eina_tls_new(Eina_TLS *key)
{
return EINA_FALSE;
}
static inline void
eina_tls_free(Eina_TLS key)
{
}
static inline void *
eina_tls_get(Eina_TLS key)
{
return NULL;
}
static inline Eina_Bool
eina_tls_set(Eina_TLS key, const void *data)
{
return EINA_FALSE;
}
/**
* @}
*/

View File

@ -433,4 +433,32 @@ eina_rwlock_release(Eina_RWLock *mutex)
return EINA_LOCK_SUCCEED;
}
static inline Eina_Bool
eina_tls_new(Eina_TLS *key)
{
if (TlsAlloc() == TLS_OUT_OF_INDEXES)
return EINA_FALSE;
return EINA_TRUE;
}
static inline void
eina_tls_free(Eina_TLS key)
{
TlsFree(key);
}
static inline void *
eina_tls_get(Eina_TLS key)
{
return (void*)TlsGetValue(key);
}
static inline Eina_Bool
eina_tls_set(Eina_TLS key, const void *data)
{
if (TlsSetValue(key, (LPVOID)data) == 0)
return EINA_FALSE;
return EINA_TRUE;
}
#endif

View File

@ -23,8 +23,9 @@
EAPI extern Eina_Bool _threads_activated;
typedef HANDLE Eina_Lock;
typedef HANDLE Eina_Lock;
typedef Eina_Lock Eina_RWLock;
typedef DWORD Eina_TLS;
static inline Eina_Bool
eina_lock_new(Eina_Lock *mutex)
@ -144,4 +145,34 @@ eina_rwlock_release(Eina_RWLock *mutex)
return eina_lock_release(mutex);
}
static inline Eina_Bool
eina_tls_new(Eina_TLS *key)
{
if (TlsAlloc() == TLS_OUT_OF_INDEXES)
return EINA_FALSE;
return EINA_TRUE;
}
static inline void
eina_tls_free(Eina_TLS key)
{
TlsFree(key);
}
static inline void *
eina_tls_get(Eina_TLS key)
{
return (void*)TlsGetValue(key);
}
static inline Eina_Bool
eina_tls_set(Eina_TLS key, const void *data)
{
if (TlsSetValue(key, (LPVOID)data) == 0)
return EINA_FALSE;
return EINA_TRUE;
}
#endif

View File

@ -76,6 +76,12 @@ static inline Eina_Lock_Result eina_rwlock_take_read(Eina_RWLock *mutex);
static inline Eina_Lock_Result eina_rwlock_take_write(Eina_RWLock *mutex);
static inline Eina_Lock_Result eina_rwlock_release(Eina_RWLock *mutex);
static inline Eina_Bool eina_tls_new(Eina_TLS *key);
static inline void eina_tls_free(Eina_TLS key);
static inline void *eina_tls_get(Eina_TLS key);
static inline Eina_Bool eina_tls_set(Eina_TLS key, const void *data);
#ifdef EINA_HAVE_DEBUG_THREADS
# define EINA_MAIN_LOOP_CHECK_RETURN_VAL(val) \
do { \