Unused variable cleanup
[openafs.git] / src / afs / afs_axscache.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #include <afsconfig.h>
11 #include "afs/param.h"
12
13
14 #include "afs/sysincludes.h"    /* Standard vendor system headers */
15 #include "afsincludes.h"        /* Afs-based standard headers */
16 #include "afs/afs_stats.h"      /* statistics */
17 #include "afs/stds.h"
18 static struct axscache *afs_axsfreelist = NULL;
19 static struct xfreelist {
20     struct xfreelist *next;
21 } *xfreemallocs = 0;
22 static int afs_xaxscnt = 0;
23 afs_rwlock_t afs_xaxs;
24
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)
28  */
29 struct axscache *
30 afs_SlowFindAxs(struct axscache **cachep, afs_int32 id)
31 {
32     register struct axscache *i, *j;
33
34     j = (*cachep);
35     i = j->next;
36     while (i) {
37         if (i->uid == id) {
38             axs_Front(cachep, j, i);    /* maintain LRU queue */
39             return (i);
40         }
41
42         if ((j = i->next)) {    /* ASSIGNMENT HERE! */
43             if (j->uid == id) {
44                 axs_Front(cachep, i, j);
45                 return (j);
46             }
47         } else
48             return ((struct axscache *)NULL);
49         i = j->next;
50     }
51     return ((struct axscache *)NULL);
52 }
53
54
55 #define NAXSs (1000 / sizeof(struct axscache))
56 struct axscache *
57 axs_Alloc(void)
58 {
59     register struct axscache *i, *j, *xsp;
60     struct axscache *h;
61     int k;
62
63     ObtainWriteLock(&afs_xaxs, 174);
64     if ((h = afs_axsfreelist)) {
65         afs_axsfreelist = h->next;
66     } else {
67         h = i = j =
68             (struct axscache *)afs_osi_Alloc(NAXSs * sizeof(struct axscache));
69         afs_xaxscnt++;
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++) {
74             i->uid = -2;
75             i->axess = 0;
76             i->next = ++j;      /* need j because order of evaluation not defined */
77         }
78         i->uid = -2;
79         i->axess = 0;
80         i->next = NULL;
81         afs_axsfreelist = h->next;
82     }
83     ReleaseWriteLock(&afs_xaxs);
84     return (h);
85 }
86
87
88 #define axs_Free(axsp) { \
89  ObtainWriteLock(&afs_xaxs,175);             \
90  axsp->next = afs_axsfreelist;           \
91  afs_axsfreelist = axsp;                 \
92  ReleaseWriteLock(&afs_xaxs);            \
93 }
94
95
96 /* I optimize for speed on lookup, and don't give a RIP about delete.
97  */
98 void
99 afs_RemoveAxs(struct axscache **headp, struct axscache *axsp)
100 {
101     struct axscache *i, *j;
102
103     if (*headp && axsp) {       /* is bullet-proofing really neccessary? */
104         if (*headp == axsp) {   /* most common case, I think */
105             *headp = axsp->next;
106             axs_Free(axsp);
107             return;
108         }
109
110         i = *headp;
111         j = i->next;
112
113         while (j) {
114             if (j == axsp) {
115                 i->next = j->next;
116                 axs_Free(axsp);
117                 return;
118             }
119             if ((i = j->next)) {        /* ASSIGNMENT HERE! */
120                 j->next = i->next;
121                 axs_Free(axsp);
122                 return;
123             }
124         }
125     }
126     /* end of "if neither pointer is NULL" */
127     return;                     /* !#@  FAILED to find it! */
128 }
129
130
131 /* 
132  * Takes an entire list of access cache structs and prepends them, lock, stock,
133  * and barrel, to the front of the freelist.
134  */
135 void
136 afs_FreeAllAxs(struct axscache **headp)
137 {
138     struct axscache *i, *j;
139
140     i = *headp;
141     j = NULL;
142
143     while (i) {                 /* chase down the list 'til we reach the end */
144         j = i->next;
145         if (!j) {
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);
150             *headp = NULL;
151             return;
152         }
153         i = j->next;
154     }
155
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);
161     }
162     *headp = NULL;
163     return;
164 }
165
166
167 /* doesn't appear to be used at all */
168 #if 0
169 static void
170 shutdown_xscache(void)
171 {
172     struct xfreelist *xp, *nxp;
173
174     AFS_RWLOCK_INIT(&afs_xaxs, "afs_xaxs");
175     xp = xfreemallocs;
176     while (xp) {
177         nxp = xp->next;
178         afs_osi_Free((char *)xp, NAXSs * sizeof(struct axscache));
179         xp = nxp;
180     }
181     afs_axsfreelist = NULL;
182     xfreemallocs = NULL;
183 }
184 #endif