rx-rw-locking-20081024
authorJeffrey Altman <jaltman@your-file-system.com>
Fri, 24 Oct 2008 21:38:56 +0000 (21:38 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 24 Oct 2008 21:38:56 +0000 (21:38 +0000)
LICENSE BSD

rename RWLOCK_INIT to AFS_RWLOCK_INIT in order to maintain naming
consistency and to distinguish them from the new RWLOCK_INIT macros
being used in rx.

====================
This delta was composed from multiple commits as part of the CVS->Git migration.
The checkin message with each commit was inconsistent.
The following are the additional commit messages.
====================
LICENSE BSD

add rx/rx_internal.h as a dependency

====================
LICENSE BSD

define RWLOCK_xxx operations

replace MUTEX_xxx operations with RWLOCK_xxx when it is appropriate
to do so.  This improves concurrency on multi-processor systems.

make additional use of atomic operations

47 files changed:
src/afs/LINUX/osi_module.c
src/afs/LINUX/osi_nfssrv.c
src/afs/afs_axscache.c
src/afs/afs_buffer.c
src/afs/afs_cell.c
src/afs/afs_dcache.c
src/afs/afs_dynroot.c
src/afs/afs_init.c
src/afs/afs_pag_call.c
src/afs/afs_vcache.c
src/afs/afs_volume.c
src/afs/lock.h
src/libafsrpc/Makefile.in
src/rx/AIX/rx_kmutex.h
src/rx/FBSD/rx_kmutex.h
src/rx/HPUX/rx_kmutex.h
src/rx/IRIX/rx_kmutex.h
src/rx/LINUX/rx_kmutex.h
src/rx/Makefile.in
src/rx/NBSD/rx_kmutex.h
src/rx/OBSD/rx_kmutex.h
src/rx/SOLARIS/rx_kmutex.h
src/rx/UKERNEL/rx_kmutex.h
src/rx/rx.c
src/rx/rx.h
src/rx/rx_clock.c
src/rx/rx_conncache.c
src/rx/rx_event.c
src/rx/rx_getaddr.c
src/rx/rx_globals.h
src/rx/rx_internal.h
src/rx/rx_lwp.c
src/rx/rx_lwp.h
src/rx/rx_misc.c
src/rx/rx_multi.c
src/rx/rx_null.c
src/rx/rx_packet.c
src/rx/rx_pthread.c
src/rx/rx_pthread.h
src/rx/rx_rdwr.c
src/rx/rx_trace.c
src/rx/rx_user.c
src/rx/rx_xmit_nt.c
src/rx/xdr.c
src/rx/xdr_array.c
src/rx/xdr_refernce.c
src/rx/xdr_rx.c

index c0ea4bb..22ee95c 100644 (file)
@@ -66,7 +66,7 @@ init_module(void)
 #endif
 {
     int err;
-    RWLOCK_INIT(&afs_xosi, "afs_xosi");
+    AFS_RWLOCK_INIT(&afs_xosi, "afs_xosi");
 
 #if !defined(AFS_LINUX24_ENV)
     /* obtain PAGE_OFFSET value */
index 5c423ce..b0cbc0b 100644 (file)
@@ -204,7 +204,7 @@ void osi_linux_nfssrv_init(void)
     int i;
 
     nfssrv_list = 0;
-    RWLOCK_INIT(&afs_xnfssrv, "afs_xnfssrv");
+    AFS_RWLOCK_INIT(&afs_xnfssrv, "afs_xnfssrv");
 
     if (authtab && !IS_ERR(authtab))
           afs_authtab = authtab;
index ab585f0..e8322bb 100644 (file)
@@ -173,7 +173,7 @@ shutdown_xscache(void)
 {
     struct xfreelist *xp, *nxp;
 
-    RWLOCK_INIT(&afs_xaxs, "afs_xaxs");
+    AFS_RWLOCK_INIT(&afs_xaxs, "afs_xaxs");
     xp = xfreemallocs;
     while (xp) {
        nxp = xp->next;
index 10c143b..3f3e5de 100644 (file)
@@ -144,7 +144,7 @@ DInit(int abuffers)
 #endif
        tb->hashIndex = 0;
        tb->dirty = 0;
-       RWLOCK_INIT(&tb->lock, "buffer lock");
+       AFS_RWLOCK_INIT(&tb->lock, "buffer lock");
     }
     return;
 }
index ad71c3e..38e83c2 100644 (file)
@@ -924,7 +924,7 @@ afs_NewCell(char *acellName, afs_int32 * acellHosts, int aflags,
        tc->fsport = AFS_FSPORT;
        tc->vlport = AFS_VLPORT;
        AFS_MD5_String(tc->cellHandle, tc->cellName, strlen(tc->cellName));
-       RWLOCK_INIT(&tc->lock, "cell lock");
+       AFS_RWLOCK_INIT(&tc->lock, "cell lock");
        newc = 1;
        aflags |= CNoSUID;
     }
@@ -1040,10 +1040,10 @@ afs_NewCell(char *acellName, afs_int32 * acellHosts, int aflags,
 void
 afs_CellInit()
 {
-    RWLOCK_INIT(&afs_xcell, "afs_xcell");
+    AFS_RWLOCK_INIT(&afs_xcell, "afs_xcell");
 #ifdef AFS_AFSDB_ENV
-    RWLOCK_INIT(&afsdb_client_lock, "afsdb_client_lock");
-    RWLOCK_INIT(&afsdb_req_lock, "afsdb_req_lock");
+    AFS_RWLOCK_INIT(&afsdb_client_lock, "afsdb_client_lock");
+    AFS_RWLOCK_INIT(&afsdb_req_lock, "afsdb_req_lock");
 #endif
     QInit(&CellLRU);
 
@@ -1060,7 +1060,7 @@ shutdown_cell()
     struct afs_q *cq, *tq;
     struct cell *tc;
 
-    RWLOCK_INIT(&afs_xcell, "afs_xcell");
+    AFS_RWLOCK_INIT(&afs_xcell, "afs_xcell");
 
     for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
        tc = QTOC(cq);
index 62f03a6..6f411e3 100644 (file)
@@ -3031,9 +3031,9 @@ afs_MemGetDSlot(register afs_int32 aslot, register struct dcache *tmpdc)
        osi_Assert(0 == NBObtainWriteLock(&tdc->tlock, 676));
     }
 
-    RWLOCK_INIT(&tdc->lock, "dcache lock");
-    RWLOCK_INIT(&tdc->tlock, "dcache tlock");
-    RWLOCK_INIT(&tdc->mflock, "dcache flock");
+    AFS_RWLOCK_INIT(&tdc->lock, "dcache lock");
+    AFS_RWLOCK_INIT(&tdc->tlock, "dcache tlock");
+    AFS_RWLOCK_INIT(&tdc->mflock, "dcache flock");
     ObtainReadLock(&tdc->tlock);
 
     if (tmpdc == NULL)
@@ -3162,9 +3162,9 @@ afs_UFSGetDSlot(register afs_int32 aslot, register struct dcache *tmpdc)
        osi_Assert(0 == NBObtainWriteLock(&tdc->tlock, 676));
     }
 
-    RWLOCK_INIT(&tdc->lock, "dcache lock");
-    RWLOCK_INIT(&tdc->tlock, "dcache tlock");
-    RWLOCK_INIT(&tdc->mflock, "dcache flock");
+    AFS_RWLOCK_INIT(&tdc->lock, "dcache lock");
+    AFS_RWLOCK_INIT(&tdc->tlock, "dcache tlock");
+    AFS_RWLOCK_INIT(&tdc->mflock, "dcache flock");
     ObtainReadLock(&tdc->tlock);
 
     /*
@@ -3523,14 +3523,14 @@ afs_dcacheInit(int afiles, int ablocks, int aDentries, int achunk, int aflags)
     afs_freeDSList = &tdp[0];
     for (i = 0; i < aDentries - 1; i++) {
        tdp[i].lruq.next = (struct afs_q *)(&tdp[i + 1]);
-        RWLOCK_INIT(&tdp[i].lock, "dcache lock");
-        RWLOCK_INIT(&tdp[i].tlock, "dcache tlock");
-        RWLOCK_INIT(&tdp[i].mflock, "dcache flock");
+        AFS_RWLOCK_INIT(&tdp[i].lock, "dcache lock");
+        AFS_RWLOCK_INIT(&tdp[i].tlock, "dcache tlock");
+        AFS_RWLOCK_INIT(&tdp[i].mflock, "dcache flock");
     }
     tdp[aDentries - 1].lruq.next = (struct afs_q *)0;
-    RWLOCK_INIT(&tdp[aDentries - 1].lock, "dcache lock");
-    RWLOCK_INIT(&tdp[aDentries - 1].tlock, "dcache tlock");
-    RWLOCK_INIT(&tdp[aDentries - 1].mflock, "dcache flock");
+    AFS_RWLOCK_INIT(&tdp[aDentries - 1].lock, "dcache lock");
+    AFS_RWLOCK_INIT(&tdp[aDentries - 1].tlock, "dcache tlock");
+    AFS_RWLOCK_INIT(&tdp[aDentries - 1].mflock, "dcache flock");
 
     afs_stats_cmperf.cacheBlocksOrig = afs_stats_cmperf.cacheBlocksTotal =
        afs_cacheBlocks = ablocks;
index a0e9618..76e5ce8 100644 (file)
@@ -760,8 +760,8 @@ afs_InitDynroot(void)
 {
     if (afs_dynrootInit)
        return 0;
-    RWLOCK_INIT(&afs_dynrootDirLock, "afs_dynrootDirLock");
-    RWLOCK_INIT(&afs_dynSymlinkLock, "afs_dynSymlinkLock");
+    AFS_RWLOCK_INIT(&afs_dynrootDirLock, "afs_dynrootDirLock");
+    AFS_RWLOCK_INIT(&afs_dynSymlinkLock, "afs_dynSymlinkLock");
     afs_dynrootInit = 0;
     return afs_dynrootCellInit();
 }
index c4fd031..b3a8b67 100644 (file)
@@ -113,10 +113,10 @@ afs_CacheInit(afs_int32 astatSize, afs_int32 afiles, afs_int32 ablocks,
     usedihint = 0;
 
     LOCK_INIT(&afs_ftf, "afs_ftf");
-    RWLOCK_INIT(&afs_xaxs, "afs_xaxs");
+    AFS_RWLOCK_INIT(&afs_xaxs, "afs_xaxs");
 #ifdef AFS_DISCON_ENV
-    RWLOCK_INIT(&afs_discon_lock, "afs_discon_lock");
-    RWLOCK_INIT(&afs_DDirtyVCListLock, "afs_DDirtyVCListLock");
+    AFS_RWLOCK_INIT(&afs_discon_lock, "afs_discon_lock");
+    AFS_RWLOCK_INIT(&afs_DDirtyVCListLock, "afs_DDirtyVCListLock");
 #endif
     osi_dnlc_init();
 
@@ -486,18 +486,18 @@ afs_ResourceInit(int preallocs)
     static struct rx_securityClass *secobj;
 
     AFS_STATCNT(afs_ResourceInit);
-    RWLOCK_INIT(&afs_xuser, "afs_xuser");
-    RWLOCK_INIT(&afs_xvolume, "afs_xvolume");
-    RWLOCK_INIT(&afs_xserver, "afs_xserver");
-    RWLOCK_INIT(&afs_xsrvAddr, "afs_xsrvAddr");
-    RWLOCK_INIT(&afs_icl_lock, "afs_icl_lock");
-    RWLOCK_INIT(&afs_xinterface, "afs_xinterface");
+    AFS_RWLOCK_INIT(&afs_xuser, "afs_xuser");
+    AFS_RWLOCK_INIT(&afs_xvolume, "afs_xvolume");
+    AFS_RWLOCK_INIT(&afs_xserver, "afs_xserver");
+    AFS_RWLOCK_INIT(&afs_xsrvAddr, "afs_xsrvAddr");
+    AFS_RWLOCK_INIT(&afs_icl_lock, "afs_icl_lock");
+    AFS_RWLOCK_INIT(&afs_xinterface, "afs_xinterface");
     LOCK_INIT(&afs_puttofileLock, "afs_puttofileLock");
 #ifndef AFS_FBSD_ENV
     LOCK_INIT(&osi_fsplock, "osi_fsplock");
     LOCK_INIT(&osi_flplock, "osi_flplock");
 #endif
-    RWLOCK_INIT(&afs_xconn, "afs_xconn");
+    AFS_RWLOCK_INIT(&afs_xconn, "afs_xconn");
 
     afs_CellInit();
     afs_InitCBQueue(1);                /* initialize callback queues */
@@ -814,11 +814,11 @@ shutdown_AFS(void)
        afs_waitForever = afs_waitForeverCount = 0;
        afs_FVIndex = -1;
        afs_server = (struct rx_service *)0;
-       RWLOCK_INIT(&afs_xconn, "afs_xconn");
+       AFS_RWLOCK_INIT(&afs_xconn, "afs_xconn");
        memset((char *)&afs_rootFid, 0, sizeof(struct VenusFid));
-       RWLOCK_INIT(&afs_xuser, "afs_xuser");
-       RWLOCK_INIT(&afs_xvolume, "afs_xvolume");
-       RWLOCK_INIT(&afs_xserver, "afs_xserver");
+       AFS_RWLOCK_INIT(&afs_xuser, "afs_xuser");
+       AFS_RWLOCK_INIT(&afs_xvolume, "afs_xvolume");
+       AFS_RWLOCK_INIT(&afs_xserver, "afs_xserver");
        LOCK_INIT(&afs_puttofileLock, "afs_puttofileLock");
 
        shutdown_cell();
index 530b798..89c0454 100644 (file)
@@ -103,10 +103,10 @@ void afspag_Init(afs_int32 nfs_server_addr)
     rx_Init(htons(7001));
 
     AFS_STATCNT(afs_ResourceInit);
-    RWLOCK_INIT(&afs_xuser, "afs_xuser");
-    RWLOCK_INIT(&afs_xpagcell, "afs_xpagcell");
-    RWLOCK_INIT(&afs_xpagsys, "afs_xpagsys");
-    RWLOCK_INIT(&afs_icl_lock, "afs_icl_lock");
+    AFS_RWLOCK_INIT(&afs_xuser, "afs_xuser");
+    AFS_RWLOCK_INIT(&afs_xpagcell, "afs_xpagcell");
+    AFS_RWLOCK_INIT(&afs_xpagsys, "afs_xpagsys");
+    AFS_RWLOCK_INIT(&afs_icl_lock, "afs_icl_lock");
 #ifndef AFS_FBSD_ENV
     LOCK_INIT(&osi_fsplock, "osi_fsplock");
     LOCK_INIT(&osi_flplock, "osi_flplock");
index c950605..3307e51 100644 (file)
@@ -907,9 +907,9 @@ restart:
     tvc->uncred = 0;
 #endif
 
-    RWLOCK_INIT(&tvc->lock, "vcache lock");
+    AFS_RWLOCK_INIT(&tvc->lock, "vcache lock");
 #if    defined(AFS_SUN5_ENV)
-    RWLOCK_INIT(&tvc->vlock, "vcache vlock");
+    AFS_RWLOCK_INIT(&tvc->vlock, "vcache vlock");
 #endif /* defined(AFS_SUN5_ENV) */
 
     tvc->parentVnode = 0;
@@ -3134,7 +3134,7 @@ afs_vcacheInit(int astatSize)
     freeVCList = NULL;
 #endif
 
-    RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
+    AFS_RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
     LOCK_INIT(&afs_xvcb, "afs_xvcb");
 
 #if !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
@@ -3269,7 +3269,7 @@ shutdown_vcache(void)
 #if !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
     freeVCList = Initial_freeVCList = 0;
 #endif
-    RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
+    AFS_RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
     LOCK_INIT(&afs_xvcb, "afs_xvcb");
     QInit(&VLRU);
     for(i = 0; i < VCSIZE; ++i)
index 77121fa..50cf2c4 100644 (file)
@@ -538,7 +538,7 @@ afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
        tv = afs_GetVolSlot();
        memset((char *)tv, 0, sizeof(struct volume));
        tv->cell = tcell->cellNum;
-       RWLOCK_INIT(&tv->lock, "volume lock");
+       AFS_RWLOCK_INIT(&tv->lock, "volume lock");
        tv->next = afs_volumes[i];      /* thread into list */
        afs_volumes[i] = tv;
        tv->volume = volid;
index 7214aa2..27787a0 100644 (file)
@@ -68,7 +68,7 @@ typedef struct afs_bozoLock afs_bozoLock_t;
 #define MReleaseWriteLock(lock)        ReleaseWriteLock(lock)
 #define MReleaseSharedLock(lock) ReleaseSharedLock(lock)
 
-#define        RWLOCK_INIT(lock, nm)   Lock_Init(lock)
+#define        AFS_RWLOCK_INIT(lock, nm)       Lock_Init(lock)
 #undef LOCK_INIT
 #define        LOCK_INIT(lock, nm)     Lock_Init(lock)
 
index fe86438..a0b471d 100644 (file)
@@ -185,7 +185,7 @@ rx_trace.o: ${RX}/rx_trace.c
 rx_multi.o: ${RX}/rx_multi.c
        ${CCRULE} ${RX}/rx_multi.c
 
-${RXOBJS}: ${RX}/rx.h ${RX}/rx_user.h ${RX}/rx_globals.h ${RX}/rx_clock.h ${RX}/rx_queue.h ${RX}/rx_event.h
+${RXOBJS}: ${RX}/rx.h ${RX}/rx_user.h ${RX}/rx_globals.h ${RX}/rx_clock.h ${RX}/rx_queue.h ${RX}/rx_event.h ${RX}/rx_internal.h
 
 rxkad_client.o: ${RXKAD}/rxkad_client.c
        ${CCRULE} ${RXKAD}/rxkad_client.c
index 6b028fe..7ec8d2f 100644 (file)
 #define CV_SIGNAL(_cv)         e_wakeup_one(_cv)
 #define CV_BROADCAST(_cv)      e_wakeup(_cv)
 typedef simple_lock_data afs_kmutex_t;
+typedef afs_kmutex_t afs_krwlock_t;
 typedef tid_t afs_kcondvar_t;
 
 
+#define RWLOCK_INIT(a, b, c, d) MUTEX_INIT(a,b,c,d)
+#define RWLOCK_DESTROY(l)       MUTEX_DESTROY(l)
+#define RWLOCK_UPLOCK(l) 
+#define RWLOCK_WRLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_RDLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_TRYWRLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_TRYRDLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_UNLOCK(l)        MUTEX_EXIT(l)
+
 #define        LOCK_INIT(a, b)         lock_alloc((void*)(a), LOCK_ALLOC_PIN, 1, 1), \
                                simple_lock_init((void *)(a))
 #define MUTEX_INIT(a,b,c,d)    lock_alloc((void*)(a), LOCK_ALLOC_PIN, 1, 1), \
index 39fe820..7a006d7 100644 (file)
@@ -36,6 +36,16 @@ typedef struct {
     struct proc *owner;
 } afs_kmutex_t;
 
+typedef afs_kmutex_t afs_krwlock_t;
+#define RWLOCK_INIT(a, b, c, d) MUTEX_INIT(a,b,c,d)
+#define RWLOCK_DESTROY(l)       MUTEX_DESTROY(l)
+#define RWLOCK_UPLOCK(l) 
+#define RWLOCK_WRLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_RDLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_TRYWRLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_TRYRDLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_UNLOCK(l)        MUTEX_EXIT(l)
+
 #define MUTEX_INIT(a,b,c,d) \
     do { \
        (a)->owner = 0; \
index 09bd3bd..8974fb8 100644 (file)
@@ -138,6 +138,16 @@ extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
 
 #define AFS_RX_ORDER 30
 
+typedef afs_kmutex_t afs_krwlock_t;
+#define RWLOCK_INIT(a, b, c, d) MUTEX_INIT(a,b,c,d)
+#define RWLOCK_DESTROY(l)       MUTEX_DESTROY(l)
+#define RWLOCK_UPLOCK(l) 
+#define RWLOCK_WRLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_RDLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_TRYWRLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_TRYRDLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_UNLOCK(l)        MUTEX_EXIT(l)
+
 #define MUTEX_INIT(a,b,c,d) b_initsema((a), 1, AFS_RX_ORDER, (b))
 #define MUTEX_DESTROY(a)
 
@@ -163,6 +173,15 @@ extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
 
 #define osirx_AssertMine(addr, msg)
 
+#define RWLOCK_INIT(a, b, c, d) 
+#define RWLOCK_DESTROY(l)       
+#define RWLOCK_UPLOCK(l) 
+#define RWLOCK_WRLOCK(l)        
+#define RWLOCK_RDLOCK(l)        
+#define RWLOCK_TRYWRLOCK(l)     
+#define RWLOCK_TRYRDLOCK(l)     
+#define RWLOCK_UNLOCK(l)        
+
 #define MUTEX_DESTROY(a)
 #define MUTEX_ENTER(a)
 #define MUTEX_TRYENTER(a) 1
index 63414a7..155a8d0 100644 (file)
@@ -28,6 +28,7 @@
 #define mutex_tryenter(m) cpsema(m)
 #endif /* mutex_tryenter */
 typedef kmutex_t afs_kmutex_t;
+typedef afs_kmutex_t afs_krwlock_t;
 typedef kcondvar_t afs_kcondvar_t;
 
 #ifndef        CV_DEFAULT
@@ -37,6 +38,15 @@ typedef kcondvar_t afs_kcondvar_t;
 #define        MUTEX_DEFAULT   0
 #endif
 
+#define RWLOCK_INIT(a, b, c, d) MUTEX_INIT(a,b,c,d)
+#define RWLOCK_DESTROY(l)       MUTEX_DESTROY(l)
+#define RWLOCK_UPLOCK(l) 
+#define RWLOCK_WRLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_RDLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_TRYWRLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_TRYRDLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_UNLOCK(l)        MUTEX_EXIT(l)
+
 #ifdef AFS_SGI62_ENV
 #define MUTEX_INIT(m, nm, type , a)  mutex_init(m, type, nm)
 #else
index 6ea4faf..054087e 100644 (file)
@@ -49,6 +49,8 @@ typedef struct afs_kmutex {
     int owner;
 } afs_kmutex_t;
 
+typedef afs_kmutex_t afs_krwlock_t;
+
 #ifndef set_current_state
 #define set_current_state(X) current->state=X
 #endif
@@ -68,6 +70,15 @@ MUTEX_ISMINE(afs_kmutex_t * l)
     return l->owner == current->pid;
 }
 
+#define RWLOCK_INIT(a, b, c, d) MUTEX_INIT(a,b,c,d)
+#define RWLOCK_DESTROY(l)       MUTEX_DESTROY(l)
+#define RWLOCK_UPLOCK(l) 
+#define RWLOCK_WRLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_RDLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_TRYWRLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_TRYRDLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_UNLOCK(l)        MUTEX_EXIT(l)
+
 #define MUTEX_INIT(a,b,c,d)    afs_mutex_init(a)
 #define MUTEX_DESTROY(a)
 #define MUTEX_ENTER            afs_mutex_enter
index 0d9ab79..140d39e 100644 (file)
@@ -49,33 +49,33 @@ RX_component_version_number.c: AFS_component_version_number.c
 
 RX_component_version_number.o: RX_component_version_number.c
 
-${RXOBJS}: ${BASICINCLS} rx.h rx_user.h rx_globals.h rx_prototypes.h
+${RXOBJS}: ${BASICINCLS} rx.h rx_user.h rx_globals.h rx_prototypes.h rx_internal.h
 
-${MULTIOBJS}: rx.h rx_multi.h rx_prototypes.h
+${MULTIOBJS}: rx.h rx_multi.h rx_prototypes.h rx_internal.h
 
 ${XDROBJS}: xdr.h xdr_prototypes.h
 
 rxperf.o: rx.h rx_null.h rx_globals.h rx_prototypes.h
 
-rx_user.o: rx.h rx_user.h rx_prototypes.h
+rx_user.o: rx.h rx_user.h rx_prototypes.h rx_internal.h
 
-rx_packet.o: rx_packet.c rx_packet.h
+rx_packet.o: rx_packet.c rx_packet.h rx_internal.h rx.h
 
-rx_rdwr.o: rx_rdwr.c rx.h rx_prototypes.h
+rx_rdwr.o: rx_rdwr.c rx.h rx_prototypes.h rx_internal.h
 
-rx.o: rx.h rx_user.h rx_prototypes.h
+rx.o: rx.h rx_user.h rx_prototypes.h rx_internal.h
 
-rx_conncache.o: rx.h rx_prototypes.h
+rx_conncache.o: rx.h rx_prototypes.h rx_internal.h
 
-rx_trace.o: rx_trace.h 
+rx_trace.o: rx_trace.h rx_internal.h
 
-rx_getaddr.o: rx.h rx_getaddr.c rx_prototypes.h
+rx_getaddr.o: rx.h rx_getaddr.c rx_prototypes.h rx_internal.h
 
-rx_globals.o: rx.h rx_user.h rx_globals.h rx_prototypes.h
+rx_globals.o: rx.h rx_user.h rx_globals.h rx_prototypes.h rx_internal.h
 
-xdr_rx.o: xdr.h rx.h xdr_prototypes.h rx_prototypes.h
+xdr_rx.o: xdr.h rx.h xdr_prototypes.h rx_prototypes.h rx_internal.h
 
-xdr_refernce.o: xdr_refernce.c xdr.h xdr_prototypes.h
+xdr_refernce.o: xdr_refernce.c xdr.h xdr_prototypes.h rx_internal.h
 
 rxperf: rxperf.o librx.a
        ${CC} -o $@ rxperf.o ${LIBS}
index 7c81966..193fdd5 100644 (file)
@@ -63,8 +63,18 @@ typedef struct {
     struct lock__bsd__ lock;
     thread_t owner;
 } afs_kmutex_t;
+typedef afs_krwlock_t afs_kmutex_t;
 typedef int afs_kcondvar_t;
 
+#define RWLOCK_INIT(a, b, c, d) MUTEX_INIT(a,b,c,d)
+#define RWLOCK_DESTROY(l)       MUTEX_DESTROY(l)
+#define RWLOCK_UPLOCK(l) 
+#define RWLOCK_WRLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_RDLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_TRYWRLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_TRYRDLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_UNLOCK(l)        MUTEX_EXIT(l)
+
 #define osi_rxWakeup(cv)        thread_wakeup((event_t)(cv))
 
 #define LOCK_INIT(a,b) \
index dfe0c16..55efa5f 100644 (file)
@@ -42,9 +42,19 @@ typedef int afs_kcondvar_t;
 typedef struct {
     struct proc *owner;
 } afs_kmutex_t;
+typedef afs_kmutex_t afs_krwlock_t;
 
 #define        MUTEX_DEFAULT   0
 
+#define RWLOCK_INIT(a, b, c, d) MUTEX_INIT(a,b,c,d)
+#define RWLOCK_DESTROY(l)       MUTEX_DESTROY(l)
+#define RWLOCK_UPLOCK(l) 
+#define RWLOCK_WRLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_RDLOCK(l)        MUTEX_ENTER(l)
+#define RWLOCK_TRYWRLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_TRYRDLOCK(l)     MUTEX_TRYENTER(l)
+#define RWLOCK_UNLOCK(l)        MUTEX_EXIT(l)
+
 #define MUTEX_INIT(a,b,c,d) \
     do { \
        (a)->owner = 0; \
index 63aa8f4..d56284b 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/mutex.h>
 
 typedef kmutex_t afs_kmutex_t;
+typedef afs_kmutex_t afs_krwlock_t;
 typedef kcondvar_t afs_kcondvar_t;
 
 #undef osirx_AssertMine
index 38a140b..ad092a2 100644 (file)
 #define RX_ENABLE_LOCKS                1
 
 #define        afs_kmutex_t            usr_mutex_t
+#define        afs_krwlock_t           usr_mutex_t
 #define        afs_kcondvar_t          usr_cond_t
+#define RWLOCK_INIT(a, b, c, d) usr_mutex_init(a)
+#define RWLOCK_DESTROY(l)       usr_mutex_destroy(l)
+#define RWLOCK_UPLOCK(l) 
+#define RWLOCK_WRLOCK(l)        usr_mutex_lock(l)
+#define RWLOCK_RDLOCK(l)        usr_mutex_lock(l)
+#define RWLOCK_TRYWRLOCK(l)     usr_mutex_trylock(l)
+#define RWLOCK_TRYRDLOCK(l)     usr_mutex_trylock(l)
+#define RWLOCK_UNLOCK(l)        usr_mutex_unlock(l)
 #define MUTEX_INIT(A,B,C,D)    usr_mutex_init(A)
 #define MUTEX_ENTER(A)         usr_mutex_lock(A)
 #define MUTEX_TRYENTER(A)      usr_mutex_trylock(A)
index 7f706ff..255acc6 100644 (file)
@@ -69,6 +69,7 @@ RCSID
 #include "rx_kernel.h"
 #include "rx_clock.h"
 #include "rx_queue.h"
+#include "rx_internal.h"
 #include "rx.h"
 #include "rx_globals.h"
 #include "rx_trace.h"
@@ -100,6 +101,7 @@ extern afs_int32 afs_termState;
 # include <netinet/in.h>
 # include <sys/time.h>
 #endif
+# include "rx_internal.h"
 # include "rx.h"
 # include "rx_user.h"
 # include "rx_clock.h"
@@ -240,9 +242,9 @@ rxi_InitPthread(void)
               0);
     CV_INIT(&rx_waitingForPackets_cv, "rx_waitingForPackets_cv", CV_DEFAULT,
            0);
-    MUTEX_INIT(&rx_peerHashTable_lock, "rx_peerHashTable_lock", MUTEX_DEFAULT,
+    RWLOCK_INIT(&rx_peerHashTable_lock, "rx_peerHashTable_lock", MUTEX_DEFAULT,
               0);
-    MUTEX_INIT(&rx_connHashTable_lock, "rx_connHashTable_lock", MUTEX_DEFAULT,
+    RWLOCK_INIT(&rx_connHashTable_lock, "rx_connHashTable_lock", MUTEX_DEFAULT,
               0);
     MUTEX_INIT(&rx_serverPool_lock, "rx_serverPool_lock", MUTEX_DEFAULT, 0);
     MUTEX_INIT(&rxi_keyCreate_lock, "rxi_keyCreate_lock", MUTEX_DEFAULT, 0);
@@ -462,9 +464,9 @@ rx_InitHost(u_int host, u_int port)
               0);
     CV_INIT(&rx_waitingForPackets_cv, "rx_waitingForPackets_cv", CV_DEFAULT,
            0);
-    MUTEX_INIT(&rx_peerHashTable_lock, "rx_peerHashTable_lock", MUTEX_DEFAULT,
+    RWLOCK_INIT(&rx_peerHashTable_lock, "rx_peerHashTable_lock", MUTEX_DEFAULT,
               0);
-    MUTEX_INIT(&rx_connHashTable_lock, "rx_connHashTable_lock", MUTEX_DEFAULT,
+    RWLOCK_INIT(&rx_connHashTable_lock, "rx_connHashTable_lock", MUTEX_DEFAULT,
               0);
     MUTEX_INIT(&rx_serverPool_lock, "rx_serverPool_lock", MUTEX_DEFAULT, 0);
 #if defined(AFS_HPUX110_ENV)
@@ -536,9 +538,7 @@ rx_InitHost(u_int host, u_int port)
     rx_SetEpoch(tv.tv_sec);    /* Start time of this package, rxkad
                                 * will provide a randomer value. */
 #endif
-    MUTEX_ENTER(&rx_stats_mutex);
-    rxi_dataQuota += rx_extraQuota;    /* + extra pkts caller asked to rsrv */
-    MUTEX_EXIT(&rx_stats_mutex);
+    rx_MutexAdd(rxi_dataQuota, rx_extraQuota, rx_stats_mutex); /* + extra pkts caller asked to rsrv */
     /* *Slightly* random start time for the cid.  This is just to help
      * out with the hashing function at the peer */
     rx_nextCid = ((tv.tv_sec ^ tv.tv_usec) << RX_CIDSHIFT);
@@ -793,11 +793,10 @@ rx_NewConnection(register afs_uint32 shost, u_short sport, u_short sservice,
      * the case of kmem_alloc? */
 
     NETPRI;
-    MUTEX_ENTER(&rx_connHashTable_lock);
+    RWLOCK_WRLOCK(&rx_connHashTable_lock);
 
     /* send in the clones */
     for(cix = 0; cix <= nclones; ++cix) {
-         
          ptconn = tconn;
          tconn = rxi_AllocConnection();
          tconn->type = RX_CLIENT_CONNECTION;
@@ -814,10 +813,10 @@ rx_NewConnection(register afs_uint32 shost, u_short sport, u_short sservice,
          tconn->delayedAbortEvent = NULL;
          tconn->abortCount = 0;
          tconn->error = 0;
-    for (i = 0; i < RX_MAXCALLS; i++) {
-       tconn->twind[i] = rx_initSendWindow;
-       tconn->rwind[i] = rx_initReceiveWindow;
-    }
+         for (i = 0; i < RX_MAXCALLS; i++) {
+             tconn->twind[i] = rx_initSendWindow;
+             tconn->rwind[i] = rx_initReceiveWindow;
+         }
          tconn->parent = 0;
          tconn->next_clone = 0;
          tconn->nclones = nclones;
@@ -849,7 +848,7 @@ rx_NewConnection(register afs_uint32 shost, u_short sport, u_short sservice,
          rx_MutexIncrement(rx_stats.nClientConns, rx_stats_mutex);     
     }
     
-    MUTEX_EXIT(&rx_connHashTable_lock);
+    RWLOCK_UNLOCK(&rx_connHashTable_lock);
     USERPRI;
     return conn;
 }
@@ -889,18 +888,16 @@ rxi_CleanupConnection(struct rx_connection *conn)
      * idle time to now. rxi_ReapConnections will reap it if it's still
      * idle (refCount == 0) after rx_idlePeerTime (60 seconds) have passed.
      */
-    MUTEX_ENTER(&rx_peerHashTable_lock);
+    RWLOCK_WRLOCK(&rx_peerHashTable_lock);
     if (conn->peer->refCount < 2) {
        conn->peer->idleWhen = clock_Sec();
        if (conn->peer->refCount < 1) {
            conn->peer->refCount = 1;
-           MUTEX_ENTER(&rx_stats_mutex);
-           rxi_lowPeerRefCount++;
-           MUTEX_EXIT(&rx_stats_mutex);
+           rx_MutexIncrement(rxi_lowPeerRefCount, rx_stats_mutex);
        }
     }
     conn->peer->refCount--;
-    MUTEX_EXIT(&rx_peerHashTable_lock);
+    RWLOCK_UNLOCK(&rx_peerHashTable_lock);
 
     if (conn->type == RX_SERVER_CONNECTION)
        rx_MutexDecrement(rx_stats.nServerConns, rx_stats_mutex);
@@ -932,8 +929,8 @@ void
 rxi_DestroyConnection(register struct rx_connection *conn)
 {
   register struct rx_connection *tconn, *dtconn;
-
-  MUTEX_ENTER(&rx_connHashTable_lock);
+  
+  RWLOCK_WRLOCK(&rx_connHashTable_lock);
   
   if(!(conn->flags & RX_CLONED_CONNECTION)) {
        tconn = conn->next_clone;
@@ -946,10 +943,10 @@ rxi_DestroyConnection(register struct rx_connection *conn)
                /* destroyed? */
                if (dtconn == rx_connCleanup_list) {
                  rx_connCleanup_list = rx_connCleanup_list->next;
-                 MUTEX_EXIT(&rx_connHashTable_lock);
+                 RWLOCK_UNLOCK(&rx_connHashTable_lock);
                  /* rxi_CleanupConnection will free tconn */   
                  rxi_CleanupConnection(dtconn);
-                 MUTEX_ENTER(&rx_connHashTable_lock);
+                 RWLOCK_WRLOCK(&rx_connHashTable_lock);
                  (conn->nclones)--;
                }
          }
@@ -960,12 +957,12 @@ rxi_DestroyConnection(register struct rx_connection *conn)
   /* conn should be at the head of the cleanup list */
   if (conn == rx_connCleanup_list) {
        rx_connCleanup_list = rx_connCleanup_list->next;
-       MUTEX_EXIT(&rx_connHashTable_lock);
+       RWLOCK_UNLOCK(&rx_connHashTable_lock);
        rxi_CleanupConnection(conn);
   }
 #ifdef RX_ENABLE_LOCKS
   else {
-       MUTEX_EXIT(&rx_connHashTable_lock);
+       RWLOCK_UNLOCK(&rx_connHashTable_lock);
   }
 #endif /* RX_ENABLE_LOCKS */
 }
@@ -986,9 +983,7 @@ rxi_DestroyConnectionNoLock(register struct rx_connection *conn)
     if (conn->refCount > 0)
        conn->refCount--;
     else {
-       MUTEX_ENTER(&rx_stats_mutex);
-       rxi_lowConnRefCount++;
-       MUTEX_EXIT(&rx_stats_mutex);
+       rx_MutexIncrement(rxi_lowConnRefCount, rx_stats_mutex);
     }
 
     if ((conn->refCount > 0) || (conn->flags & RX_CONN_BUSY)) {
@@ -1048,9 +1043,7 @@ rxi_DestroyConnectionNoLock(register struct rx_connection *conn)
     if (havecalls) {
        /* Don't destroy the connection if there are any call
         * structures still in use */
-       MUTEX_ENTER(&conn->conn_data_lock);
-       conn->flags |= RX_CONN_DESTROY_ME;
-       MUTEX_EXIT(&conn->conn_data_lock);
+       rx_MutexOr(conn->flags, RX_CONN_DESTROY_ME, conn->conn_data_lock);
        USERPRI;
        return;
     }
@@ -1114,9 +1107,7 @@ rx_GetConnection(register struct rx_connection *conn)
     SPLVAR;
 
     NETPRI;
-    MUTEX_ENTER(&conn->conn_data_lock);
-    conn->refCount++;
-    MUTEX_EXIT(&conn->conn_data_lock);
+    rx_MutexIncrement(conn->refCount, conn->conn_data_lock);
     USERPRI;
 }
 
@@ -1193,10 +1184,10 @@ rx_NewCall(register struct rx_connection *conn)
 #else
         osi_rxSleep(conn);
 #endif
-       MUTEX_ENTER(&conn->conn_data_lock);
-       conn->makeCallWaiters--;
-    } 
-    MUTEX_EXIT(&conn->conn_data_lock);
+       rx_MutexDecrement(conn->makeCallWaiters, conn->conn_data_lock);
+    } else {
+       MUTEX_EXIT(&conn->conn_data_lock);
+    }
 
        /* search for next free call on this connection or 
         * its clones, if any */
@@ -1239,9 +1230,7 @@ rx_NewCall(register struct rx_connection *conn)
 #else
                osi_rxSleep(conn);
 #endif
-               MUTEX_ENTER(&conn->conn_data_lock);
-               conn->makeCallWaiters--;
-               MUTEX_EXIT(&conn->conn_data_lock);
+               rx_MutexDecrement(conn->makeCallWaiters, conn->conn_data_lock);
     } /* for ;; */
     /*
      * Wake up anyone else who might be giving us a chance to
@@ -1537,9 +1526,7 @@ rxi_ServerProc(int threadID, struct rx_call *newcall, osi_socket * socketp)
            (*tservice->afterProc) (call, code);
 
        rx_EndCall(call, code);
-       MUTEX_ENTER(&rx_stats_mutex);
-       rxi_nCalls++;
-       MUTEX_EXIT(&rx_stats_mutex);
+       rx_MutexIncrement(rxi_nCalls, rx_stats_mutex);
     }
 }
 
@@ -1691,9 +1678,7 @@ rx_GetCall(int tno, struct rx_service *cur_service, osi_socket * socketp)
 
            if (call->flags & RX_CALL_WAIT_PROC) {
                call->flags &= ~RX_CALL_WAIT_PROC;
-               MUTEX_ENTER(&rx_stats_mutex);
-               rx_nWaiting--;
-               MUTEX_EXIT(&rx_stats_mutex);
+               rx_MutexDecrement(rx_nWaiting, rx_stats_mutex);
            }
 
            if (call->state != RX_STATE_PRECALL || call->error) {
@@ -2110,7 +2095,7 @@ rx_Finalize(void)
     }
     rxi_DeleteCachedConnections();
     if (rx_connHashTable) {
-       MUTEX_ENTER(&rx_connHashTable_lock);
+       RWLOCK_WRLOCK(&rx_connHashTable_lock);
        for (conn_ptr = &rx_connHashTable[0], conn_end =
             &rx_connHashTable[rx_hashTableSize]; conn_ptr < conn_end;
             conn_ptr++) {
@@ -2134,11 +2119,11 @@ rx_Finalize(void)
            struct rx_connection *conn;
            conn = rx_connCleanup_list;
            rx_connCleanup_list = rx_connCleanup_list->next;
-           MUTEX_EXIT(&rx_connHashTable_lock);
+           RWLOCK_UNLOCK(&rx_connHashTable_lock);
            rxi_CleanupConnection(conn);
-           MUTEX_ENTER(&rx_connHashTable_lock);
+           RWLOCK_WRLOCK(&rx_connHashTable_lock);
        }
-       MUTEX_EXIT(&rx_connHashTable_lock);
+       RWLOCK_UNLOCK(&rx_connHashTable_lock);
 #endif /* RX_ENABLE_LOCKS */
     }
     rxi_flushtrace();
@@ -2329,9 +2314,7 @@ rxi_FreeCall(register struct rx_call *call)
      * call lock held or are going through this section of code.
      */
     if (conn->flags & RX_CONN_DESTROY_ME && !(conn->flags & RX_CONN_MAKECALL_WAITING)) {
-       MUTEX_ENTER(&conn->conn_data_lock);
-       conn->refCount++;
-       MUTEX_EXIT(&conn->conn_data_lock);
+       rx_MutexIncrement(conn->refCount, conn->conn_data_lock);
 #ifdef RX_ENABLE_LOCKS
        if (haveCTLock)
            rxi_DestroyConnectionNoLock(conn);
@@ -2376,7 +2359,7 @@ rxi_SetPeerMtu(register afs_uint32 host, register afs_uint32 port, int mtu)
     struct rx_peer **peer_ptr, **peer_end;
     int hashIndex;
 
-    MUTEX_ENTER(&rx_peerHashTable_lock);
+    RWLOCK_RDLOCK(&rx_peerHashTable_lock);
     if (port == 0) {
        for (peer_ptr = &rx_peerHashTable[0], peer_end =
                 &rx_peerHashTable[rx_hashTableSize]; peer_ptr < peer_end;
@@ -2404,7 +2387,7 @@ rxi_SetPeerMtu(register afs_uint32 host, register afs_uint32 port, int mtu)
            }
        }
     }
-    MUTEX_EXIT(&rx_peerHashTable_lock);
+    RWLOCK_UNLOCK(&rx_peerHashTable_lock);
 }
 
 /* Find the peer process represented by the supplied (host,port)
@@ -2420,7 +2403,7 @@ rxi_FindPeer(register afs_uint32 host, register u_short port,
     register struct rx_peer *pp;
     int hashIndex;
     hashIndex = PEER_HASH(host, port);
-    MUTEX_ENTER(&rx_peerHashTable_lock);
+    RWLOCK_RDLOCK(&rx_peerHashTable_lock);
     for (pp = rx_peerHashTable[hashIndex]; pp; pp = pp->next) {
        if ((pp->host == host) && (pp->port == port))
             break;
@@ -2433,6 +2416,7 @@ rxi_FindPeer(register afs_uint32 host, register u_short port,
            MUTEX_INIT(&pp->peer_lock, "peer_lock", MUTEX_DEFAULT, 0);
            queue_Init(&pp->congestionQueue);
            queue_Init(&pp->rpcStats);
+           RWLOCK_UPLOCK(&rx_peerHashTable_lock);
            pp->next = rx_peerHashTable[hashIndex];
            rx_peerHashTable[hashIndex] = pp;
            rxi_InitPeerParams(pp);
@@ -2444,7 +2428,7 @@ rxi_FindPeer(register afs_uint32 host, register u_short port,
     }
     if (origPeer)
        origPeer->refCount--;
-    MUTEX_EXIT(&rx_peerHashTable_lock);
+    RWLOCK_UNLOCK(&rx_peerHashTable_lock);
     return pp;
 }
 
@@ -2469,7 +2453,7 @@ rxi_FindConnection(osi_socket socket, register afs_int32 host,
     int hashindex, flag, i;
     register struct rx_connection *conn;
     hashindex = CONN_HASH(host, port, cid, epoch, type);
-    MUTEX_ENTER(&rx_connHashTable_lock);
+    RWLOCK_RDLOCK(&rx_connHashTable_lock);
     rxLastConn ? (conn = rxLastConn, flag = 0) : (conn =
                                                  rx_connHashTable[hashindex],
                                                  flag = 1);
@@ -2482,7 +2466,7 @@ rxi_FindConnection(osi_socket socket, register afs_int32 host,
                 * like this, and there seems to be some CM bug that makes this
                 * happen from time to time -- in which case, the fileserver
                 * asserts. */
-               MUTEX_EXIT(&rx_connHashTable_lock);
+               RWLOCK_UNLOCK(&rx_connHashTable_lock);
                return (struct rx_connection *)0;
            }
            if (pp->host == host && pp->port == port)
@@ -2505,26 +2489,23 @@ rxi_FindConnection(osi_socket socket, register afs_int32 host,
     if (!conn) {
        struct rx_service *service;
        if (type == RX_CLIENT_CONNECTION) {
-           MUTEX_EXIT(&rx_connHashTable_lock);
+           RWLOCK_UNLOCK(&rx_connHashTable_lock);
            return (struct rx_connection *)0;
        }
        service = rxi_FindService(socket, serviceId);
        if (!service || (securityIndex >= service->nSecurityObjects)
            || (service->securityObjects[securityIndex] == 0)) {
-           MUTEX_EXIT(&rx_connHashTable_lock);
+           RWLOCK_UNLOCK(&rx_connHashTable_lock);
            return (struct rx_connection *)0;
        }
        conn = rxi_AllocConnection();   /* This bzero's the connection */
        MUTEX_INIT(&conn->conn_call_lock, "conn call lock", MUTEX_DEFAULT, 0);
        MUTEX_INIT(&conn->conn_data_lock, "conn data lock", MUTEX_DEFAULT, 0);
        CV_INIT(&conn->conn_call_cv, "conn call cv", CV_DEFAULT, 0);
-       conn->next = rx_connHashTable[hashindex];
-       rx_connHashTable[hashindex] = conn;
        conn->peer = rxi_FindPeer(host, port, 0, 1);
        conn->type = RX_SERVER_CONNECTION;
        conn->lastSendTime = clock_Sec();       /* don't GC immediately */
        conn->epoch = epoch;
-       conn->cid = cid & RX_CIDMASK;
        /* conn->serial = conn->lastSerial = 0; */
        /* conn->timeout = 0; */
        conn->ackRate = RX_FAST_ACK_RATE;
@@ -2541,6 +2522,10 @@ rxi_FindConnection(osi_socket socket, register afs_int32 host,
            conn->twind[i] = rx_initSendWindow;
            conn->rwind[i] = rx_initReceiveWindow;
        }
+       RWLOCK_UPLOCK(&rx_connHashTable_lock);
+       conn->next = rx_connHashTable[hashindex];
+       rx_connHashTable[hashindex] = conn;
+       conn->cid = cid & RX_CIDMASK;
        /* Notify security object of the new connection */
        RXS_NewConnection(conn->securityObject, conn);
        /* XXXX Connection timeout? */
@@ -2549,12 +2534,10 @@ rxi_FindConnection(osi_socket socket, register afs_int32 host,
         rx_MutexIncrement(rx_stats.nServerConns, rx_stats_mutex);
     }
 
-    MUTEX_ENTER(&conn->conn_data_lock);
-    conn->refCount++;
-    MUTEX_EXIT(&conn->conn_data_lock);
+    rx_MutexIncrement(conn->refCount, conn->conn_data_lock);
 
     rxLastConn = conn;         /* store this connection as the last conn used */
-    MUTEX_EXIT(&rx_connHashTable_lock);
+    RWLOCK_UNLOCK(&rx_connHashTable_lock);
     return conn;
 }
 
@@ -2675,30 +2658,22 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
            afs_int32 errcode = ntohl(rx_GetInt32(np, 0));
            dpf(("rxi_ReceivePacket ABORT rx_GetInt32 = %d", errcode));
            rxi_ConnectionError(conn, errcode);
-           MUTEX_ENTER(&conn->conn_data_lock);
-           conn->refCount--;
-           MUTEX_EXIT(&conn->conn_data_lock);
+           rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
            return np;
        }
        case RX_PACKET_TYPE_CHALLENGE:
            tnp = rxi_ReceiveChallengePacket(conn, np, 1);
-           MUTEX_ENTER(&conn->conn_data_lock);
-           conn->refCount--;
-           MUTEX_EXIT(&conn->conn_data_lock);
+           rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
            return tnp;
        case RX_PACKET_TYPE_RESPONSE:
            tnp = rxi_ReceiveResponsePacket(conn, np, 1);
-           MUTEX_ENTER(&conn->conn_data_lock);
-           conn->refCount--;
-           MUTEX_EXIT(&conn->conn_data_lock);
+           rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
            return tnp;
        case RX_PACKET_TYPE_PARAMS:
        case RX_PACKET_TYPE_PARAMS + 1:
        case RX_PACKET_TYPE_PARAMS + 2:
            /* ignore these packet types for now */
-           MUTEX_ENTER(&conn->conn_data_lock);
-           conn->refCount--;
-           MUTEX_EXIT(&conn->conn_data_lock);
+           rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
            return np;
 
 
@@ -2745,9 +2720,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
             * it must be for the previous call.
             */
            rx_MutexIncrement(rx_stats.spuriousPacketsRead, rx_stats_mutex);
-           MUTEX_ENTER(&conn->conn_data_lock);
-           conn->refCount--;
-           MUTEX_EXIT(&conn->conn_data_lock);
+           rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
            return np;
        }
     }
