From 18af550ef15605d13e7d5ac59fa88713262db82d Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Tue, 5 Jul 2011 09:17:53 +0100 Subject: [PATCH] rx: Provide Get/SetThreadNum functions Provide functions to let an application manipulate the rx thread specific key, rather than letting them root around in the internals of RX themselves. Change-Id: Ic42430de7e0c0a60217a509d9b7ef9d3523463ce Reviewed-on: http://gerrit.openafs.org/5083 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/budb/server.c | 10 +--------- src/libafsrpc/afsrpc.def | 2 ++ src/rx/rx_prototypes.h | 2 ++ src/rx/rx_pthread.c | 27 +++++++++++++++++++++++++-- src/viced/viced.c | 19 +++++-------------- src/vol/fssync-server.c | 3 +-- src/volser/volmain.c | 10 +--------- 7 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/budb/server.c b/src/budb/server.c index 4c202ee95..d7f296092 100644 --- a/src/budb/server.c +++ b/src/budb/server.c @@ -67,14 +67,6 @@ int lwps = 3; #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */ afs_uint32 SHostAddrs[ADDRSPERSITE]; -#if defined(AFS_PTHREAD_ENV) -static int -threadNum(void) -{ - return (intptr_t)pthread_getspecific(rx_thread_id_key); -} -#endif - /* check whether caller is authorized to manage RX statistics */ int BU_rxstat_userok(struct rx_call *call) @@ -432,7 +424,7 @@ main(int argc, char **argv) srandom(1); #ifdef AFS_PTHREAD_ENV - SetLogThreadNumProgram( threadNum ); + SetLogThreadNumProgram( rx_GetThreadNum ); #endif /* process the user supplied args */ diff --git a/src/libafsrpc/afsrpc.def b/src/libafsrpc/afsrpc.def index bc33abc1f..1afbbbabe 100755 --- a/src/libafsrpc/afsrpc.def +++ b/src/libafsrpc/afsrpc.def @@ -294,6 +294,8 @@ EXPORTS rx_identity_free @303 rx_SetBusyChannelError @304 + rx_GetThreadNum @305 + rx_SetThreadNum @306 ; for performance testing rx_TSFPQGlobSize @2001 DATA diff --git a/src/rx/rx_prototypes.h b/src/rx/rx_prototypes.h index 421df1d7b..b308c3e65 100644 --- a/src/rx/rx_prototypes.h +++ b/src/rx/rx_prototypes.h @@ -257,6 +257,8 @@ extern int rx_RxStatUserOk(struct rx_call *call); extern afs_int32 rx_SetSecurityConfiguration(struct rx_service *service, rx_securityConfigVariables type, void *value); +extern int rx_GetThreadNum(void); +extern int rx_SetThreadNum(void); void rxi_DebugInit(void); void rxi_DebugPrint(char *format, ...) diff --git a/src/rx/rx_pthread.c b/src/rx/rx_pthread.c index 87a2c05d3..820797658 100644 --- a/src/rx/rx_pthread.c +++ b/src/rx/rx_pthread.c @@ -28,6 +28,8 @@ #include "rx_clock.h" #include "rx_atomic.h" +static void rxi_SetThreadNum(int threadID); + /* Set rx_pthread_event_rescheduled if event_handler should just try * again instead of sleeping. * @@ -250,7 +252,7 @@ rx_ListenerProc(void *argp) /* osi_Assert(threadID != -1); */ /* osi_Assert(newcall != NULL); */ sock = OSI_NULLSOCKET; - osi_Assert(pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)threadID) == 0); + rxi_SetThreadNum(threadID); rxi_ServerProc(threadID, newcall, &sock); /* osi_Assert(sock != OSI_NULLSOCKET); */ } @@ -294,7 +296,7 @@ rx_ServerProc(void * dummy) while (1) { sock = OSI_NULLSOCKET; - osi_Assert(pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)threadID) == 0); + rxi_SetThreadNum(threadID); rxi_ServerProc(threadID, newcall, &sock); /* osi_Assert(sock != OSI_NULLSOCKET); */ newcall = NULL; @@ -436,3 +438,24 @@ struct rx_ts_info_t * rx_ts_info_init(void) { #endif /* RX_ENABLE_TSFPQ */ return rx_ts_info; } + +int +rx_GetThreadNum(void) { + return (intptr_t)pthread_getspecific(rx_thread_id_key); +} + +static void +rxi_SetThreadNum(int threadID) { + osi_Assert(pthread_setspecific(rx_thread_id_key, + (void *)(intptr_t)threadID) == 0); +} + +int +rx_SetThreadNum(void) { + int threadId; + + threadId = rx_NewThreadId(); + rxi_SetThreadNum(threadId); + return threadId; +} + diff --git a/src/viced/viced.c b/src/viced/viced.c index cb1d42641..eef02ca62 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -355,14 +355,6 @@ ResetCheckDescriptors(void) #endif } -#if defined(AFS_PTHREAD_ENV) -int -threadNum(void) -{ - return (intptr_t)pthread_getspecific(rx_thread_id_key); -} -#endif - #ifndef AFS_NT40_ENV int viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5) @@ -413,13 +405,12 @@ static void setThreadId(char *s) { #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV) + int threadId; + /* set our 'thread-id' so that the host hold table works */ - pthread_setspecific(rx_thread_id_key, - (void *)(intptr_t)rx_NewThreadId()); + threadId = rx_SetThreadNum(); afs_pthread_setname_self(s); - ViceLog(0, - ("Set thread id %p for '%s'\n", - pthread_getspecific(rx_thread_id_key), s)); + ViceLog(0, ("Set thread id 0x%x for '%s'\n", threadId, s)); #endif } @@ -2056,7 +2047,7 @@ main(int argc, char *argv[]) } #ifdef AFS_PTHREAD_ENV - SetLogThreadNumProgram( threadNum ); + SetLogThreadNumProgram( rx_GetThreadNum ); #endif /* initialize libacl routines */ diff --git a/src/vol/fssync-server.c b/src/vol/fssync-server.c index 3e356cb2d..25f60c3a2 100644 --- a/src/vol/fssync-server.c +++ b/src/vol/fssync-server.c @@ -255,8 +255,7 @@ FSYNC_sync(void * args) #ifdef AFS_PTHREAD_ENV /* set our 'thread-id' so that the host hold table works */ - tid = rx_NewThreadId(); - pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)tid); + tid = rx_SetThreadNum(); Log("Set thread id %d for FSYNC_sync\n", tid); #endif /* AFS_PTHREAD_ENV */ diff --git a/src/volser/volmain.c b/src/volser/volmain.c index 49ab4610c..daf5920dd 100644 --- a/src/volser/volmain.c +++ b/src/volser/volmain.c @@ -81,14 +81,6 @@ afs_uint32 SHostAddrs[ADDRSPERSITE]; exit(code); \ } -#if defined(AFS_PTHREAD_ENV) -int -threadNum(void) -{ - return (intptr_t)pthread_getspecific(rx_thread_id_key); -} -#endif - static void MyBeforeProc(struct rx_call *acall) { @@ -406,7 +398,7 @@ main(int argc, char **argv) InitErrTabs(); #ifdef AFS_PTHREAD_ENV - SetLogThreadNumProgram( threadNum ); + SetLogThreadNumProgram( rx_GetThreadNum ); #endif #ifdef AFS_NT40_ENV -- 2.39.5