rx: Provide Get/SetThreadNum functions
authorSimon Wilkinson <sxw@your-file-system.com>
Tue, 5 Jul 2011 08:17:53 +0000 (09:17 +0100)
committerDerrick Brashear <shadow@dementia.org>
Sat, 23 Jul 2011 21:21:36 +0000 (14:21 -0700)
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 <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/budb/server.c
src/libafsrpc/afsrpc.def
src/rx/rx_prototypes.h
src/rx/rx_pthread.c
src/viced/viced.c
src/vol/fssync-server.c
src/volser/volmain.c

index 4c202ee..d7f2960 100644 (file)
@@ -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 */
index bc33abc..1afbbba 100755 (executable)
@@ -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
index 421df1d..b308c3e 100644 (file)
@@ -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, ...)
index 87a2c05..8207976 100644 (file)
@@ -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;
+}
+
index cb1d426..eef02ca 100644 (file)
@@ -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 */
index 3e356cb..25f60c3 100644 (file)
@@ -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 */
 
index 49ab461..daf5920 100644 (file)
@@ -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