"... 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. ..."
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@64120
7cbeb6ba-43b4-40fd-8cce-
4c39aea84d33
Myungjae Lee <mjae.lee@samsung.com>
Youness Alaoui <kakaroto@kakaroto.homelinux.net>
billiob (Boris Faure) <billiob@gmail.com>
+Sung W. Park <sungwoo@gmail.com>
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
{
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
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;
+}
+
+
/**
* @}
*/
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
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)
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
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 { \