00001 #include <l4/dde/ddekit/lock.h>
00002 #include <l4/dde/ddekit/memory.h>
00003
00004 #include <l4/lock/lock.h>
00005 #include <l4/util/macros.h>
00006
00007 #define DDEKIT_DEBUG_LOCKS 0
00008
00009 struct ddekit_lock {
00010 l4lock_t lock;
00011 };
00012
00013 void _ddekit_lock_init(struct ddekit_lock **mtx) {
00014 *mtx = (struct ddekit_lock *) ddekit_simple_malloc(sizeof(struct ddekit_lock));
00015 (*mtx)->lock = L4LOCK_UNLOCKED;
00016 }
00017
00018 void _ddekit_lock_deinit(struct ddekit_lock **mtx) {
00019 ddekit_simple_free(*mtx);
00020 *mtx = NULL;
00021 }
00022
00023 void _ddekit_lock_lock(struct ddekit_lock **mtx) {
00024 #if DDEKIT_DEBUG_LOCKS
00025 if (&(*mtx)->lock == 0x35ac)
00026 LOG("DOWN %p: "l4util_idfmt" <-> "l4util_idfmt,
00027 &(*mtx)->lock,
00028 l4util_idstr(l4_myself()),
00029 l4util_idstr(l4thread_l4_id(l4lock_owner(&((*mtx)->lock)))));
00030 #endif
00031 l4lock_lock(&(*mtx)->lock);
00032 #if DDEKIT_DEBUG_LOCKS
00033 if (&(*mtx)->lock == 0x35ac)
00034 LOG("DOWN %p! "l4util_idfmt, &(*mtx)->lock, l4util_idstr(l4_myself()));
00035 #endif
00036 }
00037
00038
00039 int _ddekit_lock_try_lock(struct ddekit_lock **mtx) {
00040 return l4lock_try_lock(&(*mtx)->lock) ? 0 : 1;
00041 }
00042
00043 void _ddekit_lock_unlock(struct ddekit_lock **mtx) {
00044 #if DDEKIT_DEBUG_LOCKS
00045 if (&(*mtx)->lock == 0x35ac)
00046 LOG("UP %p: "l4util_idfmt" <-> "l4util_idfmt,
00047 &(*mtx)->lock,
00048 l4util_idstr(l4_myself()),
00049 l4util_idstr(l4thread_l4_id(l4lock_owner(&((*mtx)->lock)))));
00050 #endif
00051 l4lock_unlock(&(*mtx)->lock);
00052 #if DDEKIT_DEBUG_LOCKS
00053 if (&(*mtx)->lock == 0x35ac)
00054 LOG("UP %p! "l4util_idfmt, &(*mtx)->lock, l4util_idstr(l4_myself()));
00055 #endif
00056 }
00057
00058
00059 int _ddekit_lock_owner(struct ddekit_lock **mtx) {
00060 return (int)l4lock_owner(&(*mtx)->lock);
00061 }
00062