]> git.sur5r.net Git - openldap/commitdiff
Added native thread-specific data support
authorHoward Chu <hyc@openldap.org>
Thu, 25 Oct 2007 06:42:40 +0000 (06:42 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 25 Oct 2007 06:42:40 +0000 (06:42 +0000)
include/ldap_int_thread.h
include/ldap_pvt_thread.h
libraries/libldap_r/thr_cthreads.c
libraries/libldap_r/thr_nt.c
libraries/libldap_r/thr_posix.c
libraries/libldap_r/thr_pth.c
libraries/libldap_r/thr_stub.c
libraries/libldap_r/thr_thr.c
libraries/libldap_r/tpool.c

index d6a6d779575564762c1c324635562ea9acfcb270..db345df06dedd639b25526d04991cc92ae120d59 100644 (file)
@@ -44,6 +44,7 @@ LDAP_BEGIN_DECL
 typedef pthread_t              ldap_int_thread_t;
 typedef pthread_mutex_t                ldap_int_thread_mutex_t;
 typedef pthread_cond_t         ldap_int_thread_cond_t;
+typedef pthread_key_t          ldap_int_thread_key_t;
 
 #define ldap_int_thread_equal(a, b)    pthread_equal((a), (b))
 
@@ -88,6 +89,7 @@ LDAP_BEGIN_DECL
 typedef cthread_t              ldap_int_thread_t;
 typedef struct mutex           ldap_int_thread_mutex_t;
 typedef struct condition       ldap_int_thread_cond_t;
+typedef cthread_key_t          ldap_int_thread_key_t;
 
 LDAP_END_DECL
 
@@ -106,6 +108,7 @@ LDAP_BEGIN_DECL
 typedef pth_t          ldap_int_thread_t;
 typedef pth_mutex_t    ldap_int_thread_mutex_t;
 typedef pth_cond_t     ldap_int_thread_cond_t;
+typedef pth_key_t      ldap_int_thread_key_t;
 
 #if 0
 #define LDAP_THREAD_HAVE_RDWR 1
@@ -129,6 +132,7 @@ LDAP_BEGIN_DECL
 typedef thread_t               ldap_int_thread_t;
 typedef mutex_t                        ldap_int_thread_mutex_t;
 typedef cond_t                 ldap_int_thread_cond_t;
+typedef thread_key_t   ldap_int_thread_key_t;
 
 #define HAVE_REENTRANT_FUNCTIONS 1
 
@@ -181,6 +185,7 @@ LDAP_BEGIN_DECL
 typedef unsigned long  ldap_int_thread_t;
 typedef HANDLE ldap_int_thread_mutex_t;
 typedef HANDLE ldap_int_thread_cond_t;
+typedef DWORD  ldap_int_thread_key_t;
 
 LDAP_END_DECL
 
@@ -201,6 +206,7 @@ LDAP_BEGIN_DECL
 typedef int                    ldap_int_thread_t;
 typedef int                    ldap_int_thread_mutex_t;
 typedef int                    ldap_int_thread_cond_t;
+typedef int                    ldap_int_thread_key_t;
 
 #define LDAP_THREAD_HAVE_TPOOL 1
 typedef int                    ldap_int_thread_pool_t;
index 151756d692a03690537699f3e3f3ec709e6f1af6..21b2dc69cdf3affcca2b2db47d5ed4404b06c3bc 100644 (file)
@@ -34,6 +34,7 @@ typedef ldap_int_thread_cond_t                ldap_pvt_thread_cond_t;
 typedef ldap_int_thread_rdwr_t         ldap_pvt_thread_rdwr_t;
 #endif
 typedef ldap_int_thread_rmutex_t       ldap_pvt_thread_rmutex_t;
+typedef ldap_int_thread_key_t  ldap_pvt_thread_key_t;
 #endif /* !LDAP_PVT_THREAD_H_DONE */
 
 #define ldap_pvt_thread_equal          ldap_int_thread_equal
@@ -169,6 +170,18 @@ ldap_pvt_thread_rdwr_wtrylock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
 LDAP_F( int )
 ldap_pvt_thread_rdwr_wunlock LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
 
+LDAP_F( int )
+ldap_pvt_thread_key_create LDAP_P((ldap_pvt_thread_key_t *keyp));
+
+LDAP_F( int )
+ldap_pvt_thread_key_destroy LDAP_P((ldap_pvt_thread_key_t key));
+
+LDAP_F( int )
+ldap_pvt_thread_key_setdata LDAP_P((ldap_pvt_thread_key_t key, void *data));
+
+LDAP_F( int )
+ldap_pvt_thread_key_getdata LDAP_P((ldap_pvt_thread_key_t key, void **data));
+
 #ifdef LDAP_DEBUG
 LDAP_F( int )
 ldap_pvt_thread_rdwr_readers LDAP_P((ldap_pvt_thread_rdwr_t *rdwrp));
index b98a47afa2caa28f736207e6a19a7faa6c73e84f..ab19880bb77d3f18c90b5df31336bf01f6519be4 100644 (file)
@@ -153,4 +153,28 @@ ldap_pvt_thread_self( void )
        return cthread_self();
 }
 
