From: "Sung W. Park" <sungwoo@gmail.com>
authorSung W. Park <sungwoo@gmail.com>
Mon, 17 Oct 2011 05:06:01 +0000 (05:06 +0000)
committerraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 17 Oct 2011 05:06:01 +0000 (05:06 +0000)
"... 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

AUTHORS
src/include/eina_inline_lock_posix.x
src/include/eina_inline_lock_void.x
src/include/eina_inline_lock_win32.x
src/include/eina_inline_lock_wince.x
src/include/eina_lock.h

diff --git a/AUTHORS b/AUTHORS
index 354de52..1483270 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -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>
index 2da5bfc..77f5b8b 100644 (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
index e6d503a..64097af 100644 (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;
+}
+
+
 /**
  * @}
  */
index 7cc58b9..fa0c8e6 100644 (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
index 1be0890..965d475 100644 (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
index 3b2f610..7c26dc0 100644 (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 {                                                                 \