mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Thread-secure dregister(3) and dunregister(3).
This commit is contained in:
parent
a1ccba00f7
commit
ff443c9f5e
3 changed files with 10 additions and 0 deletions
|
@ -31,6 +31,8 @@ extern "C" { DIR* __firstdir = NULL; }
|
|||
extern "C" int dcloseall(void)
|
||||
{
|
||||
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 )
|
||||
result |= closedir(__firstdir);
|
||||
return result ? EOF : 0;
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
#include <pthread.h>
|
||||
|
||||
extern "C" pthread_mutex_t __dirname_lock;
|
||||
|
||||
extern "C" void dregister(DIR* dir)
|
||||
{
|
||||
|
|
|
@ -24,11 +24,15 @@
|
|||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
#include <pthread.h>
|
||||
|
||||
extern "C" { pthread_mutex_t __dirname_lock = PTHREAD_MUTEX_INITIALIZER; }
|
||||
|
||||
extern "C" void dunregister(DIR* dir)
|
||||
{
|
||||
if ( !(dir->flags & _DIR_REGISTERED) )
|
||||
return;
|
||||
pthread_mutex_lock(&__dirname_lock);
|
||||
if ( !dir->prev )
|
||||
__firstdir = dir->next;
|
||||
if ( dir->prev )
|
||||
|
@ -36,4 +40,5 @@ extern "C" void dunregister(DIR* dir)
|
|||
if ( dir->next )
|
||||
dir->next->prev = dir->prev;
|
||||
dir->flags &= ~_DIR_REGISTERED;
|
||||
pthread_mutex_unlock(&__dirname_lock);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue