Thread-secure dregister(3) and dunregister(3).
This commit is contained in:
parent
a1ccba00f7
commit
ff443c9f5e
|
@ -31,6 +31,8 @@ extern "C" { DIR* __firstdir = NULL; }
|
||||||
extern "C" int dcloseall(void)
|
extern "C" int dcloseall(void)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
// We do not lock __firstdir_lock here because this function is called on
|
||||||
|
// process termination and only one thread can call exit(3).
|
||||||
while ( __firstdir )
|
while ( __firstdir )
|
||||||
result |= closedir(__firstdir);
|
result |= closedir(__firstdir);
|
||||||
return result ? EOF : 0;
|
return result ? EOF : 0;
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <DIR.h>
|
#include <DIR.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
extern "C" pthread_mutex_t __dirname_lock;
|
||||||
|
|
||||||
extern "C" void dregister(DIR* dir)
|
extern "C" void dregister(DIR* dir)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,11 +24,15 @@
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <DIR.h>
|
#include <DIR.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
extern "C" { pthread_mutex_t __dirname_lock = PTHREAD_MUTEX_INITIALIZER; }
|
||||||
|
|
||||||
extern "C" void dunregister(DIR* dir)
|
extern "C" void dunregister(DIR* dir)
|
||||||
{
|
{
|
||||||
if ( !(dir->flags & _DIR_REGISTERED) )
|
if ( !(dir->flags & _DIR_REGISTERED) )
|
||||||
return;
|
return;
|
||||||
|
pthread_mutex_lock(&__dirname_lock);
|
||||||
if ( !dir->prev )
|
if ( !dir->prev )
|
||||||
__firstdir = dir->next;
|
__firstdir = dir->next;
|
||||||
if ( dir->prev )
|
if ( dir->prev )
|
||||||
|
@ -36,4 +40,5 @@ extern "C" void dunregister(DIR* dir)
|
||||||
if ( dir->next )
|
if ( dir->next )
|
||||||
dir->next->prev = dir->prev;
|
dir->next->prev = dir->prev;
|
||||||
dir->flags &= ~_DIR_REGISTERED;
|
dir->flags &= ~_DIR_REGISTERED;
|
||||||
|
pthread_mutex_unlock(&__dirname_lock);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue