rx: Make statistics interface use Atomics
[openafs.git] / src / rx / rx_lwp.c
index f4c80a9..c87ce23 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
@@ -21,8 +21,6 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
 
 # include <sys/types.h>                /* fd_set on older platforms */
 # include <errno.h>
@@ -44,9 +42,11 @@ RCSID
 # include <sys/ioctl.h>
 # include <sys/time.h>
 #endif
-# include "rx_internal.h"
+# include <assert.h>
 # include "rx.h"
+# include "rx_atomic.h"
 # include "rx_globals.h"
+# include "rx_stats.h"
 # include <lwp.h>
 
 #define MAXTHREADNAMELENGTH 64
@@ -163,7 +163,7 @@ rxi_ListenerProc(fd_set * rfds, int *tnop, struct rx_call **newcallp)
 {
     afs_uint32 host;
     u_short port;
-    register struct rx_packet *p = (struct rx_packet *)0;
+    struct rx_packet *p = (struct rx_packet *)0;
     osi_socket socket;
     struct clock cv;
     afs_int32 nextPollTime;    /* time to next poll FD before sleeping */
@@ -182,13 +182,16 @@ rxi_ListenerProc(fd_set * rfds, int *tnop, struct rx_call **newcallp)
     code = LWP_CurrentProcess(&pid);
     if (code) {
        fprintf(stderr, "rxi_Listener: Can't get my pid.\n");
-       exit(1);
+       assert(0);
     }
     rx_listenerPid = pid;
     if (swapNameProgram)
        (*swapNameProgram) (pid, "listener", &name[0]);
 
     for (;;) {
+        /* See if a check for additional packets was issued */
+        rx_CheckPackets();
+
        /* Grab a new packet only if necessary (otherwise re-use the old one) */
        if (p) {
            rxi_RestoreDataBufs(p);
@@ -212,7 +215,8 @@ rxi_ListenerProc(fd_set * rfds, int *tnop, struct rx_call **newcallp)
            tv.tv_usec = cv.usec;
            tvp = &tv;
        }
-       rx_AtomicIncrement(rx_stats.selects, rx_stats_mutex);
+       if (rx_stats_active)
+           rx_atomic_inc(&rx_stats.selects);
 
        *rfds = rx_selectMask;
 
@@ -435,7 +439,8 @@ rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags)
     fd_set *sfds = (fd_set *) 0;
     while (sendmsg(socket, msg_p, flags) == -1) {
        int err;
-       rx_AtomicIncrement(rx_stats.sendSelects, rx_stats_mutex);
+       if (rx_stats_active)
+           rx_atomic_inc(&rx_stats.sendSelects);
 
        if (!sfds) {
            if (!(sfds = IOMGR_AllocFDSet())) {
@@ -463,6 +468,13 @@ rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags)
        {
            (osi_Msg "rx failed to send packet: ");
            perror("rx_sendmsg");
+#ifndef AFS_NT40_ENV
+            if (errno > 0)
+              return -errno;
+#else
+            if (WSAGetLastError() > 0)
+              return -WSAGetLastError();
+#endif
            return -1;
        }
        while ((err = select(socket + 1, 0, sfds, 0, 0)) != 1) {