Browse Source

macro out the thread funcs in libc if threading is disabled

Mike Frysinger 18 years ago
parent
commit
aab07d0500

+ 8 - 0
include/libc-internal.h

@@ -174,6 +174,14 @@ extern int __gettimeofday(struct timeval *__restrict __tv, *__restrict __timezon
 #   define gettimeofday __gettimeofday
 #  endif
 
+/* #include <pthread.h> */
+#  ifndef __UCLIBC_HAS_THREADS__
+#   define __pthread_mutex_init(mutex, mutexattr)         ((void)0)
+#   define __pthread_mutex_lock(mutex)                    ((void)0)
+#   define __pthread_mutex_trylock(mutex)                 ((void)0)
+#   define __pthread_mutex_unlock(mutex)                  ((void)0)
+#  endif
+
 # endif /* IS_IN_libc */
 #endif /* __ASSEMBLER__ */
 

+ 3 - 6
libc/inet/getnetent.c

@@ -24,14 +24,11 @@
 
 
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK	__pthread_mutex_lock(&mylock)
-# define UNLOCK	__pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&mylock)
+#define UNLOCK	__pthread_mutex_unlock(&mylock)
 
 
 

+ 4 - 6
libc/inet/getproto.c

@@ -64,15 +64,13 @@
 #include <string.h>
 #include <errno.h>
 
+
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-# define LOCK	__pthread_mutex_lock(&mylock)
-# define UNLOCK	__pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&mylock)
+#define UNLOCK	__pthread_mutex_unlock(&mylock)
 
 
 

+ 3 - 7
libc/inet/getservice.c

@@ -67,16 +67,12 @@
 #include <errno.h>
 
 
-
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-# define LOCK	__pthread_mutex_lock(&mylock)
-# define UNLOCK	__pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&mylock)
+#define UNLOCK	__pthread_mutex_unlock(&mylock)
 
 
 

+ 8 - 12
libc/inet/resolv.c

@@ -186,15 +186,13 @@ extern char * __nameserver[MAX_SERVERS];
 extern int __searchdomains;
 extern char * __searchdomain[MAX_SEARCH];
 
+
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 extern pthread_mutex_t __resolv_lock;
-# define BIGLOCK	__pthread_mutex_lock(&__resolv_lock)
-# define BIGUNLOCK	__pthread_mutex_unlock(&__resolv_lock);
-#else
-# define BIGLOCK
-# define BIGUNLOCK
 #endif
+#define BIGLOCK	__pthread_mutex_lock(&__resolv_lock)
+#define BIGUNLOCK	__pthread_mutex_unlock(&__resolv_lock)
 
 
 
@@ -659,15 +657,12 @@ int __form_query(int id, const char *name, int type, unsigned char *packet,
 #endif
 
 #if defined(L_dnslookup) || defined(L_gethostent)
-
 #ifdef __UCLIBC_HAS_THREADS__
+# include <pthread.h>
 static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK	__pthread_mutex_lock(&mylock)
-# define UNLOCK	__pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&mylock)
+#define UNLOCK	__pthread_mutex_unlock(&mylock)
 #endif
 
 #ifdef L_dnslookup
@@ -981,6 +976,7 @@ char * __nameserver[MAX_SERVERS];
 int __searchdomains;
 char * __searchdomain[MAX_SEARCH];
 #ifdef __UCLIBC_HAS_THREADS__
+# include <pthread.h>
 pthread_mutex_t __resolv_lock = PTHREAD_MUTEX_INITIALIZER;
 #endif
 

+ 3 - 6
libc/inet/rpc/create_xid.c

@@ -31,14 +31,11 @@
 /* The RPC code is not threadsafe, but new code should be threadsafe. */
 
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 static pthread_mutex_t createxid_lock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK	__pthread_mutex_lock(&createxid_lock)
-# define UNLOCK	__pthread_mutex_unlock(&createxid_lock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&createxid_lock)
+#define UNLOCK	__pthread_mutex_unlock(&createxid_lock)
 
 static int is_initialized;
 static struct drand48_data __rpc_lrand48_data;

+ 2 - 5
libc/inet/rpc/getrpcent.c

@@ -257,12 +257,9 @@ static struct rpcent *interpret(register struct rpcdata *d)
 #if defined(__UCLIBC_HAS_THREADS__)
 # include <pthread.h>
 static pthread_mutex_t rpcdata_lock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK    __pthread_mutex_lock(&rpcdata_lock)
-# define UNLOCK  __pthread_mutex_unlock(&rpcdata_lock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK    __pthread_mutex_lock(&rpcdata_lock)
+#define UNLOCK  __pthread_mutex_unlock(&rpcdata_lock)
 
 static int __copy_rpcent(struct rpcent *r, struct rpcent *result_buf, char *buffer, 
 		size_t buflen, struct rpcent **result)

+ 0 - 4
libc/misc/dirent/closedir.c

@@ -19,14 +19,10 @@ int closedir(DIR * dir)
 		__set_errno(EBADF);
 		return -1;
 	}
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_lock(&(dir->dd_lock));
-#endif
 	fd = dir->dd_fd;
 	dir->dd_fd = -1;
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_unlock(&(dir->dd_lock));
-#endif
 	free(dir->dd_buf);
 	free(dir);
 	return __close(fd);

+ 0 - 2
libc/misc/dirent/opendir.c

@@ -51,8 +51,6 @@ DIR *opendir(const char *name)
 		return NULL;
 	}
 	ptr->dd_buf = buf;
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_init(&(ptr->dd_lock), NULL);
-#endif
 	return ptr;
 }

