summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/ChangeLog6
-rw-r--r--winsup/cygwin/grp.cc20
-rw-r--r--winsup/cygwin/passwd.cc21
3 files changed, 33 insertions, 14 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index ef093c28f..a2fdacc79 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,9 @@
+Fri Sep 28 02:57:03 2001 Christopher Faylor <cgf@cygnus.com>
+
+ * 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.
+
Fri Sep 28 01:50:09 2001 Christopher Faylor <cgf@cygnus.com>
* pipe.cc (fhandler_pipe::hit_eof): Return correct value when there is
diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc
index 48a74e99c..e4a4afd6c 100644
--- a/winsup/cygwin/grp.cc
+++ b/winsup/cygwin/grp.cc
@@ -117,6 +117,14 @@ add_grp_line (const char *line)
curr_lines++;
}
+class group_lock
+{
+ pthread_mutex_t mutex;
+ public:
+ group_lock (): mutex ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) {}
+ void arm () {pthread_mutex_lock (&mutex); }
+};
+
/* Cygwin internal */
/* Read in /etc/group and save contents in the group cache */
/* This sets group_in_memory_p to 1 so functions in this file can
@@ -132,15 +140,13 @@ read_etc_group ()
strncpy (group_name, "Administrators", sizeof (group_name));
- static NO_COPY pthread_mutex_t etc_group_mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
- pthread_mutex_lock (&etc_group_mutex);
+ static NO_COPY group_lock here;
+ if (cygwin_finished_initializing)
+ here.arm ();
/* if we got blocked by the mutex, then etc_group may have been processed */
if (group_state != uninitialized)
- {
- pthread_mutex_unlock(&etc_group_mutex);
- return;
- }
+ return;
if (group_state != initializing)
{
@@ -193,7 +199,7 @@ read_etc_group ()
}
}
- pthread_mutex_unlock(&etc_group_mutex);
+ return;
}
extern "C"
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 */