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 "../afs/param.h" /* Should be always first */
11 #include "../afs/sysincludes.h" /* Standard vendor system headers */
12 #include "../afs/afsincludes.h" /* Afs-based standard headers */
13 #include "../afs/afs_stats.h" /* statistics */
15 static struct axscache *afs_axsfreelist = NULL;
16 static struct xfreelist { struct xfreelist *next; } *xfreemallocs = 0, *xsp = 0;
18 afs_rwlock_t afs_xaxs;
20 /* takes an address of an access cache & uid, returns ptr */
21 /* PRECONDITION: first field has been checked and doesn't match!
22 * INVARIANT: isparent(i,j) ^ isparent(j,i) (ie, they switch around)
24 struct axscache *afs_SlowFindAxs(cachep,id)
25 struct axscache **cachep;
28 register struct axscache *i,*j;
34 axs_Front(cachep,j,i); /* maintain LRU queue */
38 if (j=i->next) { /* ASSIGNMENT HERE! */
40 axs_Front(cachep,i,j);
44 return ((struct axscache *) NULL);
47 return ((struct axscache *) NULL);
51 #define NAXSs (1000 / sizeof(struct axscache))
52 struct axscache *axs_Alloc()
54 register struct axscache *i, *j, *xsp;
58 ObtainWriteLock(&afs_xaxs,174);
59 if (h = afs_axsfreelist) {
60 afs_axsfreelist = h->next;
62 h=i=j= (struct axscache *) afs_osi_Alloc(NAXSs * sizeof(struct axscache));
64 xsp = (struct axscache *)xfreemallocs;
65 xfreemallocs = (struct xfreelist *)h;
66 xfreemallocs->next = (struct xfreelist *)xsp;
67 for (k = 0; k < NAXSs-1; k++, i++) {
70 i->next = ++j; /* need j because order of evaluation not defined */
75 afs_axsfreelist = h->next;
77 ReleaseWriteLock(&afs_xaxs);
82 #define axs_Free(axsp) { \
83 ObtainWriteLock(&afs_xaxs,175); \
84 axsp->next = afs_axsfreelist; \
85 afs_axsfreelist = axsp; \
86 ReleaseWriteLock(&afs_xaxs); \
90 /* I optimize for speed on lookup, and don't give a RIP about delete.
92 void afs_RemoveAxs(headp, axsp)
93 struct axscache **headp, *axsp;
95 struct axscache *i, *j;
97 if (*headp && axsp) { /* is bullet-proofing really neccessary? */
98 if (*headp == axsp) { /* most common case, I think */
113 if (i = j->next) { /* ASSIGNMENT HERE! */
119 } /* end of "if neither pointer is NULL" */
121 return; /* !#@ FAILED to find it! */
126 * Takes an entire list of access cache structs and prepends them, lock, stock,
127 * and barrel, to the front of the freelist.
129 void afs_FreeAllAxs(headp)
130 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 void shutdown_xscache()
163 struct xfreelist *xp, *nxp;
165 RWLOCK_INIT(&afs_xaxs, "afs_xaxs");
169 afs_osi_Free((char *)xp, NAXSs * sizeof(struct axscache));
172 afs_axsfreelist = NULL;