@@ -2761,9 +2734,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
            if (call)
                MUTEX_EXIT(&call->lock);
 #endif
-           MUTEX_ENTER(&conn->conn_data_lock);
-           conn->refCount--;
-           MUTEX_EXIT(&conn->conn_data_lock);
+           rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
            return np;
        }
        if (!call) {
@@ -2788,9 +2759,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
                rxi_CallError(call, rx_BusyError);
                tp = rxi_SendCallAbort(call, np, 1, 0);
                MUTEX_EXIT(&call->lock);
-               MUTEX_ENTER(&conn->conn_data_lock);
-               conn->refCount--;
-               MUTEX_EXIT(&conn->conn_data_lock);
+               rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
                 rx_MutexIncrement(rx_stats.nBusies, rx_stats_mutex);
                return tp;
            }
@@ -2827,9 +2796,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
                tp = rxi_SendSpecial(call, conn, np, RX_PACKET_TYPE_BUSY,
                                     NULL, 0, 1);
                MUTEX_EXIT(&call->lock);
-               MUTEX_ENTER(&conn->conn_data_lock);
-               conn->refCount--;
-               MUTEX_EXIT(&conn->conn_data_lock);
+               rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
                return tp;
            }
            rxi_ResetCall(call, 0);
@@ -2851,9 +2818,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
                rxi_CallError(call, rx_BusyError);
                tp = rxi_SendCallAbort(call, np, 1, 0);
                MUTEX_EXIT(&call->lock);
