summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/telldir.c
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2000-12-06 03:15:49 +0000
committerdeischen <deischen@FreeBSD.org>2000-12-06 03:15:49 +0000
commitcf92dabe14c7581217daf96f6257caae8c56b826 (patch)
tree0dd5c36710eb675e55c9d6b12fdea35f32c5b68e /lib/libc/gen/telldir.c
parent507950431dac1887fe7f639efde6d9a3bcdb790f (diff)
downloadFreeBSD-src-cf92dabe14c7581217daf96f6257caae8c56b826.zip
FreeBSD-src-cf92dabe14c7581217daf96f6257caae8c56b826.tar.gz
Cleanup XXXdir functions to eliminate global hash table of
telldir positions. This will allow (future) locking on a per-DIR basis (for MT-safety). For now, this change does the following: o Remove the hash table from telldir.c. Recode to use queue macros. o Remove 'const' from 'telldir(const DIR *)'. o Remove 'register' variables as suggested in a recent thread. No response from: -current
Diffstat (limited to 'lib/libc/gen/telldir.c')
-rw-r--r--lib/libc/gen/telldir.c68
1 files changed, 23 insertions, 45 deletions
diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c
index ab23d9d..fba5394 100644
--- a/lib/libc/gen/telldir.c
+++ b/lib/libc/gen/telldir.c
@@ -29,6 +29,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $FreeBSD$
*/
#if defined(LIBC_SCCS) && !defined(lint)
@@ -53,40 +55,29 @@ static char sccsid[] = "@(#)telldir.c 8.1 (Berkeley) 6/4/93";
* cookie returned by getdirentries and the offset within the buffer
* associated with that return value.
*/
-struct ddloc {
- struct ddloc *loc_next;/* next structure in list */
+struct _ddloc {
+ LIST_ENTRY(_ddloc) loc_lqe; /* entry in list */
long loc_index; /* key associated with structure */
long loc_seek; /* magic cookie returned by getdirentries */
long loc_loc; /* offset of entry in buffer */
- const DIR* loc_dirp; /* directory which used this entry */
};
-#define NDIRHASH 32 /* Num of hash lists, must be a power of 2 */
-#define LOCHASH(i) ((i)&(NDIRHASH-1))
-
-static long dd_loccnt; /* Index of entry for sequential readdir's */
-static struct ddloc *dd_hash[NDIRHASH]; /* Hash list heads for ddlocs */
-
/*
* return a pointer into a directory
*/
long
telldir(dirp)
- const DIR *dirp;
+ DIR *dirp;
{
- register int index;
- register struct ddloc *lp;
+ struct _ddloc *lp;
- if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL)
+ if ((lp = (struct _ddloc *)malloc(sizeof(struct _ddloc))) == NULL)
return (-1);
- index = dd_loccnt++;
- lp->loc_index = index;
+ lp->loc_index = dirp->dd_loccnt++;
lp->loc_seek = dirp->dd_seek;
lp->loc_loc = dirp->dd_loc;
- lp->loc_dirp = dirp;
- lp->loc_next = dd_hash[LOCHASH(index)];
- dd_hash[LOCHASH(index)] = lp;
- return (index);
+ LIST_INSERT_HEAD(&dirp->dd_locq, lp, loc_lqe);
+ return (lp->loc_index);
}
/*
@@ -95,20 +86,15 @@ telldir(dirp)
*/
void
_seekdir(dirp, loc)
- register DIR *dirp;
+ DIR *dirp;
long loc;
{
- register struct ddloc *lp;
- register struct ddloc **prevlp;
+ struct _ddloc *lp;
struct dirent *dp;
- prevlp = &dd_hash[LOCHASH(loc)];
- lp = *prevlp;
- while (lp != NULL) {
+ LIST_FOREACH(lp, &dirp->dd_locq, loc_lqe) {
if (lp->loc_index == loc)
break;
- prevlp = &lp->loc_next;
- lp = lp->loc_next;
}
if (lp == NULL)
return;
@@ -124,7 +110,7 @@ _seekdir(dirp, loc)
}
found:
#ifdef SINGLEUSE
- *prevlp = lp->loc_next;
+ LIST_REMOVE(lp, loc_lqe);
free((caddr_t)lp);
#endif
}
@@ -134,24 +120,16 @@ found:
*/
void
_reclaim_telldir(dirp)
- register const DIR *dirp;
+ DIR *dirp;
{
- register struct ddloc *lp;
- register struct ddloc **prevlp;
- int i;
+ struct _ddloc *lp;
+ struct _ddloc *templp;
- for (i = 0; i < NDIRHASH; i++) {
- prevlp = &dd_hash[i];
- lp = *prevlp;
- while (lp != NULL) {
- if (lp->loc_dirp == dirp) {
- *prevlp = lp->loc_next;
- free((caddr_t)lp);
- lp = *prevlp;
- continue;
- }
- prevlp = &lp->loc_next;
- lp = lp->loc_next;
- }
+ lp = LIST_FIRST(&dirp->dd_locq);
+ while (lp != NULL) {
+ templp = lp;
+ lp = LIST_NEXT(lp, loc_lqe);
+ free(templp);
}
+ LIST_INIT(&dirp->dd_locq);
}
OpenPOWER on IntegriCloud