2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
17 #include "afs/sysincludes.h"
24 * multi.c and multi.h, together with some rxgen hooks, provide a way of
25 * making multiple, but similar, rx calls to multiple hosts simultaneously
29 multi_Init(struct rx_connection **conns, register int nConns)
31 register struct rx_call **calls;
32 register short *ready;
33 register struct multi_handle *mh;
37 * Note: all structures that are possibly referenced by other
38 * processes must be allocated. In some kernels variables allocated on
39 * a process stack will not be accessible to other processes
42 calls = (struct rx_call **)osi_Alloc(sizeof(struct rx_call *) * nConns);
43 ready = (short *)osi_Alloc(sizeof(short *) * nConns);
44 mh = (struct multi_handle *)osi_Alloc(sizeof(struct multi_handle));
45 if (!calls || !ready || !mh)
46 osi_Panic("multi_Rx: no mem\n");
48 mh->nextReady = mh->firstNotReady = mh->ready = ready;
51 #ifdef RX_ENABLE_LOCKS
52 MUTEX_INIT(&mh->lock, "rx_multi_lock", MUTEX_DEFAULT, 0);
53 CV_INIT(&mh->cv, "rx_multi_cv", CV_DEFAULT, 0);
54 #endif /* RX_ENABLE_LOCKS */
55 for (i = 0; i < nConns; i++) {
56 register struct rx_call *call;
57 call = mh->calls[i] = rx_NewCall(conns[i]);
58 rx_SetArrivalProc(call, multi_Ready, (void *) mh, i);
63 /* Return the user's connection index of the most recently ready call; that is, a call that has received at least one reply packet */
65 multi_Select(register struct multi_handle *mh)
70 #ifdef RX_ENABLE_LOCKS
71 MUTEX_ENTER(&mh->lock);
72 #endif /* RX_ENABLE_LOCKS */
73 while (mh->nextReady == mh->firstNotReady) {
74 if (mh->nReady == mh->nConns) {
75 #ifdef RX_ENABLE_LOCKS
76 MUTEX_EXIT(&mh->lock);
77 #endif /* RX_ENABLE_LOCKS */
81 #ifdef RX_ENABLE_LOCKS
82 CV_WAIT(&mh->cv, &mh->lock);
83 #else /* RX_ENABLE_LOCKS */
85 #endif /* RX_ENABLE_LOCKS */
87 index = *(mh->nextReady);
89 #ifdef RX_ENABLE_LOCKS
90 MUTEX_EXIT(&mh->lock);
91 #endif /* RX_ENABLE_LOCKS */
96 /* Called by Rx when the first reply packet of a call is received, or the call is aborted. */
98 multi_Ready(register struct rx_call *call, register void *amh,
101 register struct multi_handle *mh = (struct multi_handle *)amh;
102 #ifdef RX_ENABLE_LOCKS
103 MUTEX_ENTER(&mh->lock);
104 #endif /* RX_ENABLE_LOCKS */
105 *mh->firstNotReady++ = index;
107 #ifdef RX_ENABLE_LOCKS
109 MUTEX_EXIT(&mh->lock);
110 #else /* RX_ENABLE_LOCKS */
112 #endif /* RX_ENABLE_LOCKS */
115 /* Called when the multi rx call is over, or when the user aborts it (by using the macro multi_Abort) */
117 multi_Finalize(register struct multi_handle *mh)
120 register int nCalls = mh->nConns;
121 for (i = 0; i < nCalls; i++) {
122 register struct rx_call *call = mh->calls[i];
124 rx_EndCall(call, RX_USER_ABORT);
126 #ifdef RX_ENABLE_LOCKS
127 MUTEX_DESTROY(&mh->lock);
129 #endif /* RX_ENABLE_LOCKS */
130 osi_Free(mh->calls, sizeof(struct rx_call *) * nCalls);
131 osi_Free(mh->ready, sizeof(short *) * nCalls);
132 osi_Free(mh, sizeof(struct multi_handle));
135 /* ignores all remaining multiRx calls */
137 multi_Finalize_Ignore(register struct multi_handle *mh)
140 register int nCalls = mh->nConns;
141 for (i = 0; i < nCalls; i++) {
142 register struct rx_call *call = mh->calls[i];
146 #ifdef RX_ENABLE_LOCKS
147 MUTEX_DESTROY(&mh->lock);
149 #endif /* RX_ENABLE_LOCKS */
150 osi_Free(mh->calls, sizeof(struct rx_call *) * nCalls);
151 osi_Free(mh->ready, sizeof(short *) * nCalls);
152 osi_Free(mh, sizeof(struct multi_handle));