-               MUTEX_ENTER(&conn->conn_data_lock);
-               conn->refCount--;
-               MUTEX_EXIT(&conn->conn_data_lock);
+               rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
                 rx_MutexIncrement(rx_stats.nBusies, rx_stats_mutex);
                return tp;
            }
@@ -2871,9 +2836,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
                MUTEX_EXIT(&call->lock);
            }
 #endif
-           MUTEX_ENTER(&conn->conn_data_lock);
-           conn->refCount--;
-           MUTEX_EXIT(&conn->conn_data_lock);
+           rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
            return np;
        }
 
@@ -2886,9 +2849,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
                MUTEX_EXIT(&call->lock);
            }
 #endif
-           MUTEX_ENTER(&conn->conn_data_lock);
-           conn->refCount--;
-           MUTEX_EXIT(&conn->conn_data_lock);
+           rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
            return np;
        }
        /* If the service security object index stamped in the packet does not
@@ -2897,9 +2858,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
 #ifdef RX_ENABLE_LOCKS
            MUTEX_EXIT(&call->lock);
 #endif
-           MUTEX_ENTER(&conn->conn_data_lock);
-           conn->refCount--;
-           MUTEX_EXIT(&conn->conn_data_lock);
+           rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
            return np;
        }
 
@@ -2947,9 +2906,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
                if (ntohl(rx_GetInt32(np, FIRSTACKOFFSET)) < call->tfirst) {
                     rx_MutexIncrement(rx_stats.spuriousPacketsRead, rx_stats_mutex);
                    MUTEX_EXIT(&call->lock);
-                   MUTEX_ENTER(&conn->conn_data_lock);
-                   conn->refCount--;
-                   MUTEX_EXIT(&conn->conn_data_lock);
+                   rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
                    return np;
                }
            }
@@ -3011,9 +2968,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
        dpf(("rxi_ReceivePacket ABORT rx_DataOf = %d", errdata));
        rxi_CallError(call, errdata);
        MUTEX_EXIT(&call->lock);
-       MUTEX_ENTER(&conn->conn_data_lock);
-       conn->refCount--;
-       MUTEX_EXIT(&conn->conn_data_lock);
+       rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
        return np;              /* xmitting; drop packet */
     }
     case RX_PACKET_TYPE_BUSY:
