summaryrefslogtreecommitdiff
path: root/mutex_helpers.c
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-07-20 14:01:01 +0200
committerKevin Chabowski <kevin@kch42.de>2013-07-20 14:01:01 +0200
commit8e6850107adb5ca37ed0e9a4500282b2e8743294 (patch)
treeccd4ef7d03e79a5c9f32359f643275cdd27eb67c /mutex_helpers.c
parent2992a3f013aaa833f2c72ef1e368a9752b2bb889 (diff)
downloadnebula2-8e6850107adb5ca37ed0e9a4500282b2e8743294.tar.gz
nebula2-8e6850107adb5ca37ed0e9a4500282b2e8743294.tar.bz2
nebula2-8e6850107adb5ca37ed0e9a4500282b2e8743294.zip
Rough structure done. Parallel working should work.
Diffstat (limited to 'mutex_helpers.c')
-rw-r--r--mutex_helpers.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/mutex_helpers.c b/mutex_helpers.c
new file mode 100644
index 0000000..e390316
--- /dev/null
+++ b/mutex_helpers.c
@@ -0,0 +1,30 @@
+#include <stdlib.h>
+#include <pthread.h>
+
+/* Creating a locked mutex */
+pthread_mutex_t*
+mutex_create() {
+ pthread_mutex_t* mu;
+
+ if(!(mu = malloc(sizeof(pthread_mutex_t)))) {
+ return NULL;
+ }
+
+ if(pthread_mutex_init(mu, NULL) != 0) {
+ free(mu);
+ return NULL;
+ }
+
+ pthread_mutex_trylock(mu);
+
+ return mu;
+}
+
+/* Destroy a mutex created by mutex_create */
+void
+mutex_destroy(pthread_mutex_t* mu) {
+ if(mu) {
+ pthread_mutex_unlock(mu);
+ pthread_mutex_destroy(mu);
+ }
+}