]>
Commit | Line | Data |
---|---|---|
3d9156a7 A |
1 | --- telldir.c.orig 2003-05-20 15:21:03.000000000 -0700 |
2 | +++ telldir.c 2004-11-19 17:18:44.000000000 -0800 | |
3 | @@ -54,7 +54,9 @@ | |
4 | * cookie may be used only once before it is freed. This option | |
5 | * is used to avoid having memory usage grow without bound. | |
6 | */ | |
7 | +#if !__DARWIN_UNIX03 | |
8 | #define SINGLEUSE | |
9 | +#endif /* !__DARWIN_UNIX03 */ | |
10 | ||
11 | /* | |
12 | * return a pointer into a directory | |
13 | @@ -65,14 +67,32 @@ | |
14 | { | |
15 | struct ddloc *lp; | |
16 | ||
17 | +#if __DARWIN_UNIX03 | |
18 | + if (__isthreaded) | |
19 | + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); | |
20 | + LIST_FOREACH(lp, &dirp->dd_td->td_locq, loc_lqe) { | |
21 | + if ((lp->loc_seek == dirp->dd_seek) && | |
22 | + (lp->loc_loc == dirp->dd_loc)) | |
23 | + goto found; | |
24 | + } | |
25 | + if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) { | |
26 | + if (__isthreaded) | |
27 | + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); | |
28 | + return (-1); | |
29 | + } | |
30 | +#else /* !__DARWIN_UNIX03 */ | |
31 | if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) | |
32 | return (-1); | |
33 | if (__isthreaded) | |
34 | _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); | |
35 | +#endif /* __DARWIN_UNIX03 */ | |
36 | lp->loc_index = dirp->dd_td->td_loccnt++; | |
37 | lp->loc_seek = dirp->dd_seek; | |
38 | lp->loc_loc = dirp->dd_loc; | |
39 | LIST_INSERT_HEAD(&dirp->dd_td->td_locq, lp, loc_lqe); | |
40 | +#if __DARWIN_UNIX03 | |
41 | +found: | |
42 | +#endif /* __DARWIN_UNIX03 */ | |
43 | if (__isthreaded) | |
44 | _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); | |
45 | return (lp->loc_index); | |
46 | @@ -106,13 +126,14 @@ | |
47 | if (dp == NULL) | |
48 | break; | |
49 | } | |
50 | -found: | |
51 | +found:; | |
52 | #ifdef SINGLEUSE | |
53 | LIST_REMOVE(lp, loc_lqe); | |
54 | free((caddr_t)lp); | |
55 | #endif | |
56 | } | |
57 | ||
58 | +#ifndef BUILDING_VARIANT | |
59 | /* | |
60 | * Reclaim memory for telldir cookies which weren't used. | |
61 | */ | |
62 | @@ -131,3 +152,4 @@ | |
63 | } | |
64 | LIST_INIT(&dirp->dd_td->td_locq); | |
65 | } | |
66 | +#endif /* !BUILDING_VARIANT */ |