aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis R. Rodriguez <mcgrof@kernel.org>2016-06-03 09:01:37 -0700
committerLuis R. Rodriguez <mcgrof@kernel.org>2016-06-23 15:23:28 -0700
commit98ce492a9086da1206d3db3a4f0103961ae8740c (patch)
tree66d96477f62a5e892a1b044f94d0257df6d0852d
parentc3b7dd5ca162075327a1f6e9677e802844bf00f7 (diff)
downloadlinker-tables-98ce492a9086da1206d3db3a4f0103961ae8740c.tar.gz
mutex: add initial mutex support
We'll later use this to peg __sched, which will be our first example subsection to test with linker tables. Before we do the work to pget mutext to __sched we'll add a bit more kernel interface support to make things a bit more interesting and useful to test. This a simple mutex implementation which just wraps around the pthread pthread_mutex_t. Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
-rw-r--r--Makefile2
-rw-r--r--include/linux/mutex.h15
-rw-r--r--kernel/locking/mutex.c26
3 files changed, 43 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index d69aa28..8282f3e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
CFLAGS += -O2 -g
CFLAGS += -std=gnu99 -Wall -Werror
+CFLAGS += -pthread
CFLAGS += -DCONFIG_KPROBES
INCLUDES = -I include/ -I arch/x86/include/
CFLAGS += $(INCLUDES)
@@ -43,6 +44,7 @@ OBJS = arch/x86/kernel/sort-init.o \
memory.o \
kasan.o\
arch/x86/kernel/init.o \
+ kernel/locking/mutex.o \
kprobes.o \
pci.o \
pci-quirks.o \
diff --git a/include/linux/mutex.h b/include/linux/mutex.h
new file mode 100644
index 0000000..f8134ec
--- /dev/null
+++ b/include/linux/mutex.h
@@ -0,0 +1,15 @@
+#ifndef __LINUX_MUTEX_H
+#define __LINUX_MUTEX_H
+
+#include <pthread.h>
+
+struct mutex {
+ pthread_mutex_t lock;
+};
+
+void mutex_init(struct mutex *lock);
+void mutex_destroy(struct mutex *lock);
+void mutex_lock(struct mutex *lock);
+void mutex_unlock(struct mutex *lock);
+
+#endif /* __LINUX_MUTEX_H */
diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
new file mode 100644
index 0000000..21e6212
--- /dev/null
+++ b/kernel/locking/mutex.c
@@ -0,0 +1,26 @@
+#include <linux/kernel.h>
+#include <linux/mutex.h>
+
+void mutex_init(struct mutex *lock)
+{
+ int r;
+
+ r = pthread_mutex_init(&lock->lock, NULL);
+ if (r)
+ BUG_ON(r);
+}
+
+void mutex_destroy(struct mutex *lock)
+{
+ pthread_mutex_destroy(&lock->lock);
+}
+
+void mutex_lock(struct mutex *lock)
+{
+ pthread_mutex_lock(&lock->lock);
+}
+
+void mutex_unlock(struct mutex *lock)
+{
+ pthread_mutex_unlock(&lock->lock);
+}