+int
+ldap_pvt_thread_key_create( ldap_pvt_thread_key_t *key )
+{
+       return cthread_keycreate( key );
+}
+
+int
+ldap_pvt_thread_key_destroy( ldap_pvt_thread_key_t key )
+{
+       return( 0 );
+}
+
+int
+ldap_pvt_thread_key_setdata( ldap_pvt_thread_key_t key, void *data )
+{
+       return cthread_setspecific( key, data );
+}
+
+int
+ldap_pvt_thread_key_getdata( ldap_pvt_thread_key_t key, void **data )
+{
+       return cthread_getspecific( key, data );
+}
+
 #endif /* HAVE_MACH_CTHREADS */
index f3d0755de99941f3a78f237b3c40a6d4349c9330..29416fa85e0071b2f6915987bd27d0608d1dcc97 100644 (file)
@@ -198,4 +198,37 @@ ldap_pvt_thread_self( void )
        return GetCurrentThreadId();
 }
 
+int
+ldap_pvt_thread_key_create( ldap_pvt_thread_key_t *keyp )
+{
+       DWORD key = TlsAlloc();
+       if ( key != TLS_OUT_OF_INDEXES ) {
+               *keyp = key;
+               return 0;
+       } else {
+               return -1;
+       }
+}
+
+int
+ldap_pvt_thread_key_destroy( ldap_pvt_thread_key_t key )
+{
+       /* TlsFree returns 0 on failure */
+       return( TlsFree( key ) == 0 );
+}
+
+int
+ldap_pvt_thread_key_setdata( ldap_pvt_thread_key_t key, void *data )
+{
+       return ( TlsSetValue( key, data ) == 0 );
+}
+
+int
+ldap_pvt_thread_key_getdata( ldap_pvt_thread_key_t key, void **data )
+{
+       void *ptr = TlsGetValue( key );
+       *data = ptr;
+       return( ptr ? GetLastError() : 0 );
+}
+
 #endif
index 4e0a45b4321b44872a5b8f20915ce6fd1341288f..34914b626f959e7454821ecd111e991b8f4f7383 100644 (file)
@@ -312,6 +312,31 @@ ldap_pvt_thread_t ldap_pvt_thread_self( void )
        return pthread_self();
 }
 
+int
+ldap_pvt_thread_key_create( ldap_pvt_thread_key_t *key )
+{
+       return pthread_key_create( key, NULL );
+}
+
+int
+ldap_pvt_thread_key_destroy( ldap_pvt_thread_key_t key )
+{
+       return pthread_key_delete( key );
+}
+
+int
+ldap_pvt_thread_key_setdata( ldap_pvt_thread_key_t key, void *data )
+{
+       return pthread_setspecific( key, data );
+}
+
+int
+ldap_pvt_thread_key_getdata( ldap_pvt_thread_key_t key, void **data )
+{
+       *data = pthread_getspecific( key );
+       return 0;
+}
+
 #ifdef LDAP_THREAD_HAVE_RDWR
 #ifdef HAVE_PTHREAD_RWLOCK_DESTROY
 int 