+ 0 - 4
libc/misc/dirent/readdir.c

@@ -16,9 +16,7 @@ struct dirent *readdir(DIR * dir)
 		return NULL;
 	}
 
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_lock(&(dir->dd_lock));
-#endif
 
 	do {
 	    if (dir->dd_size <= dir->dd_nextloc) {
@@ -44,8 +42,6 @@ struct dirent *readdir(DIR * dir)
 	} while (de->d_ino == 0);
 
 all_done:
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_unlock(&(dir->dd_lock));
-#endif
 	return de;
 }

+ 0 - 4
libc/misc/dirent/readdir64.c

@@ -31,9 +31,7 @@ struct dirent64 *readdir64(DIR * dir)
 		return NULL;
 	}
 
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_lock(&(dir->dd_lock));
-#endif
 
 	do {
 	    if (dir->dd_size <= dir->dd_nextloc) {
@@ -59,9 +57,7 @@ struct dirent64 *readdir64(DIR * dir)
 	} while (de->d_ino == 0);
 
 all_done:
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_unlock(&(dir->dd_lock));
-#endif
 
 	return de;
 }

+ 0 - 4
libc/misc/dirent/readdir64_r.c

@@ -32,9 +32,7 @@ int readdir64_r(DIR *dir, struct dirent64 *entry, struct dirent64 **result)
 	}
 	de = NULL;
 
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_lock(&(dir->dd_lock));
-#endif
 
 	do {
 	    if (dir->dd_size <= dir->dd_nextloc) {
@@ -68,9 +66,7 @@ int readdir64_r(DIR *dir, struct dirent64 *entry, struct dirent64 **result)
 
 all_done:
 
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_unlock(&(dir->dd_lock));
-#endif
         return((de != NULL)? 0 : ret);
 }
 #endif /* __UCLIBC_HAS_LFS__ */

+ 2 - 6
libc/misc/dirent/readdir_r.c

@@ -5,7 +5,6 @@
 #include <dirent.h>
 #include "dirstream.h"
 
-
 int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
 {
 	int ret;
@@ -18,9 +17,7 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
 	}
 	de = NULL;
 
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_lock(&(dir->dd_lock));
-#endif
 
 	do {
 	    if (dir->dd_size <= dir->dd_nextloc) {
@@ -54,8 +51,7 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
 
 all_done:
 
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_unlock(&(dir->dd_lock));
-#endif
-        return((de != NULL)? 0 : ret);
+
+	return((de != NULL)? 0 : ret);
 }

+ 0 - 4
libc/misc/dirent/rewinddir.c

@@ -11,12 +11,8 @@ void rewinddir(DIR * dir)
 		__set_errno(EBADF);
 		return;
 	}
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_lock(&(dir->dd_lock));
-#endif
 	lseek(dir->dd_fd, 0, SEEK_SET);
 	dir->dd_nextoff = dir->dd_nextloc = dir->dd_size = 0;
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_unlock(&(dir->dd_lock));
-#endif
 }

+ 0 - 5
libc/misc/dirent/seekdir.c

