]> granicus.if.org Git - libtirpc/commitdiff
Add a pthread key initializer constant
authorChuck Lever <chuck.lever@oracle.com>
Thu, 23 Jan 2014 16:17:09 +0000 (11:17 -0500)
committerSteve Dickson <steved@redhat.com>
Thu, 23 Jan 2014 16:27:44 +0000 (11:27 -0500)
Clean up: replace the naked "-1" with a symbolic constant that helps
document what is going on.  The name matches the name of the other
pthread initializer constants.

Also, since pthread_key_t is an unsigned integer, use a type cast to
eliminate the implicit cast that occurs every time foo_key is
compared to -1.  This eliminates a number of compiler warnings.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
src/clnt_simple.c
src/getnetconfig.c
src/mt_misc.c
src/rpc_generic.c
src/rpc_soc.c
tirpc/reentrant.h

index e66da6a3ab293070fd7f1595b0dfe649b9249969..7ee9542b6882e521efe44c5c7801e1e1fa1e2e79 100644 (file)
@@ -104,9 +104,9 @@ rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype)
        extern thread_key_t rpc_call_key;
        extern mutex_t tsd_lock;
 
-       if (rpc_call_key == -1) {
+       if (rpc_call_key == KEY_INITIALIZER) {
                mutex_lock(&tsd_lock);
-               if (rpc_call_key == -1)
+               if (rpc_call_key == KEY_INITIALIZER)
                        thr_keycreate(&rpc_call_key, rpc_call_destroy);
                mutex_unlock(&tsd_lock);
        }
index 78de0f6bd523ded16bdf30729de9b192ebb2cb43..635c03a7ff9c5296f58f7b0108b9995a16b52709 100644 (file)
@@ -137,10 +137,10 @@ __nc_error()
         * (including non-threaded programs), or if an allocation
         * fails.
         */
-       if (nc_key == -1) {
+       if (nc_key == KEY_INITIALIZER) {
                error = 0;
                mutex_lock(&nc_lock);
-               if (nc_key == -1)
+               if (nc_key == KEY_INITIALIZER)
                        error = thr_keycreate(&nc_key, free);
                mutex_unlock(&nc_lock);
                if (error)
index d459dec7b9d9de31e288fb314c48a78cca4a345f..093086e8815294fd229cf92ad3d788aea3fdcd6f 100644 (file)
@@ -78,12 +78,12 @@ pthread_mutex_t     svcraw_lock = PTHREAD_MUTEX_INITIALIZER;
 pthread_mutex_t        tsd_lock = PTHREAD_MUTEX_INITIALIZER;
 
 /* Library global tsd keys */
-thread_key_t clnt_broadcast_key;
-thread_key_t rpc_call_key = -1;
-thread_key_t tcp_key = -1;
-thread_key_t udp_key = -1;
-thread_key_t nc_key = -1;
-thread_key_t rce_key = -1;
+thread_key_t clnt_broadcast_key = KEY_INITIALIZER;
+thread_key_t rpc_call_key = KEY_INITIALIZER;
+thread_key_t tcp_key = KEY_INITIALIZER;
+thread_key_t udp_key = KEY_INITIALIZER;
+thread_key_t nc_key = KEY_INITIALIZER;
+thread_key_t rce_key = KEY_INITIALIZER;
 
 /* xprtlist (svc_generic.c) */
 pthread_mutex_t        xprtlist_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -110,7 +110,7 @@ __rpc_createerr()
        struct rpc_createerr *rce_addr;
 
        mutex_lock(&tsd_lock);
-       if (rce_key == -1)
+       if (rce_key == KEY_INITIALIZER)
                thr_keycreate(&rce_key, free);
        mutex_unlock(&tsd_lock);
 
@@ -131,17 +131,17 @@ __rpc_createerr()
 
 void tsd_key_delete(void)
 {
-       if (clnt_broadcast_key != -1)
+       if (clnt_broadcast_key != KEY_INITIALIZER)
                pthread_key_delete(clnt_broadcast_key);
-       if (rpc_call_key != -1)
+       if (rpc_call_key != KEY_INITIALIZER)
                pthread_key_delete(rpc_call_key);
-       if (tcp_key != -1)
+       if (tcp_key != KEY_INITIALIZER)
                pthread_key_delete(tcp_key);
-       if (udp_key != -1)
+       if (udp_key != KEY_INITIALIZER)
                pthread_key_delete(udp_key);
-       if (nc_key != -1)
+       if (nc_key != KEY_INITIALIZER)
                pthread_key_delete(nc_key);
-       if (rce_key != -1)
+       if (rce_key != KEY_INITIALIZER)
                pthread_key_delete(rce_key);
        return;
 }
index 2eb91ad0b75c882f62e8f8e455ae6f1f927a4310..a43906c0dc5f2be964364970f1fc4315e9d9668b 100644 (file)
@@ -228,16 +228,16 @@ __rpc_getconfip(nettype)
        extern thread_key_t tcp_key, udp_key;
        extern mutex_t tsd_lock;
 
-       if (tcp_key == -1) {
+       if (tcp_key == KEY_INITIALIZER) {
                mutex_lock(&tsd_lock);
-               if (tcp_key == -1)
+               if (tcp_key == KEY_INITIALIZER)
                        thr_keycreate(&tcp_key, free);
                mutex_unlock(&tsd_lock);
        }
        netid_tcp = (char *)thr_getspecific(tcp_key);
-       if (udp_key == -1) {
+       if (udp_key == KEY_INITIALIZER) {
                mutex_lock(&tsd_lock);
-               if (udp_key == -1)
+               if (udp_key == KEY_INITIALIZER)
                        thr_keycreate(&udp_key, free);
                mutex_unlock(&tsd_lock);
        }
index 4213ca07a3705d1193157d40c9348d2fd1e92fb6..338edbbfebcd8b986c4343c691c24d33218fd870 100644 (file)
@@ -508,9 +508,9 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult)
 {
        extern mutex_t tsd_lock;
 
-       if (clnt_broadcast_key == -1) {
+       if (clnt_broadcast_key == KEY_INITIALIZER) {
                mutex_lock(&tsd_lock);
-               if (clnt_broadcast_key == -1)
+               if (clnt_broadcast_key == KEY_INITIALIZER)
                        thr_keycreate(&clnt_broadcast_key, free);
                mutex_unlock(&tsd_lock);
        }
index 9489b15d91de01b6a437b5cab07895033c0949c2..5f5c96e46a87b057c0de84e4baf314979d45e748 100644 (file)
@@ -46,6 +46,8 @@
 #define once_t                 pthread_once_t
 
 #define thread_key_t           pthread_key_t
+
+#define KEY_INITIALIZER                ((thread_key_t)-1)
 #define MUTEX_INITIALIZER      PTHREAD_MUTEX_INITIALIZER
 #define RWLOCK_INITIALIZER     PTHREAD_RWLOCK_INITIALIZER
 #define ONCE_INITIALIZER       PTHREAD_ONCE_INIT