@@ -3038,9 +2993,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
            break;
 #else /* RX_ENABLE_LOCKS */
            MUTEX_EXIT(&call->lock);
-           MUTEX_ENTER(&conn->conn_data_lock);
-           conn->refCount--;
-           MUTEX_EXIT(&conn->conn_data_lock);
+           rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
            return np;          /* xmitting; drop packet */
 #endif /* RX_ENABLE_LOCKS */
        }
@@ -3061,9 +3014,7 @@ rxi_ReceivePacket(register struct rx_packet *np, osi_socket socket,
      * (if not, then the time won't actually be re-evaluated here). */
     call->lastReceiveTime = clock_Sec();
     MUTEX_EXIT(&call->lock);
-    MUTEX_ENTER(&conn->conn_data_lock);
-    conn->refCount--;
-    MUTEX_EXIT(&conn->conn_data_lock);
+    rx_MutexDecrement(conn->refCount, conn->conn_data_lock);
     return np;
 }
 
@@ -4259,9 +4210,7 @@ rxi_AttachServerProc(register struct rx_call *call,
            call->flags &= ~RX_CALL_WAIT_PROC;
            if (queue_IsOnQueue(call)) {
                queue_Remove(call);
-               MUTEX_ENTER(&rx_stats_mutex);
-               rx_nWaiting--;
-               MUTEX_EXIT(&rx_stats_mutex);
+               rx_MutexDecrement(rx_nWaiting, rx_stats_mutex);
            }
        }
        call->state = RX_STATE_ACTIVE;
@@ -4723,9 +4672,7 @@ rxi_ResetCall(register struct rx_call *call, register int newcall)
        if (queue_IsOnQueue(call)) {
            queue_Remove(call);
            if (flags & RX_CALL_WAIT_PROC) {
-               MUTEX_ENTER(&rx_stats_mutex);
-               rx_nWaiting--;
-               MUTEX_EXIT(&rx_stats_mutex);
+               rx_MutexDecrement(rx_nWaiting, rx_stats_mutex);
            }
        }
        MUTEX_EXIT(call->call_queue_lock);
@@ -5984,7 +5931,7 @@ rxi_ReapConnections(struct rxevent *unused, void *unused1, void *unused2)
     {
        struct rx_connection **conn_ptr, **conn_end;
        int i, havecalls = 0;
-       MUTEX_ENTER(&rx_connHashTable_lock);
+       RWLOCK_WRLOCK(&rx_connHashTable_lock);
        for (conn_ptr = &rx_connHashTable[0], conn_end =
             &rx_connHashTable[rx_hashTableSize]; conn_ptr < conn_end;
             conn_ptr++) {
@@ -6045,11 +5992,11 @@ rxi_ReapConnections(struct rxevent *unused, void *unused1, void *unused2)
            struct rx_connection *conn;
            conn = rx_connCleanup_list;
            rx_connCleanup_list = rx_connCleanup_list->next;
-           MUTEX_EXIT(&rx_connHashTable_lock);
+           RWLOCK_UNLOCK(&rx_connHashTable_lock);
            rxi_CleanupConnection(conn);
-           MUTEX_ENTER(&rx_connHashTable_lock);
+           RWLOCK_WRLOCK(&rx_connHashTable_lock);
        }
-       MUTEX_EXIT(&rx_connHashTable_lock);
+       RWLOCK_UNLOCK(&rx_connHashTable_lock);
 #endif /* RX_ENABLE_LOCKS */
     }
 
@@ -6059,7 +6006,7 @@ rxi_ReapConnections(struct rxevent *unused, void *unused1, void *unused2)
        struct rx_peer **peer_ptr, **peer_end;
        int code;
        MUTEX_ENTER(&rx_rpc_stats);
-       MUTEX_ENTER(&rx_peerHashTable_lock);
+       RWLOCK_RDLOCK(&rx_peerHashTable_lock);
        for (peer_ptr = &rx_peerHashTable[0], peer_end =
             &rx_peerHashTable[rx_hashTableSize]; peer_ptr < peer_end;
             peer_ptr++) {
@@ -6090,13 +6037,14 @@ rxi_ReapConnections(struct rxevent *unused, void *unused1, void *unused2)
                        rxi_Free(rpc_stat, space);
                        rxi_rpc_peer_stat_cnt -= num_funcs;
                    }
-                   rxi_FreePeer(peer);
                     rx_MutexDecrement(rx_stats.nPeerStructs, rx_stats_mutex);
+                   RWLOCK_UPLOCK(&rx_peerHashTable_lock);
                    if (peer == *peer_ptr) {
                        *peer_ptr = next;
                        prev = next;
                    } else
                        prev->next = next;
+                   rxi_FreePeer(peer);
                } else {
                    if (code) {
                        MUTEX_EXIT(&peer->peer_lock);
@@ -6105,7 +6053,7 @@ rxi_ReapConnections(struct rxevent *unused, void *unused1, void *unused2)
                }
            }
        }
