summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen
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
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')
-rw-r--r--lib/libc/gen/closedir.c6
-rw-r--r--lib/libc/gen/directory.32
-rw-r--r--lib/libc/gen/opendir.c2
-rw-r--r--lib/libc/gen/readdir.c9
-rw-r--r--lib/libc/gen/telldir.c68
5 files changed, 34 insertions, 53 deletions
diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c
index 86de88d..69f1232 100644
--- a/lib/libc/gen/closedir.c
+++ b/lib/libc/gen/closedir.c
@@ -42,14 +42,14 @@ static char sccsid[] = "@(#)closedir.c 8.1 (Berkeley) 6/10/93";
#include <stdlib.h>
#include <unistd.h>
-extern void _reclaim_telldir __P(( const DIR * ));
+extern void _reclaim_telldir __P((DIR *));
/*
* close a directory.
*/
int
closedir(dirp)
- register DIR *dirp;
+ DIR *dirp;
{
int fd;
@@ -58,7 +58,7 @@ closedir(dirp)
dirp->dd_fd = -1;
dirp->dd_loc = 0;
free((void *)dirp->dd_buf);
- free((void *)dirp);
_reclaim_telldir(dirp);
+ free((void *)dirp);
return(_close(fd));
}
diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3
index 27907af..8061d1d 100644
--- a/lib/libc/gen/directory.3
+++ b/lib/libc/gen/directory.3
@@ -57,7 +57,7 @@
.Ft int
.Fn readdir_r "DIR *dirp" "struct dirent *entry" "struct dirent **result"
.Ft long
-.Fn telldir "const DIR *dirp"
+.Fn telldir "DIR *dirp"
.Ft void
.Fn seekdir "DIR *dirp" "long loc"
.Ft void
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index d94b9af..90aaec3 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -259,6 +259,8 @@ __opendir2(name, flags)
dirp->dd_loc = 0;
dirp->dd_fd = fd;
dirp->dd_flags = flags;
+ dirp->dd_loccnt = 0;
+ LIST_INIT(&dirp->dd_locq);
/*
* Set up seek point for rewinddir.
diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c
index 14cc001..1f6f84e 100644
--- a/lib/libc/gen/readdir.c
+++ b/lib/libc/gen/readdir.c
@@ -52,9 +52,9 @@ static char sccsid[] = "@(#)readdir.c 8.3 (Berkeley) 9/29/94";
*/
struct dirent *
readdir(dirp)
- register DIR *dirp;
+ DIR *dirp;
{
- register struct dirent *dp;
+ struct dirent *dp;
for (;;) {
if (dirp->dd_loc >= dirp->dd_size) {
@@ -90,9 +90,10 @@ readdir_r(dirp, entry, result)
struct dirent **result;
{
struct dirent *dp;
- int ret, saved_errno;
-
+ int saved_errno;
#ifdef _THREAD_SAFE
+ int ret;
+
if ((ret = _FD_LOCK(dirp->dd_fd, FD_READ, NULL)) != 0)
return (ret);
#endif
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