index c5844533c12da13974e8ecb9ed13b651c0240ab2..f06efe0d130730637c29e3a188e3b6209abecca6 100644 (file)
@@ -159,6 +159,31 @@ ldap_pvt_thread_self( void )
        return pth_self();
 }
 
+int
+ldap_pvt_thread_key_create( ldap_pvt_thread_key_t *key )
+{
+       return pth_key_create( key, NULL );
+}
+
+int
+ldap_pvt_thread_key_destroy( ldap_pvt_thread_key_t key )
+{
+       return pth_key_delete( key );
+}
+
+int
+ldap_pvt_thread_key_setdata( ldap_pvt_thread_key_t key, void *data )
+{
+       return pth_key_setdata( key, data );
+}
+
+int
+ldap_pvt_thread_key_getdata( ldap_pvt_thread_key_t key, void **data )
+{
+       *data = pth_key_getdata( key );
+       return 0;
+}
+
 #ifdef LDAP_THREAD_HAVE_RDWR
 int 
 ldap_pvt_thread_rdwr_init( ldap_pvt_thread_rdwr_t *rw )
index 1dce9d160be0f08a4796bd01e2537fd73b2c8bb5..65a18bd0ac1bb919b21b01a78ec3db1fbbd3f4c4 100644 (file)
@@ -237,6 +237,30 @@ ldap_pvt_thread_self( void )
        return(0);
 }
 
+int
+ldap_pvt_thread_key_create( ldap_pvt_thread_key_t *key )
+{
+       return(0);
+}
+
+int
+ldap_pvt_thread_key_destroy( ldap_pvt_thread_key_t key )
+{
+       return(0);
+}
+
+int
+ldap_pvt_thread_key_setdata( ldap_pvt_thread_key_t key, void *data )
+{
+       return(0);
+}
+
+int
+ldap_pvt_thread_key_getdata( ldap_pvt_thread_key_t key, void **data )
+{
+       return(0);
+}
+
 ldap_pvt_thread_t
 ldap_pvt_thread_pool_tid( void *vctx )
 {
index 2acbe083a64978566581134e46a507defc2dbe5e..2a9abae5454f160180ad822b0a03698df0dadb44 100644 (file)
@@ -159,4 +159,28 @@ ldap_pvt_thread_self( void )
        return thr_self();
 }
 
+int
+ldap_pvt_thread_key_create( ldap_pvt_thread_key_t *key )
+{
+       return thr_keycreate( key, NULL );
+}
+
+int
+ldap_pvt_thread_key_destroy( ldap_pvt_thread_key_t key )
+{
+       return( 0 );
+}
+
+int
+ldap_pvt_thread_key_setdata( ldap_pvt_thread_key_t key, void *data )
+{
+       return thr_setspecific( key, data );
+}
+
+int
+ldap_pvt_thread_key_getdata( ldap_pvt_thread_key_t key, void **data )
+{
+       return thr_getspecific( key, data );
+}
+
 #endif /* HAVE_THR */
index 6e3d81b3b2d18b99d0f5ae903277870e0827f747..8309089cc746e6254f8be9a4c511fe78d789b016 100644 (file)
@@ -38,11 +38,11 @@ typedef enum ldap_int_thread_pool_state_e {
 } ldap_int_thread_pool_state_t;
 
 /* Thread-specific key with data and optional free function */
-typedef struct ldap_int_thread_key_s {
+typedef struct ldap_int_tpool_key_s {
        void *ltk_key;
        void *ltk_data;
        ldap_pvt_thread_pool_keyfree_t *ltk_free;
-} ldap_int_thread_key_t;
+} ldap_int_tpool_key_t;
 
 /* Max number of thread-specific keys we store per thread.
  * We don't expect to use many...
@@ -55,7 +55,7 @@ typedef struct ldap_int_thread_key_s {
 /* Context: thread ID and thread-specific key/data pairs */
 typedef struct ldap_int_thread_userctx_s {
        ldap_pvt_thread_t ltu_id;
-       ldap_int_thread_key_t ltu_key[MAXKEYS];
+       ldap_int_tpool_key_t ltu_key[MAXKEYS];
 } ldap_int_thread_userctx_t;