summaryrefslogtreecommitdiff
path: root/libddekit/lock.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2012-11-25 23:49:29 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2012-11-25 23:49:29 +0000
commit36318d1929e9437df0402a78ff63a70f78d6a89e (patch)
tree38588eaa8b400d7abf384a17e21dea75b104b177 /libddekit/lock.c
parenteaa21da4ea94937a1bc2157c042a233d524d17ce (diff)
parentd261675a592f6109826ccbdb07c7f485c4c88683 (diff)
Merge branch 'dde-upstream' into dde
Conflicts: dde_e100/Makefile dde_e1000/Makefile dde_ne2k_pci/Makefile dde_pcnet32/Makefile dde_rtl8139/Makefile
Diffstat (limited to 'libddekit/lock.c')
-rw-r--r--libddekit/lock.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/libddekit/lock.c b/libddekit/lock.c
index e534bebe..26d5cfc8 100644
--- a/libddekit/lock.c
+++ b/libddekit/lock.c
@@ -1,38 +1,39 @@
-#include <cthreads.h>
+#include <pthread.h>
#include "ddekit/lock.h"
#include "ddekit/memory.h"
+#include "ddekit/thread.h"
#define DDEKIT_DEBUG_LOCKS 0
struct ddekit_lock {
- struct mutex lock;
- cthread_t helder;
+ pthread_mutex_t lock;
+ ddekit_thread_t *helder;
};
void _ddekit_lock_init(struct ddekit_lock **mtx) {
struct ddekit_lock *lock;
lock = (struct ddekit_lock *) ddekit_simple_malloc (sizeof *lock);
- mutex_init (&lock->lock);
+ pthread_mutex_init (&lock->lock, NULL);
lock->helder = NULL;
*mtx = lock;
}
void _ddekit_lock_deinit(struct ddekit_lock **mtx) {
- mutex_free (*mtx);
+ ddekit_simple_free (*mtx);
*mtx = NULL;
}
void _ddekit_lock_lock(struct ddekit_lock **mtx) {
- mutex_lock (&(*mtx)->lock);
- (*mtx)->helder = cthread_self ();
+ pthread_mutex_lock (&(*mtx)->lock);
+ (*mtx)->helder = ddekit_thread_myself ();
}
/* returns 0 on success, != 0 if it would block */
int _ddekit_lock_try_lock(struct ddekit_lock **mtx) {
- if (mutex_try_lock (&(*mtx)->lock)) { /* lock succeessfully */
- (*mtx)->helder = cthread_self ();
+ if (!pthread_mutex_trylock (&(*mtx)->lock)) { /* lock succeessfully */
+ (*mtx)->helder = ddekit_thread_myself ();
return 0;
}
return -1;
@@ -41,7 +42,7 @@ int _ddekit_lock_try_lock(struct ddekit_lock **mtx) {
void _ddekit_lock_unlock(struct ddekit_lock **mtx) {
// TODO I wonder if it can cause any trouble.
(*mtx)->helder = NULL;
- mutex_unlock (&(*mtx)->lock);
+ pthread_mutex_unlock (&(*mtx)->lock);
}