mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-18 11:05:48 +08:00
Added ldap_pvt_thread_self() and ldap_pvt_thread_pool_context() API.
This commit is contained in:
parent
146c0085d3
commit
9490776d7b
@ -97,6 +97,9 @@ ldap_pvt_thread_mutex_trylock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
|
||||
LDAP_F( int )
|
||||
ldap_pvt_thread_mutex_unlock LDAP_P(( ldap_pvt_thread_mutex_t *mutex ));
|
||||
|
||||
LDAP_F( ldap_pvt_thread_t )
|
||||
ldap_pvt_thread_self LDAP_P(( void ));
|
||||
|
||||
#ifndef LDAP_THREAD_HAVE_RDWR
|
||||
typedef struct ldap_int_thread_rdwr_s * ldap_pvt_thread_rdwr_t;
|
||||
#endif
|
||||
@ -184,6 +187,10 @@ ldap_pvt_thread_pool_setkey LDAP_P((
|
||||
void *data,
|
||||
ldap_pvt_thread_pool_keyfree_t *kfree ));
|
||||
|
||||
LDAP_F( void *)
|
||||
ldap_pvt_thread_pool_context LDAP_P((
|
||||
ldap_pvt_thread_pool_t *pool ));
|
||||
|
||||
LDAP_END_DECL
|
||||
|
||||
#endif /* _LDAP_THREAD_H */
|
||||
|
@ -146,4 +146,10 @@ ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mutex )
|
||||
return mutex_try_lock( mutex );
|
||||
}
|
||||
|
||||
ldap_pvt_thread_t
|
||||
ldap_pvt_thread_self( void )
|
||||
{
|
||||
return cthread_self();
|
||||
}
|
||||
|
||||
#endif /* HAVE_MACH_CTHREADS */
|
||||
|
@ -360,4 +360,14 @@ ldap_pvt_thread_cond_broadcast( ldap_pvt_thread_cond_t *cv )
|
||||
return( cv->lcv_created ? cv_broadcast( cv->lcv_cv ) : 0 );
|
||||
}
|
||||
|
||||
ldap_pvt_thread_t
|
||||
ldap_pvt_thread_self( void )
|
||||
{
|
||||
thread_t mylwp;
|
||||
|
||||
lwp_self( &mylwp );
|
||||
|
||||
return mylwp;
|
||||
}
|
||||
|
||||
#endif /* HAVE_LWP */
|
||||
|
@ -152,4 +152,10 @@ ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mp )
|
||||
? -1 : 0;
|
||||
}
|
||||
|
||||
ldap_pvt_thread_t
|
||||
ldap_pvt_thread_self( void )
|
||||
{
|
||||
return GetCurrentThread();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -311,6 +311,11 @@ ldap_pvt_thread_mutex_unlock( ldap_pvt_thread_mutex_t *mutex )
|
||||
#endif
|
||||
}
|
||||
|
||||
ldap_pvt_thread_t ldap_pvt_thread_self( void )
|
||||
{
|
||||
return pthread_self();
|
||||
}
|
||||
|
||||
#ifdef LDAP_THREAD_HAVE_RDWR
|
||||
#ifdef HAVE_PTHREAD_RWLOCK_DESTROY
|
||||
int
|
||||
|
@ -146,6 +146,12 @@ ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mutex )
|
||||
return( pth_mutex_acquire( mutex, 1, NULL ) ? 0 : errno );
|
||||
}
|
||||
|
||||
ldap_pvt_thread_t
|
||||
ldap_pvt_thread_self( void )
|
||||
{
|
||||
return pth_self();
|
||||
}
|
||||
|
||||
#ifdef LDAP_THREAD_HAVE_RDWR
|
||||
int
|
||||
ldap_pvt_thread_rdwr_init( ldap_pvt_thread_rdwr_t *rw )
|
||||
|
@ -191,4 +191,11 @@ int ldap_pvt_thread_pool_setkey (
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
ldap_pvt_thread_t
|
||||
ldap_pvt_thread_self( void )
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
#endif /* NO_THREADS */
|
||||
|
@ -149,4 +149,10 @@ ldap_pvt_thread_mutex_trylock( ldap_pvt_thread_mutex_t *mp )
|
||||
return( mutex_trylock( mp ) );
|
||||
}
|
||||
|
||||
ldap_pvt_thread_t
|
||||
ldap_pvt_thread_self( void )
|
||||
{
|
||||
return thr_self();
|
||||
}
|
||||
|
||||
#endif /* HAVE_THR */
|
||||
|
@ -46,9 +46,11 @@ typedef struct ldap_int_thread_ctx_s {
|
||||
union {
|
||||
LDAP_STAILQ_ENTRY(ldap_int_thread_ctx_s) q;
|
||||
LDAP_SLIST_ENTRY(ldap_int_thread_ctx_s) l;
|
||||
LDAP_SLIST_ENTRY(ldap_int_thread_ctx_s) al;
|
||||
} ltc_next;
|
||||
ldap_pvt_thread_start_t *ltc_start_routine;
|
||||
void *ltc_arg;
|
||||
ldap_pvt_thread_t ltc_thread_id;
|
||||
ldap_int_thread_key_t ltc_key[MAXKEYS];
|
||||
} ldap_int_thread_ctx_t;
|
||||
|
||||
@ -58,6 +60,7 @@ struct ldap_int_thread_pool_s {
|
||||
ldap_pvt_thread_cond_t ltp_cond;
|
||||
LDAP_STAILQ_HEAD(tcq, ldap_int_thread_ctx_s) ltp_pending_list;
|
||||
LDAP_SLIST_HEAD(tcl, ldap_int_thread_ctx_s) ltp_free_list;
|
||||
LDAP_SLIST_HEAD(tclq, ldap_int_thread_ctx_s) ltp_active_list;
|
||||
long ltp_state;
|
||||
long ltp_max_count;
|
||||
long ltp_max_pending;
|
||||
@ -120,6 +123,7 @@ ldap_pvt_thread_pool_init (
|
||||
pool->ltp_max_pending = max_pending;
|
||||
LDAP_STAILQ_INIT(&pool->ltp_pending_list);
|
||||
LDAP_SLIST_INIT(&pool->ltp_free_list);
|
||||
LDAP_SLIST_INIT(&pool->ltp_active_list);
|
||||
ldap_pvt_thread_mutex_lock(&ldap_pvt_thread_pool_mutex);
|
||||
LDAP_STAILQ_INSERT_TAIL(&ldap_int_thread_pool_list, pool, ltp_next);
|
||||
ldap_pvt_thread_mutex_unlock(&ldap_pvt_thread_pool_mutex);
|
||||
@ -373,6 +377,11 @@ ldap_pvt_thread_pool_destroy ( ldap_pvt_thread_pool_t *tpool, int run_pending )
|
||||
LDAP_FREE(ctx);
|
||||
}
|
||||
|
||||
while ((ctx = LDAP_SLIST_FIRST(&pool->ltp_active_list)) != NULL)
|
||||
{
|
||||
LDAP_SLIST_REMOVE_HEAD(&pool->ltp_active_list, ltc_next.al);
|
||||
}
|
||||
|
||||
ldap_pvt_thread_cond_destroy(&pool->ltp_cond);
|
||||
ldap_pvt_thread_mutex_destroy(&pool->ltp_mutex);
|
||||
LDAP_FREE(pool);
|
||||
@ -425,9 +434,11 @@ ldap_int_thread_pool_wrapper (
|
||||
}
|
||||
|
||||
pool->ltp_pending_count--;
|
||||
LDAP_SLIST_INSERT_HEAD(&pool->ltp_active_list, ctx, ltc_next.al);
|
||||
pool->ltp_active_count++;
|
||||
ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex);
|
||||
|
||||
ctx->ltc_thread_id = ldap_pvt_thread_self();
|
||||
ctx->ltc_start_routine(ctx, ctx->ltc_arg);
|
||||
|
||||
ldap_pvt_thread_mutex_lock(&pool->ltp_mutex);
|
||||
@ -442,6 +453,10 @@ ldap_int_thread_pool_wrapper (
|
||||
|
||||
ldap_pvt_thread_mutex_lock(&pool->ltp_mutex);
|
||||
pool->ltp_active_count--;
|
||||
ctx = LDAP_SLIST_FIRST(&pool->ltp_active_list);
|
||||
if (ctx) {
|
||||
LDAP_SLIST_REMOVE_HEAD(&pool->ltp_active_list, ltc_next.al);
|
||||
}
|
||||
}
|
||||
|
||||
pool->ltp_open_count--;
|
||||
@ -494,4 +509,36 @@ int ldap_pvt_thread_pool_setkey(
|
||||
}
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is necessary if the caller does not have access to the
|
||||
* thread context handle (for example, a slapd plugin calling
|
||||
* slapi_search_internal()). No doubt it is more efficient to
|
||||
* for the application to keep track of the thread context
|
||||
* handles itself.
|
||||
*/
|
||||
void *ldap_pvt_thread_pool_context( ldap_pvt_thread_pool_t *tpool )
|
||||
{
|
||||
ldap_pvt_thread_pool_t pool;
|
||||
ldap_pvt_thread_t tid;
|
||||
ldap_int_thread_ctx_t *ptr;
|
||||
|
||||
pool = *tpool;
|
||||
if (pool == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tid = ldap_pvt_thread_self();
|
||||
|
||||
ldap_pvt_thread_mutex_lock(&pool->ltp_mutex);
|
||||
LDAP_SLIST_FOREACH(ptr, &pool->ltp_active_list, ltc_next.al)
|
||||
if (ptr != NULL && ptr->ltc_thread_id == tid) break;
|
||||
if (ptr != NULL && ptr->ltc_thread_id != tid) {
|
||||
ptr = NULL;
|
||||
}
|
||||
ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#endif /* LDAP_HAVE_THREAD_POOL */
|
||||
|
Loading…
Reference in New Issue
Block a user