diff options
author | Christopher Faylor <me@cgf.cx> | 2001-09-28 07:01:22 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2001-09-28 07:01:22 +0000 |
commit | 8b51edbfa6c8f372f9ce68c7edad0046b71ce1fd (patch) | |
tree | c2bbc0c758f73a4e9b04520d32daaf1d6dfbd9d3 /winsup/cygwin/passwd.cc | |
parent | 9c61aed684d15af5348870fcb271ca20dbc51e9b (diff) | |
download | cygnal-8b51edbfa6c8f372f9ce68c7edad0046b71ce1fd.tar.gz cygnal-8b51edbfa6c8f372f9ce68c7edad0046b71ce1fd.tar.bz2 cygnal-8b51edbfa6c8f372f9ce68c7edad0046b71ce1fd.zip |
* passwd.cc (read_etc_passwd): Don't bother with locking when
in cygwin initialization since there is only one thread.
* grp.cc (read_etc_group): Ditto.
Diffstat (limited to 'winsup/cygwin/passwd.cc')
-rw-r--r-- | winsup/cygwin/passwd.cc | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc index 87ba9c672..c86c07b6a 100644 --- a/winsup/cygwin/passwd.cc +++ b/winsup/cygwin/passwd.cc @@ -109,6 +109,14 @@ add_pwd_line (char *line) parse_pwd (passwd_buf[curr_lines++], line); } +class passwd_lock +{ + pthread_mutex_t mutex; + public: + passwd_lock (): mutex ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) {} + void arm () {pthread_mutex_lock (&mutex); } +}; + /* Read in /etc/passwd and save contents in the password cache. This sets passwd_state to loaded or emulated so functions in this file can tell that /etc/passwd has been read in or will be emulated. */ @@ -120,15 +128,14 @@ read_etc_passwd () * for non-shared mutexs in the future. Also, this function will at most be called * once from each thread, after that the passwd_state test will succeed */ - static NO_COPY pthread_mutex_t etc_passwd_mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER; - pthread_mutex_lock (&etc_passwd_mutex); + static NO_COPY passwd_lock here; + + if (cygwin_finished_initializing) + here.arm (); /* if we got blocked by the mutex, then etc_passwd may have been processed */ if (passwd_state != uninitialized) - { - pthread_mutex_unlock(&etc_passwd_mutex); - return; - } + return; if (passwd_state != initializing) { @@ -165,7 +172,7 @@ read_etc_passwd () } - pthread_mutex_unlock (&etc_passwd_mutex); + return; } /* Cygwin internal */ |