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"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
15 #include "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h" /* statistics */
18 static struct axscache *afs_axsfreelist = NULL;
19 static struct xfreelist {
20 struct xfreelist *next;
22 static int afs_xaxscnt = 0;
23 afs_rwlock_t afs_xaxs;
25 /* takes an address of an access cache & uid, returns ptr */
26 /* PRECONDITION: first field has been checked and doesn't match!
27 * INVARIANT: isparent(i,j) ^ isparent(j,i) (ie, they switch around)
30 afs_SlowFindAxs(struct axscache **cachep, afs_int32 id)
32 register struct axscache *i, *j;
38 axs_Front(cachep, j, i); /* maintain LRU queue */
42 if ((j = i->next)) { /* ASSIGNMENT HERE! */
44 axs_Front(cachep, i, j);
48 return ((struct axscache *)NULL);
51 return ((struct axscache *)NULL);
55 #define NAXSs (1000 / sizeof(struct axscache))
59 register struct axscache *i, *j, *xsp;
63 ObtainWriteLock(&afs_xaxs, 174);
64 if ((h = afs_axsfreelist)) {
65 afs_axsfreelist = h->next;
68 (struct axscache *)afs_osi_Alloc(NAXSs * sizeof(struct axscache));
70 xsp = (struct axscache *)xfreemallocs;
71 xfreemallocs = (struct xfreelist *)h;
72 xfreemallocs->next = (struct xfreelist *)xsp;
73 for (k = 0; k < NAXSs - 1; k++, i++) {
76 i->next = ++j; /* need j because order of evaluation not defined */
81 afs_axsfreelist = h->next;
83 ReleaseWriteLock(&afs_xaxs);
88 #define axs_Free(axsp) { \
89 ObtainWriteLock(&afs_xaxs,175); \
90 axsp->next = afs_axsfreelist; \
91 afs_axsfreelist = axsp; \
92 ReleaseWriteLock(&afs_xaxs); \
96 /* I optimize for speed on lookup, and don't give a RIP about delete.
99 afs_RemoveAxs(struct axscache **headp, struct axscache *axsp)
101 struct axscache *i, *j;
103 if (*headp && axsp) { /* is bullet-proofing really neccessary? */
104 if (*headp == axsp) { /* most common case, I think */
119 if ((i = j->next)) { /* ASSIGNMENT HERE! */
126 /* end of "if neither pointer is NULL" */
127 return; /* !#@ FAILED to find it! */
132 * Takes an entire list of access cache structs and prepends them, lock, stock,
133 * and barrel, to the front of the freelist.
136 afs_FreeAllAxs(struct axscache **headp)
138 struct axscache *i, *j;
143 while (i) { /* chase down the list 'til we reach the end */
146 ObtainWriteLock(&afs_xaxs, 176);
147 i->next = afs_axsfreelist; /* tack on the freelist to the end */
148 afs_axsfreelist = *headp;
149 ReleaseWriteLock(&afs_xaxs);
156 if (j) { /* we ran off the end of the list... */
157 ObtainWriteLock(&afs_xaxs, 177);
158 j->next = afs_axsfreelist; /* tack on the freelist to the end */
159 afs_axsfreelist = *headp;
160 ReleaseWriteLock(&afs_xaxs);
167 /* doesn't appear to be used at all */
170 shutdown_xscache(void)
172 struct xfreelist *xp, *nxp;
174 AFS_RWLOCK_INIT(&afs_xaxs, "afs_xaxs");
178 afs_osi_Free((char *)xp, NAXSs * sizeof(struct axscache));
181 afs_axsfreelist = NULL;