@@ -3,19 +3,14 @@
 #include <unistd.h>
 #include "dirstream.h"
 
-
 void seekdir(DIR * dir, long int offset)
 {
 	if (!dir) {
 		__set_errno(EBADF);
 		return;
 	}
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_lock(&(dir->dd_lock));
-#endif
 	dir->dd_nextoff = lseek(dir->dd_fd, offset, SEEK_SET);
 	dir->dd_size = dir->dd_nextloc = 0;
-#ifdef __UCLIBC_HAS_THREADS__
 	__pthread_mutex_unlock(&(dir->dd_lock));
-#endif
 }

+ 3 - 6
libc/misc/mntent/mntent.c

@@ -7,14 +7,11 @@
 #include <mntent.h>
 
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK	__pthread_mutex_lock(&mylock)
-# define UNLOCK	__pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&mylock)
+#define UNLOCK	__pthread_mutex_unlock(&mylock)
 
 /* Reentrant version of getmntent.  */
 struct mntent *getmntent_r (FILE *filep, 

+ 3 - 6
libc/misc/syslog/syslog.c

@@ -86,14 +86,11 @@
 
 
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-# define LOCK	__pthread_mutex_lock(&mylock)
-# define UNLOCK	__pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&mylock)
+#define UNLOCK	__pthread_mutex_unlock(&mylock)
 
 
 static int	LogFile = -1;		/* fd for log */

+ 2 - 11
libc/misc/time/time.c

@@ -199,21 +199,12 @@ typedef struct {
 } rule_struct;
 
 #ifdef __UCLIBC_HAS_THREADS__
-
-#include <pthread.h>
-
+# include <pthread.h>
 extern pthread_mutex_t _time_tzlock;
-
+#endif
 #define TZLOCK		__pthread_mutex_lock(&_time_tzlock)
 #define TZUNLOCK	__pthread_mutex_unlock(&_time_tzlock)
 
-#else
-
-#define TZLOCK		((void) 0)
-#define TZUNLOCK	((void) 0)
-
-#endif
-
 extern rule_struct _time_tzinfo[2];
 
 extern struct tm *_time_t2tm(const time_t *__restrict timer,

+ 3 - 6
libc/misc/utmp/utent.c

@@ -23,14 +23,11 @@
 
 
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 static pthread_mutex_t utmplock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK	__pthread_mutex_lock(&utmplock)
-# define UNLOCK	__pthread_mutex_unlock(&utmplock)
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&utmplock)
+#define UNLOCK	__pthread_mutex_unlock(&utmplock)
 
 
 

+ 4 - 7
libc/pwd_grp/lckpwdf.c

@@ -31,14 +31,11 @@
 #include <paths.h>
 
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK   __pthread_mutex_lock(&mylock)
-# define UNLOCK __pthread_mutex_unlock(&mylock);
-#else       
-# define LOCK
-# define UNLOCK
-#endif      
+#endif
+#define LOCK   __pthread_mutex_lock(&mylock)
+#define UNLOCK __pthread_mutex_unlock(&mylock)
 
 /* How long to wait for getting the lock before returning with an
    error.  */

+ 3 - 6
libc/pwd_grp/pwd_grp.c

@@ -402,15 +402,12 @@ int getpw(uid_t uid, char *buf)
 #endif
 /**********************************************************************/
 #if defined(L_getpwent_r) || defined(L_getgrent_r) || defined(L_getspent_r)
-
 #ifdef __UCLIBC_HAS_THREADS__
+# include <pthread.h>
 static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK		__pthread_mutex_lock(&mylock)
-# define UNLOCK		__pthread_mutex_unlock(&mylock);
-#else
-# define LOCK		((void) 0)
-# define UNLOCK		((void) 0)
 #endif
+#define LOCK		__pthread_mutex_lock(&mylock)
+#define UNLOCK		__pthread_mutex_unlock(&mylock)
 #endif
 
 #ifdef L_getpwent_r

+ 4 - 7
libc/stdio/popen.c

@@ -32,14 +32,11 @@
 #endif
 
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK			__pthread_mutex_lock(&mylock)
-# define UNLOCK			__pthread_mutex_unlock(&mylock);
-#else
-# define LOCK			((void) 0)
-# define UNLOCK			((void) 0)
-#endif      
+#endif
+#define LOCK			__pthread_mutex_lock(&mylock)
+#define UNLOCK			__pthread_mutex_unlock(&mylock)
 
 #ifndef VFORK_LOCK
 # define VFORK_LOCK		LOCK

+ 2 - 5
libc/stdlib/abort.c

@@ -75,12 +75,9 @@ static int been_there_done_that = 0;
 #ifdef __UCLIBC_HAS_THREADS__
 # include <pthread.h>
 static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-# define LOCK	__pthread_mutex_lock(&mylock)
-# define UNLOCK	__pthread_mutex_unlock(&mylock)
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&mylock)
+#define UNLOCK	__pthread_mutex_unlock(&mylock)
 
 
 extern int __raise (int __sig) __THROW attribute_hidden;

