Browse Source

split internal lock API out of libc.h, creating lock.h

this further reduces the number of source files which need to include
libc.h and thereby be potentially exposed to libc global state and
internals.

this will also facilitate further improvements like adding an inline
fast-path, if we want to do so later.
Rich Felker 5 years ago
parent
commit
5f12ffe123

+ 1 - 1
src/dirent/readdir_r.c

@@ -2,7 +2,7 @@
 #include <errno.h>
 #include <string.h>
 #include "__dirent.h"
-#include "libc.h"
+#include "lock.h"
 
 int readdir_r(DIR *restrict dir, struct dirent *restrict buf, struct dirent **restrict result)
 {

+ 1 - 1
src/dirent/rewinddir.c

@@ -1,7 +1,7 @@
 #include <dirent.h>
 #include <unistd.h>
 #include "__dirent.h"
-#include "libc.h"
+#include "lock.h"
 
 void rewinddir(DIR *dir)
 {

+ 1 - 1
src/dirent/seekdir.c

@@ -1,7 +1,7 @@
 #include <dirent.h>
 #include <unistd.h>
 #include "__dirent.h"
-#include "libc.h"
+#include "lock.h"
 
 void seekdir(DIR *dir, long off)
 {

+ 1 - 1
src/exit/abort.c

@@ -3,7 +3,7 @@
 #include "syscall.h"
 #include "pthread_impl.h"
 #include "atomic.h"
-#include "libc.h"
+#include "lock.h"
 #include "ksigaction.h"
 
 hidden volatile int __abort_lock[1];

+ 1 - 0
src/exit/at_quick_exit.c

@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include "libc.h"
+#include "lock.h"
 
 #define COUNT 32
 

+ 1 - 0
src/exit/atexit.c

@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include "libc.h"
+#include "lock.h"
 
 /* Ensure that at least 32 atexit handlers can be registered without malloc */
 #define COUNT 32

+ 0 - 6
src/internal/libc.h

@@ -51,12 +51,6 @@ extern char *__progname, *__progname_full;
 
 extern hidden const char __libc_version[];
 
-/* Designed to avoid any overhead in non-threaded processes */
-hidden void __lock(volatile int *);
-hidden void __unlock(volatile int *);
-#define LOCK(x) __lock(x)
-#define UNLOCK(x) __unlock(x)
-
 hidden void __synccall(void (*)(void *), void *);
 hidden int __setxid(int, int, int, int);
 

+ 9 - 0
src/internal/lock.h

@@ -0,0 +1,9 @@
+#ifndef LOCK_H
+#define LOCK_H
+
+hidden void __lock(volatile int *);
+hidden void __unlock(volatile int *);
+#define LOCK(x) __lock(x)
+#define UNLOCK(x) __unlock(x)
+
+#endif

+ 1 - 0
src/locale/dcngettext.c

@@ -9,6 +9,7 @@
 #include "locale_impl.h"
 #include "atomic.h"
 #include "pleval.h"
+#include "lock.h"
 
 struct binding {
 	struct binding *next;

+ 1 - 1
src/locale/locale_map.c

@@ -3,7 +3,7 @@
 #include <sys/mman.h>
 #include "locale_impl.h"
 #include "libc.h"
-#include "atomic.h"
+#include "lock.h"
 
 const char *__lctrans_impl(const char *msg, const struct __locale_map *lm)
 {

+ 1 - 1
src/locale/setlocale.c

@@ -3,7 +3,7 @@
 #include <string.h>
 #include "locale_impl.h"
 #include "libc.h"
-#include "atomic.h"
+#include "lock.h"
 
 static char buf[LC_ALL*(LOCALE_NAME_MAX+1)];
 

+ 1 - 1
src/malloc/lite_malloc.c

@@ -2,7 +2,7 @@
 #include <stdint.h>
 #include <limits.h>
 #include <errno.h>
-#include "libc.h"
+#include "lock.h"
 #include "malloc_impl.h"
 
 #define ALIGN 16

+ 1 - 1
src/misc/syslog.c

@@ -9,7 +9,7 @@
 #include <pthread.h>
 #include <errno.h>
 #include <fcntl.h>
-#include "libc.h"
+#include "lock.h"
 
 static volatile int lock[1];
 static char log_ident[32];

+ 1 - 1
src/prng/random.c

@@ -1,6 +1,6 @@
 #include <stdlib.h>
 #include <stdint.h>
-#include "libc.h"
+#include "lock.h"
 
 /*
 this code uses the same lagged fibonacci generator as the

+ 1 - 0
src/signal/sigaction.c

@@ -4,6 +4,7 @@
 #include "syscall.h"
 #include "pthread_impl.h"
 #include "libc.h"
+#include "lock.h"
 #include "ksigaction.h"
 
 volatile int dummy_lock[1] = { 0 };

+ 1 - 1
src/stdio/ofl.c

@@ -1,5 +1,5 @@
 #include "stdio_impl.h"
-#include "libc.h"
+#include "lock.h"
 
 static FILE *ofl_head;
 static volatile int ofl_lock[1];

+ 1 - 0
src/thread/pthread_atfork.c

@@ -1,5 +1,6 @@
 #include <pthread.h>
 #include "libc.h"
+#include "lock.h"
 
 static struct atfork_funcs {
 	void (*prepare)(void);

+ 1 - 0
src/thread/pthread_create.c

@@ -2,6 +2,7 @@
 #include "pthread_impl.h"
 #include "stdio_impl.h"
 #include "libc.h"
+#include "lock.h"
 #include <sys/mman.h>
 #include <string.h>
 #include <stddef.h>

+ 1 - 0
src/thread/pthread_getschedparam.c

@@ -1,4 +1,5 @@
 #include "pthread_impl.h"
+#include "lock.h"
 
 int pthread_getschedparam(pthread_t t, int *restrict policy, struct sched_param *restrict param)
 {

+ 1 - 0
src/thread/pthread_kill.c

@@ -1,4 +1,5 @@
 #include "pthread_impl.h"
+#include "lock.h"
 
 int pthread_kill(pthread_t t, int sig)
 {

+ 1 - 0
src/thread/pthread_setschedparam.c

@@ -1,4 +1,5 @@
 #include "pthread_impl.h"
+#include "lock.h"
 
 int pthread_setschedparam(pthread_t t, int policy, const struct sched_param *param)
 {

+ 1 - 0
src/thread/pthread_setschedprio.c

@@ -1,4 +1,5 @@
 #include "pthread_impl.h"
+#include "lock.h"
 
 int pthread_setschedprio(pthread_t t, int prio)
 {

+ 1 - 1
src/thread/sem_open.c

@@ -11,7 +11,7 @@
 #include <sys/stat.h>
 #include <stdlib.h>
 #include <pthread.h>
-#include "libc.h"
+#include "lock.h"
 
 static struct {
 	ino_t ino;

+ 1 - 0
src/thread/synccall.c

@@ -7,6 +7,7 @@
 #include "futex.h"
 #include "atomic.h"
 #include "../dirent/__dirent.h"
+#include "lock.h"
 
 static struct chain {
 	struct chain *next;

+ 1 - 0
src/time/__tz.c

@@ -5,6 +5,7 @@
 #include <string.h>
 #include <sys/mman.h>
 #include "libc.h"
+#include "lock.h"
 
 long  __timezone = 0;
 int   __daylight = 0;