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"
15 #include "afs/sysincludes.h" /* Standard vendor system headers */
16 #include "afsincludes.h" /* Afs-based standard headers */
17 #include "afs/afs_stats.h" /* statistics */
19 static struct axscache *afs_axsfreelist = NULL;
20 static struct xfreelist { struct xfreelist *next; } *xfreemallocs = 0;
21 static int afs_xaxscnt = 0;
22 afs_rwlock_t afs_xaxs;
24 /* takes an address of an access cache & uid, returns ptr */
25 /* PRECONDITION: first field has been checked and doesn't match!
26 * INVARIANT: isparent(i,j) ^ isparent(j,i) (ie, they switch around)
28 struct axscache *afs_SlowFindAxs(struct axscache **cachep, afs_int32 id)
30 register struct axscache *i,*j;
36 axs_Front(cachep,j,i); /* maintain LRU queue */
40 if ((j=i->next)) { /* ASSIGNMENT HERE! */
42 axs_Front(cachep,i,j);
46 return ((struct axscache *) NULL);
49 return ((struct axscache *) NULL);
53 #define NAXSs (1000 / sizeof(struct axscache))
54 struct axscache *axs_Alloc(void)
56 register struct axscache *i, *j, *xsp;
60 ObtainWriteLock(&afs_xaxs,174);
61 if ((h = afs_axsfreelist)) {
62 afs_axsfreelist = h->next;
64 h=i=j= (struct axscache *) afs_osi_Alloc(NAXSs * sizeof(struct axscache));
66 xsp = (struct axscache *)xfreemallocs;
67 xfreemallocs = (struct xfreelist *)h;
68 xfreemallocs->next = (struct xfreelist *)xsp;
69 for (k = 0; k < NAXSs-1; k++, i++) {
72 i->next = ++j; /* need j because order of evaluation not defined */
77 afs_axsfreelist = h->next;
79 ReleaseWriteLock(&afs_xaxs);
84 #define axs_Free(axsp) { \
85 ObtainWriteLock(&afs_xaxs,175); \
86 axsp->next = afs_axsfreelist; \
87 afs_axsfreelist = axsp; \
88 ReleaseWriteLock(&afs_xaxs); \
92 /* I optimize for speed on lookup, and don't give a RIP about delete.
94 void afs_RemoveAxs(struct axscache **headp, struct axscache *axsp)
96 struct axscache *i, *j;
98 if (*headp && axsp) { /* is bullet-proofing really neccessary? */
99 if (*headp == axsp) { /* most common case, I think */
114 if ((i = j->next)) { /* ASSIGNMENT HERE! */
120 } /* end of "if neither pointer is NULL" */
122 return; /* !#@ FAILED to find it! */
127 * Takes an entire list of access cache structs and prepends them, lock, stock,
128 * and barrel, to the front of the freelist.
130 void afs_FreeAllAxs(struct axscache **headp)
132 struct axscache *i,*j;
137 while (i) { /* chase down the list 'til we reach the end */
140 ObtainWriteLock (&afs_xaxs,176);
141 i->next = afs_axsfreelist; /* tack on the freelist to the end */
142 afs_axsfreelist = *headp;
143 ReleaseWriteLock (&afs_xaxs);
150 if (j) { /* we ran off the end of the list... */
151 ObtainWriteLock (&afs_xaxs,177);
152 j->next = afs_axsfreelist; /* tack on the freelist to the end */
153 afs_axsfreelist = *headp;
154 ReleaseWriteLock (&afs_xaxs);
161 /* doesn't appear to be used at all */
163 static void shutdown_xscache(void)
165 struct xfreelist *xp, *nxp;
167 RWLOCK_INIT(&afs_xaxs, "afs_xaxs");
171 afs_osi_Free((char *)xp, NAXSs * sizeof(struct axscache));
174 afs_axsfreelist = NULL;