summaryrefslogtreecommitdiff
path: root/libc/misc/mntent/mntent.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2006-12-07 23:24:02 +0000
committerEric Andersen <andersen@codepoet.org>2006-12-07 23:24:02 +0000
commit1478c2de052374c6356db5513749a144c13791b1 (patch)
tree3b22a3f8361f94c99508c497e240ecb71acf8641 /libc/misc/mntent/mntent.c
parent99d6c367c4820a072dc4ada51561df17e2093778 (diff)
Major cleanup of internal mutex locking. Be more consistant in how we do
things, and avoid potential deadlocks caused when a thread holding a uClibc internal lock get canceled and terminates without releasing the lock. This change also provides a single place, bits/uClibc_mutex.h, for thread libraries to modify to change all instances of internal locking.
Diffstat (limited to 'libc/misc/mntent/mntent.c')
-rw-r--r--libc/misc/mntent/mntent.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/libc/misc/mntent/mntent.c b/libc/misc/mntent/mntent.c
index 3164f6634..a5db799dc 100644
--- a/libc/misc/mntent/mntent.c
+++ b/libc/misc/mntent/mntent.c
@@ -8,6 +8,9 @@
#include <stdlib.h>
#include <string.h>
#include <mntent.h>
+#include <bits/uClibc_mutex.h>
+
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
libc_hidden_proto(getmntent_r)
libc_hidden_proto(setmntent)
@@ -23,13 +26,6 @@ libc_hidden_proto(fgets)
libc_hidden_proto(abort)
libc_hidden_proto(fprintf)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-#define LOCK __pthread_mutex_lock(&mylock)
-#define UNLOCK __pthread_mutex_unlock(&mylock)
-
/* Reentrant version of getmntent. */
struct mntent *getmntent_r (FILE *filep,
struct mntent *mnt, char *buff, int bufsize)
@@ -85,7 +81,7 @@ struct mntent *getmntent(FILE * filep)
struct mntent *tmp;
static char *buff = NULL;
static struct mntent mnt;
- LOCK;
+ __UCLIBC_MUTEX_LOCK(mylock);
if (!buff) {
buff = malloc(BUFSIZ);
@@ -94,7 +90,7 @@ struct mntent *getmntent(FILE * filep)
}
tmp = getmntent_r(filep, &mnt, buff, BUFSIZ);
- UNLOCK;
+ __UCLIBC_MUTEX_UNLOCK(mylock);
return(tmp);
}