-       MUTEX_EXIT(&rx_peerHashTable_lock);
+       RWLOCK_UNLOCK(&rx_peerHashTable_lock);
        MUTEX_EXIT(&rx_rpc_stats);
     }
 
@@ -6676,7 +6624,6 @@ rx_GetServerStats(osi_socket socket, afs_uint32 remoteAddr,
 {
     struct rx_debugIn in;
     afs_int32 *lp = (afs_int32 *) stat;
-    int i;
     afs_int32 rc = 0;
 
     /*
@@ -6920,7 +6867,7 @@ shutdown_rx(void)
                for (queue_Scan
                     (&peer->rpcStats, rpc_stat, nrpc_stat,
                      rx_interface_stat)) {
-                   unsigned int num_funcs;
+                   int num_funcs;
                    if (!rpc_stat)
                        break;
                    queue_Remove(&rpc_stat->queue_header);
@@ -6932,9 +6879,7 @@ shutdown_rx(void)
                        sizeof(rx_function_entry_v1_t);
 
                    rxi_Free(rpc_stat, space);
-                   MUTEX_ENTER(&rx_rpc_stats);
-                   rxi_rpc_peer_stat_cnt -= num_funcs;
-                   MUTEX_EXIT(&rx_rpc_stats);
+                   rx_MutexAdd(rxi_rpc_peer_stat_cnt, -num_funcs, rx_rpc_stats);
                }
                next = peer->next;
                rxi_FreePeer(peer);
@@ -6948,7 +6893,7 @@ shutdown_rx(void)
     }
     for (i = 0; i < rx_hashTableSize; i++) {
        register struct rx_connection *tc, *ntc;
-       MUTEX_ENTER(&rx_connHashTable_lock);
+       RWLOCK_RDLOCK(&rx_connHashTable_lock);
        for (tc = rx_connHashTable[i]; tc; tc = ntc) {
            ntc = tc->next;
            for (j = 0; j < RX_MAXCALLS; j++) {
@@ -6958,7 +6903,7 @@ shutdown_rx(void)
            }
            rxi_Free(tc, sizeof(*tc));
        }
-       MUTEX_EXIT(&rx_connHashTable_lock);
+       RWLOCK_UNLOCK(&rx_connHashTable_lock);
     }
 
     MUTEX_ENTER(&freeSQEList_lock);
@@ -6972,8 +6917,8 @@ shutdown_rx(void)
     MUTEX_EXIT(&freeSQEList_lock);
     MUTEX_DESTROY(&freeSQEList_lock);
     MUTEX_DESTROY(&rx_freeCallQueue_lock);
-    MUTEX_DESTROY(&rx_connHashTable_lock);
-    MUTEX_DESTROY(&rx_peerHashTable_lock);
+    RWLOCK_DESTROY(&rx_connHashTable_lock);
+    RWLOCK_DESTROY(&rx_peerHashTable_lock);
     MUTEX_DESTROY(&rx_serverPool_lock);
 
     osi_Free(rx_connHashTable,
@@ -7743,7 +7688,7 @@ rx_disablePeerRPCStats(void)
        rx_enable_stats = 0;
     }
 
-    MUTEX_ENTER(&rx_peerHashTable_lock);
+    RWLOCK_RDLOCK(&rx_peerHashTable_lock);
     for (peer_ptr = &rx_peerHashTable[0], peer_end =
         &rx_peerHashTable[rx_hashTableSize]; peer_ptr < peer_end;
         peer_ptr++) {
@@ -7782,7 +7727,7 @@ rx_disablePeerRPCStats(void)
            }
        }
     }
-    MUTEX_EXIT(&rx_peerHashTable_lock);
+    RWLOCK_UNLOCK(&rx_peerHashTable_lock);
     MUTEX_EXIT(&rx_rpc_stats);
 }
 
index 2828f55..d100ffe 100644 (file)
@@ -64,7 +64,6 @@
 #endif
 #endif /* KERNEL */
 
-
 /* Configurable parameters */
 #define        RX_IDLE_DEAD_TIME       60      /* default idle dead time */
 #define        RX_MAX_SERVICES         20      /* Maximum number of services that may be installed */
@@ -258,6 +257,7 @@ struct rx_connection {
     afs_uint32 callNumber[RX_MAXCALLS];        /* Current call numbers */
     afs_uint32 rwind[RX_MAXCALLS];
     u_short twind[RX_MAXCALLS];
+    u_short serviceId;         /* To stamp on requests (clients only) */
     afs_uint32 serial;         /* Next outgoing packet serial number */
     afs_uint32 lastSerial;     /* # of last packet received, for computing skew */
     afs_int32 maxSerial;       /* largest serial number seen on incoming packets */
@@ -269,7 +269,6 @@ struct rx_connection {
     int abortCount;            /* count of abort messages sent */
     /* client-- to retransmit the challenge */
     struct rx_service *service;        /* used by servers only */
-    u_short serviceId;         /* To stamp on requests (clients only) */
     afs_uint32 refCount;               /* Reference count */
     u_char flags;              /* Defined below */
     u_char type;               /* Type of connection, defined below */
@@ -287,7 +286,8 @@ struct rx_connection {
     u_short hardDeadTime;      /* hard max for call execution */
     u_short idleDeadTime;      /* max time a call can be idle (no data) */
     u_char ackRate;            /* how many packets between ack requests */
-    u_char makeCallWaiters;    /* how many rx_NewCalls are waiting */
+    u_char spareb;
+    afs_int32 makeCallWaiters; /* how many rx_NewCalls are waiting */
     afs_int32 idleDeadErr;
     int nSpecific;             /* number entries in specific data */
     void **specific;           /* pointer to connection specific data */
@@ -1079,59 +1079,6 @@ typedef struct rx_interface_stat {
 
 #define RX_STATS_SERVICE_ID 409
 
-#ifdef AFS_NT40_ENV
-#define rx_MutexIncrement(object, mutex) InterlockedIncrement(&object)
-#define rx_MutexAdd(object, addend, mutex) InterlockedAdd(&object, addend)
-#define rx_MutexDecrement(object, mutex) InterlockedDecrement(&object)
-#define rx_MutexAdd1Increment2(object1, addend, object2, mutex) \
-    do { \
-        MUTEX_ENTER(&mutex); \
-        object1 += addend; \
-        InterlockedIncrement(&object2); \
-        MUTEX_EXIT(&mutex); \
-    } while (0)
-#define rx_MutexAdd1Decrement2(object1, addend, object2, mutex) \
-    do { \
-        MUTEX_ENTER(&mutex); \
-        object1 += addend; \
-        InterlockedDecrement(&object2); \
-        MUTEX_EXIT(&mutex); \
-    } while (0)
-#else
-#define rx_MutexIncrement(object, mutex) \
-    do { \
-        MUTEX_ENTER(&mutex); \
-        object++; \
-        MUTEX_EXIT(&mutex); \
-    } while(0)
-#define rx_MutexAdd(object, addend, mutex) \
-    do { \
-        MUTEX_ENTER(&mutex); \
-        object += addend; \
-        MUTEX_EXIT(&mutex); \
-    } while(0)
-#define rx_MutexAdd1Increment2(object1, addend, object2, mutex) \
-    do { \
-        MUTEX_ENTER(&mutex); \
-        object1 += addend; \
-        object2++; \
-        MUTEX_EXIT(&mutex); \
-    } while(0)
-#define rx_MutexAdd1Decrement2(object1, addend, object2, mutex) \
-    do { \
-        MUTEX_ENTER(&mutex); \
-        object1 += addend; \
-        object2--; \
-        MUTEX_EXIT(&mutex); \
-    } while(0)
-#define rx_MutexDecrement(object, mutex) \
-    do { \
-        MUTEX_ENTER(&mutex); \
-        object--; \
-        MUTEX_EXIT(&mutex); \
-    } while(0)
-#endif 
-
 #endif /* _RX_   End of rx.h */
 
 #ifdef KERNEL
index 9d7ca30..348cfc5 100644 (file)
@@ -32,6 +32,7 @@ RCSID
 #else /* !UKERNEL */
 #include "afs/sysincludes.h"
 #include "afsincludes.h"
+#include "rx/rx_internal.h"
 #include "rx/rx.h"
 #include "rx/rx_clock.h"
 #endif /* !UKERNEL */
@@ -43,6 +44,7 @@ RCSID
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
+#include "rx_internal.h"
 #include "rx.h"
 #include "rx_clock.h"
 #endif
index 4754194..5af237b 100644 (file)
@@ -24,11 +24,13 @@ RCSID
 #ifdef UKERNEL
 #include "afs/sysincludes.h"
 #include "afsincludes.h"
+#include "rx/rx_internal.h"
 #include "rx/rx.h"
 #else /* ! UKERNEL */
 #include <sys/types.h>
 #include <errno.h>
 #include <assert.h>
+#include "rx_internal.h"
 #include "rx.h"
 #endif /* UKERNEL */
 
index bcdba29..594b2ce 100644 (file)
@@ -34,6 +34,7 @@ RCSID
 #include "rx/rx_kernel.h"
 #include "rx_kmutex.h"
 #ifdef RX_ENABLE_LOCKS
+#include "rx/rx_internal.h"
 #include "rx/rx.h"
 #endif /* RX_ENABLE_LOCKS */
 #include "rx/rx_globals.h"
@@ -61,6 +62,7 @@ extern void *osi_Alloc();
 #include "rx_lwp.h"
 #endif
 #ifdef RX_ENABLE_LOCKS
+#include "rx_internal.h"
 #include "rx.h"
 #endif /* RX_ENABLE_LOCKS */
 #include "rx_globals.h"
index 57740e9..c1475a8 100644 (file)
@@ -32,6 +32,7 @@ RCSID
  * By including this, we get any system dependencies. In particular,
  * the pthreads for solaris requires the socket call to be mapped.
  */
+#include "rx_internal.h"
 #include "rx.h"
 #include "rx_globals.h"
 #endif /* AFS_NT40_ENV */
@@ -39,6 +40,7 @@ RCSID
 #ifdef UKERNEL
 #include "rx/rx_kcommon.h"
 #else /* UKERNEL */
+#include "rx/rx_internal.h"
 #include "rx/rx.h"
 #endif /* UKERNEL */
 #endif /* KERNEL */
index 3e021bd..74c9e5f 100644 (file)
@@ -521,8 +521,8 @@ EXT struct rx_connection **rx_connHashTable;
 EXT struct rx_connection *rx_connCleanup_list GLOBALSINIT(0);
 EXT afs_uint32 rx_hashTableSize GLOBALSINIT(257);      /* Prime number */
 #ifdef RX_ENABLE_LOCKS
-EXT afs_kmutex_t rx_peerHashTable_lock;
-EXT afs_kmutex_t rx_connHashTable_lock;
+EXT afs_krwlock_t rx_peerHashTable_lock;
+EXT afs_krwlock_t rx_connHashTable_lock;
 #endif /* RX_ENABLE_LOCKS */
 
 #define CONN_HASH(host, port, cid, epoch, type) ((((cid)>>RX_CIDSHIFT)%rx_hashTableSize))
index cb95457..b582e68 100644 (file)
 /*
- * 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
+ * Copyright (c) 2008, Your File System, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without 
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, 
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright 
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the company nor the names of its contributors may 
+ *    be used to endorse or promote products derived from this software 
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-/* Remove this file */
+#ifndef        _RX_INTERNAL_H_
+#define _RX_INTERNAL_H_
+
+#ifdef AFS_NT40_ENV
+#ifndef _WIN64
+#ifndef __cplusplus
+#include <intrin.h>
+#pragma intrinsic(_InterlockedOr)
+#pragma intrinsic(_InterlockedAnd)
+#define rx_MutexOr(object, operand, mutex) _InterlockedOr(&object, operand)
+#define rx_MutexAnd(object, operand, mutex) _InterlockedAnd(&object, operand)
+#endif
+#else
+#define rx_MutexOr(object, operand, mutex) InterlockedOr(&object, operand)
+#define rx_MutexAnd(object, operand, mutex) InterlockedAnd(&object, operand)
+#endif
+#define rx_MutexIncrement(object, mutex) InterlockedIncrement(&object)
+#define rx_MutexXor(object, operand, mutex) InterlockedXor(&object, operand)
+#define rx_MutexAdd(object, addend, mutex) InterlockedExchangeAdd(&object, addend)
+#define rx_MutexDecrement(object, mutex) InterlockedDecrement(&object)
+#define rx_MutexAdd1Increment2(object1, addend, object2, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object1 += addend; \
+        InterlockedIncrement(&object2); \
+        MUTEX_EXIT(&mutex); \
+    } while (0)
+#define rx_MutexAdd1Decrement2(object1, addend, object2, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object1 += addend; \
+        InterlockedDecrement(&object2); \
+        MUTEX_EXIT(&mutex); \
+    } while (0)
+#else
+#define rx_MutexIncrement(object, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object++; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#define rx_MutexOr(object, operand, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object |= operand; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#define rx_MutexAnd(object, operand, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object &= operand; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#define rx_MutexXor(object, operand, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object ^= operand; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#define rx_MutexAdd(object, addend, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object += addend; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#define rx_MutexAdd1Increment2(object1, addend, object2, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object1 += addend; \
+        object2++; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#define rx_MutexAdd1Decrement2(object1, addend, object2, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object1 += addend; \
+        object2--; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#define rx_MutexDecrement(object, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object--; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#endif 
+
+#endif /* _RX_INTERNAL_H */
index 4585560..bef6846 100644 (file)
@@ -44,6 +44,7 @@ RCSID
 # include <sys/ioctl.h>
 # include <sys/time.h>
 #endif
+# include "rx_internal.h"
 # include "rx.h"
 # include "rx_globals.h"
 # include <lwp.h>
index 3b4fe46..bfeaa03 100644 (file)
 #define MUTEX_ISMINE(a)
 #define CV_INIT(a,b,c,d)
 #define CV_DESTROY(a)
+#define RWLOCK_INIT(a, b, c, d) 
+#define RWLOCK_DESTROY(l) 
+#define RWLOCK_UPLOCK(l) 
+#define RWLOCK_WRLOCK(l) 
+#define RWLOCK_RDLOCK(l) 
+#define RWLOCK_TRYWRLOCK(l) 1
+#define RWLOCK_TRYRDLOCK(l) 1
+#define RWLOCK_UNLOCK(l) 
 #define osirx_AssertMine(a, b)
 
 #endif /* KERNEL */
index d9b1301..2800658 100644 (file)
@@ -27,6 +27,7 @@ RCSID
 #include <afs/errors.h>
 #include "xdr.h"
 #ifdef AFS_PTHREAD_ENV
+#include "rx_internal.h"
 #include "rx.h"
 #endif /* AFS_PTHREAD_ENV */
 #include <stdlib.h>
index b8b3f36..d15fc92 100644 (file)
@@ -15,8 +15,10 @@ RCSID
 
 #ifdef KERNEL
 #include "afs/sysincludes.h"
+#include "rx/rx_internal.h"
 #include "rx/rx.h"
 #else /* KERNEL */
+# include "rx_internal.h"
 # include "rx.h"
 #endif /* KERNEL */
 
index d8ff2c1..2add44f 100644 (file)
@@ -23,8 +23,10 @@ RCSID
 #else /* !UKERNEL */
 #include "afs/sysincludes.h"
 #endif /* !UKERNEL */
+#include "rx/rx_internal.h"
 #include "rx/rx.h"
 #else /* KERNEL */
+#include "rx_internal.h"
 #include "rx.h"
 #endif /* KERNEL */
 
index 686a52e..8701567 100644 (file)
@@ -79,6 +79,7 @@ RCSID
 #include <netinet/in.h>
 #endif
 #include "rx_clock.h"
+#include "rx_internal.h"
 #include "rx.h"
 #include "rx_queue.h"
 #ifdef AFS_SUN5_ENV
@@ -1833,7 +1834,7 @@ rxi_ReceiveDebugPacket(register struct rx_packet *ap, osi_socket asocket,
                (void)IOMGR_Poll();
 #endif
 #endif
-               MUTEX_ENTER(&rx_connHashTable_lock);
+               RWLOCK_RDLOCK(&rx_connHashTable_lock);
                /* We might be slightly out of step since we are not 
                 * locking each call, but this is only debugging output.
                 */
@@ -1886,8 +1887,8 @@ rxi_ReceiveDebugPacket(register struct rx_packet *ap, osi_socket asocket,
                                 sizeof(afs_int32); i++)
                                DOHTONL(sparel[i]);
                        }
-
-                       MUTEX_EXIT(&rx_connHashTable_lock);
+                       
+                       RWLOCK_UNLOCK(&rx_connHashTable_lock);
                        rx_packetwrite(ap, 0, sizeof(struct rx_debugConn),
                                       (char *)&tconn);
                        tl = ap->length;
@@ -1898,7 +1899,7 @@ rxi_ReceiveDebugPacket(register struct rx_packet *ap, osi_socket asocket,
                        return ap;
                    }
                }
-               MUTEX_EXIT(&rx_connHashTable_lock);
+               RWLOCK_UNLOCK(&rx_connHashTable_lock);
            }
            /* if we make it here, there are no interesting packets */
            tconn.cid = htonl(0xffffffff);      /* means end */
@@ -1945,7 +1946,8 @@ rxi_ReceiveDebugPacket(register struct rx_packet *ap, osi_socket asocket,
                (void)IOMGR_Poll();
 #endif
 #endif
-               MUTEX_ENTER(&rx_peerHashTable_lock);
+               RWLOCK_RDLOCK(&rx_peerHashTable_lock);
+               /* XXX should copy out, then unlock and byteswap */
                for (tp = rx_peerHashTable[i]; tp; tp = tp->next) {
                    if (tin.index-- <= 0) {
                        tpeer.host = tp->host;
@@ -1981,7 +1983,7 @@ rxi_ReceiveDebugPacket(register struct rx_packet *ap, osi_socket asocket,
                        tpeer.bytesReceived.low =
                            htonl(tp->bytesReceived.low);
 
-                       MUTEX_EXIT(&rx_peerHashTable_lock);
+                       RWLOCK_UNLOCK(&rx_peerHashTable_lock);
                        rx_packetwrite(ap, 0, sizeof(struct rx_debugPeer),
                                       (char *)&tpeer);
                        tl = ap->length;
@@ -1992,7 +1994,7 @@ rxi_ReceiveDebugPacket(register struct rx_packet *ap, osi_socket asocket,
                        return ap;
                    }
                }
-               MUTEX_EXIT(&rx_peerHashTable_lock);
+               RWLOCK_UNLOCK(&rx_peerHashTable_lock);
            }
            /* if we make it here, there are no interesting packets */
            tpeer.host = htonl(0xffffffff);     /* means end */
index 69857ea..a717885 100644 (file)
@@ -35,6 +35,7 @@ RCSID
 # include <sys/time.h>
 #endif
 #include <sys/stat.h>
+#include "rx_internal.h"
 #include <rx/rx.h>
 #include <rx/rx_globals.h>
 #include <assert.h>
@@ -357,9 +358,7 @@ rxi_StartListener(void)
        dpf(("Unable to create Rx event handling thread\n"));
        exit(1);
     }
-    MUTEX_ENTER(&rx_stats_mutex);
-    ++rxi_pthread_hinum;
-    MUTEX_EXIT(&rx_stats_mutex);
+    rx_MutexIncrement(rxi_pthread_hinum, rx_stats_mutex);
     AFS_SIGSET_RESTORE();
 
     assert(pthread_mutex_lock(&listener_mutex) == 0);
@@ -396,9 +395,7 @@ rxi_Listen(osi_socket sock)
        dpf(("Unable to create socket listener thread\n"));
        exit(1);
     }
-    MUTEX_ENTER(&rx_stats_mutex);
-    ++rxi_pthread_hinum;
-    MUTEX_EXIT(&rx_stats_mutex);
+    rx_MutexIncrement(rxi_pthread_hinum, rx_stats_mutex);
     AFS_SIGSET_RESTORE();
     return 0;
 }
index ff53183..c28dccd 100644 (file)
@@ -33,6 +33,7 @@
 #include <pthread.h>
 
 typedef pthread_mutex_t afs_kmutex_t;
+typedef pthread_rwlock_t afs_krwlock_t;
 typedef pthread_cond_t afs_kcondvar_t;
 #ifdef RX_ENABLE_LOCKS
 #define MUTEX_ISMINE(l) (pthread_mutex_trylock(l) == EDEADLK)
@@ -46,6 +47,7 @@ typedef pthread_cond_t afs_kcondvar_t;
 
 #include <pthread.h>
 typedef pthread_mutex_t afs_kmutex_t;
+typedef pthread_rwlock_t afs_krwlock_t;
 typedef pthread_cond_t afs_kcondvar_t;
 
 #if !defined(pthread_yield) && defined(AFS_SUN5_ENV)
@@ -74,6 +76,10 @@ typedef pthread_cond_t afs_kcondvar_t;
 extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
 
 #ifdef AFS_PTHREAD_ENV
+#if !defined(PTHREAD_RWLOCK_INITIALIZER) && defined(AFS_DARWIN80_ENV)
+#define PTHREAD_RWLOCK_INITIALIZER {0x2DA8B3B4, {0}}
+#endif
+
 #ifdef MUTEX_INIT
 #undef MUTEX_INIT
 #endif
@@ -124,6 +130,46 @@ extern void osirx_AssertMine(afs_kmutex_t * lockaddr, char *msg);
 #endif
 #define CV_BROADCAST(cv) osi_Assert(pthread_cond_broadcast(cv) == 0)
 
+#ifdef RWLOCK_INIT
+#undef RWLOCK_INIT
+#endif
+#define RWLOCK_INIT(a, b, c, d) osi_Assert(pthread_rwlock_init(a, NULL) == 0)
+
+#ifdef RWLOCK_DESTROY
+#undef RWLOCK_DESTROY
+#endif
+#define RWLOCK_DESTROY(l) osi_Assert(pthread_rwlock_destroy(l) == 0)
+
+#ifdef RWLOCK_UPLOCK
+#undef RWLOCK_UPLOCK
+#endif
+#define RWLOCK_UPLOCK(l) do {osi_Assert(pthread_rwlock_unlock(l) == 0); osi_Assert(pthread_rwlock_wrlock(l) == 0);} while (0)
+
+#ifdef RWLOCK_WRLOCK
+#undef RWLOCK_WRLOCK
+#endif
+#define RWLOCK_WRLOCK(l) osi_Assert(pthread_rwlock_wrlock(l) == 0)
+
+#ifdef RWLOCK_RDLOCK
+#undef RWLOCK_RDLOCK
+#endif
+#define RWLOCK_RDLOCK(l) osi_Assert(pthread_rwlock_rdlock(l) == 0)
+
+#ifdef RWLOCK_TRYWRLOCK
+#undef RWLOCK_TRYWRLOCK
+#endif
+#define RWLOCK_TRYWRLOCK(l) pthread_rwlock_trywrlock(l) ? 0 : 1
+
+#ifdef RWLOCK_TRYRDLOCK
+#undef RWLOCK_TRYRDLOCK
+#endif
+#define RWLOCK_TRYRDLOCK(l) pthread_rwlock_tryrdlock(l) ? 0 : 1
+
+#ifdef RWLOCK_UNLOCK
+#undef RWLOCK_UNLOCK
+#endif
+#define RWLOCK_UNLOCK(l) osi_Assert(pthread_rwlock_unlock(l) == 0)
+
 #endif /* AFS_PTHREAD_ENV */
 
 
index e3aac08..59828fb 100644 (file)
@@ -58,6 +58,7 @@ RCSID
 #include "rx/rx_kernel.h"
 #include "rx/rx_clock.h"
 #include "rx/rx_queue.h"
+#include "rx/rx_internal.h"
 #include "rx/rx.h"
 #include "rx/rx_globals.h"
 #include "afs/lock.h"
@@ -88,6 +89,7 @@ RCSID
 # include "rx_user.h"
 # include "rx_clock.h"
 # include "rx_queue.h"
+# include "rx_internal.h"
 # include "rx.h"
 # include "rx_globals.h"
 #endif /* KERNEL */
index 79c6274..c61adf0 100644 (file)
@@ -22,6 +22,7 @@ RCSID
 #include <sys/file.h>
 #include <unistd.h>
 #endif
+#include "rx_internal.h"
 #include "rx.h"
 #include "rx_globals.h"
 #include "rx_trace.h"
index 9facb6c..4537559 100644 (file)
@@ -48,6 +48,7 @@ RCSID
 #ifndef AFS_NT40_ENV
 # include <sys/time.h>
 #endif
+# include "rx_internal.h"
 # include "rx.h"
 # include "rx_globals.h"
 
index 63b02a6..12fec94 100644 (file)
@@ -24,6 +24,7 @@ RCSID
 
 #include <winsock2.h>
 
+#include "rx_internal.h"
 #include "rx.h"
 #include "rx_packet.h"
 #include "rx_globals.h"
index 54011e6..b2779db 100644 (file)
@@ -59,6 +59,7 @@ RCSID
 #include <stdio.h>
 #endif
 #include "xdr.h"
+#include "rx_internal.h"
 #include "rx.h"
 
 /*
index 03d8947..ff7183b 100644 (file)
@@ -28,6 +28,7 @@
  */
 #include <afsconfig.h>
 #include <afs/param.h>
+#include "rx_internal.h"
 #include "rx.h"
 
 RCSID
index 933def0..1485bbe 100644 (file)
@@ -28,6 +28,7 @@
  */
 #include <afsconfig.h>
 #include <afs/param.h>
+#include "rx_internal.h"
 #include "rx.h"
 
 RCSID
index 4f2a425..79e2d36 100644 (file)
@@ -53,6 +53,7 @@ RCSID
 #include "rpc/types.h"
 #include "rpc/xdr.h"
 #endif /* !UKERNEL */
+#include "rx/rx_internal.h"
 #include "rx/rx.h"
 
 #else /* KERNEL */
@@ -61,6 +62,7 @@ RCSID
 #ifndef AFS_NT40_ENV
 #include <netinet/in.h>
 #endif
+#include "rx_internal.h"
 #include "rx.h"
 #include "xdr.h"
 #endif /* KERNEL */