+ 3 - 6
libc/stdlib/atexit.c

@@ -45,14 +45,11 @@
 #include <atomic.h>
 
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 extern pthread_mutex_t mylock;
-# define LOCK	__pthread_mutex_lock(&mylock)
-# define UNLOCK	__pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&mylock)
+#define UNLOCK	__pthread_mutex_unlock(&mylock)
 
 
 typedef void (*aefuncp) (void);         /* atexit function pointer */

+ 3 - 6
libc/stdlib/malloc-simple/alloc.c

@@ -111,14 +111,11 @@ void free(void *ptr)
 
 #ifdef L_memalign
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 pthread_mutex_t __malloc_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-# define LOCK	__pthread_mutex_lock(&__malloc_lock)
-# define UNLOCK	__pthread_mutex_unlock(&__malloc_lock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&__malloc_lock)
+#define UNLOCK	__pthread_mutex_unlock(&__malloc_lock)
 
 /* List of blocks allocated with memalign or valloc */
 struct alignlist

+ 3 - 6
libc/stdlib/malloc-standard/malloc.h

@@ -26,14 +26,11 @@
 
 
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 extern pthread_mutex_t __malloc_lock;
-# define LOCK	__pthread_mutex_lock(&__malloc_lock)
-# define UNLOCK	__pthread_mutex_unlock(&__malloc_lock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&__malloc_lock)
+#define UNLOCK	__pthread_mutex_unlock(&__malloc_lock)
 
 
 

+ 2 - 8
libc/stdlib/malloc/heap.h

@@ -135,14 +135,8 @@ extern void __heap_dump (struct heap *heap, const char *str);
 extern void __heap_check (struct heap *heap, const char *str);
 
 
-#ifdef HEAP_USE_LOCKING
-# define __heap_lock(heap)	__pthread_mutex_lock (&(heap)->lock)
-# define __heap_unlock(heap)	__pthread_mutex_unlock (&(heap)->lock)
-#else /* !__UCLIBC_HAS_THREADS__ */
-/* Without threads, mutex operations are a nop.  */
-# define __heap_lock(heap)	(void)0
-# define __heap_unlock(heap)	(void)0
-#endif /* HEAP_USE_LOCKING */
+#define __heap_lock(heap)	__pthread_mutex_lock (&(heap)->lock)
+#define __heap_unlock(heap)	__pthread_mutex_unlock (&(heap)->lock)
 
 
 /* Delete the free-area FA from HEAP.  */

+ 2 - 4
libc/stdlib/random.c

@@ -31,15 +31,13 @@
 #include <limits.h>
 #include <stddef.h>
 #include <stdlib.h>
+
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 /* POSIX.1c requires that there is mutual exclusion for the `rand' and
    `srand' functions to prevent concurrent calls from modifying common
    data.  */
 static pthread_mutex_t lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#else
-#define __pthread_mutex_lock(x)
-#define __pthread_mutex_unlock(x)
 #endif
 
 /* An improved random number generation package.  In addition to the standard

+ 3 - 6
libc/stdlib/setenv.c

@@ -29,14 +29,11 @@
 #include <unistd.h>
 
 #ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# include <pthread.h>
 static pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
-# define LOCK	__pthread_mutex_lock(&mylock)
-# define UNLOCK	__pthread_mutex_unlock(&mylock);
-#else
-# define LOCK
-# define UNLOCK
 #endif
+#define LOCK	__pthread_mutex_lock(&mylock)
+#define UNLOCK	__pthread_mutex_unlock(&mylock)
 
 extern int __unsetenv (__const char *__name) attribute_hidden;