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"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
17 #include "afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h" /* statistics */
20 static struct axscache *afs_axsfreelist = NULL;
21 static struct xfreelist {
22 struct xfreelist *next;
24 static int afs_xaxscnt = 0;
25 afs_rwlock_t afs_xaxs;
27 /* takes an address of an access cache & uid, returns ptr */
28 /* PRECONDITION: first field has been checked and doesn't match!
29 * INVARIANT: isparent(i,j) ^ isparent(j,i) (ie, they switch around)
32 afs_SlowFindAxs(struct axscache **cachep, afs_int32 id)
34 register struct axscache *i, *j;
40 axs_Front(cachep, j, i); /* maintain LRU queue */
44 if ((j = i->next)) { /* ASSIGNMENT HERE! */
46 axs_Front(cachep, i, j);
50 return ((struct axscache *)NULL);
53 return ((struct axscache *)NULL);
57 #define NAXSs (1000 / sizeof(struct axscache))
61 register struct axscache *i, *j, *xsp;
65 ObtainWriteLock(&afs_xaxs, 174);
66 if ((h = afs_axsfreelist)) {
67 afs_axsfreelist = h->next;
70 (struct axscache *)afs_osi_Alloc(NAXSs * sizeof(struct axscache));
72 xsp = (struct axscache *)xfreemallocs;
73 xfreemallocs = (struct xfreelist *)h;
74 xfreemallocs->next = (struct xfreelist *)xsp;
75 for (k = 0; k < NAXSs - 1; k++, i++) {
78 i->next = ++j; /* need j because order of evaluation not defined */
83 afs_axsfreelist = h->next;
85 ReleaseWriteLock(&afs_xaxs);
90 #define axs_Free(axsp) { \
91 ObtainWriteLock(&afs_xaxs,175); \
92 axsp->next = afs_axsfreelist; \
93 afs_axsfreelist = axsp; \
94 ReleaseWriteLock(&afs_xaxs); \
98 /* I optimize for speed on lookup, and don't give a RIP about delete.
101 afs_RemoveAxs(struct axscache **headp, struct axscache *axsp)
103 struct axscache *i, *j;
105 if (*headp && axsp) { /* is bullet-proofing really neccessary? */
106 if (*headp == axsp) { /* most common case, I think */
121 if ((i = j->next)) { /* ASSIGNMENT HERE! */
128 /* end of "if neither pointer is NULL" */
129 return; /* !#@ FAILED to find it! */
134 * Takes an entire list of access cache structs and prepends them, lock, stock,
135 * and barrel, to the front of the freelist.
138 afs_FreeAllAxs(struct axscache **headp)
140 struct axscache *i, *j;
145 while (i) { /* chase down the list 'til we reach the end */
148 ObtainWriteLock(&afs_xaxs, 176);
149 i->next = afs_axsfreelist; /* tack on the freelist to the end */
150 afs_axsfreelist = *headp;
151 ReleaseWriteLock(&afs_xaxs);
158 if (j) { /* we ran off the end of the list... */
159 ObtainWriteLock(&afs_xaxs, 177);
160 j->next = afs_axsfreelist; /* tack on the freelist to the end */
161 afs_axsfreelist = *headp;
162 ReleaseWriteLock(&afs_xaxs);
169 /* doesn't appear to be used at all */
172 shutdown_xscache(void)
174 struct xfreelist *xp, *nxp;
176 RWLOCK_INIT(&afs_xaxs, "afs_xaxs");
180 afs_osi_Free((char *)xp, NAXSs * sizeof(struct axscache));
183 afs_axsfreelist = NULL;