From 1478c2de052374c6356db5513749a144c13791b1 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 7 Dec 2006 23:24:02 +0000 Subject: 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. --- libc/misc/mntent/mntent.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'libc/misc/mntent') 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 #include #include +#include + +__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 -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); } -- cgit v1.2.3