7 * dir_table is a global static array of pthread mutexes. The array is NMUTEXES
8 * in length (NMUTEXES * sizeof(pthread_mutex_t)).
10 * Whenever a call to readdir_r is made, the element in the array indexed by the
11 * modulus of the file descriptor associated with dirp is locked, and readdir is
12 * called on dirp. The result is returned in readdir_r semantics and the
13 * element in dir_table is unlocked.
16 static pthread_mutex_t dir_table
[] = {
17 PTHREAD_MUTEX_INITIALIZER
,
18 PTHREAD_MUTEX_INITIALIZER
,
19 PTHREAD_MUTEX_INITIALIZER
,
20 PTHREAD_MUTEX_INITIALIZER
,
21 PTHREAD_MUTEX_INITIALIZER
,
22 PTHREAD_MUTEX_INITIALIZER
,
23 PTHREAD_MUTEX_INITIALIZER
,
24 PTHREAD_MUTEX_INITIALIZER
28 int readdir_r(DIR *dirp
, struct dirent
*entry
, struct dirent
**result
)
31 int mindex
= dirp
->dd_fd
% NMUTEXES
;
34 pthread_mutex_lock(&dir_table
[mindex
]);
36 tmpdp
= readdir(dirp
);
40 pthread_mutex_unlock(&dir_table
[mindex
]);
44 memcpy(entry
, tmpdp
, sizeof(struct dirent
));
47 pthread_mutex_unlock(&dir_table
[mindex
]);