2 * This file is part of DDEKit.
4 * (c) 2006-2012 Bjoern Doebel <doebel@os.inf.tu-dresden.de>
5 * Christian Helmuth <ch12@os.inf.tu-dresden.de>
6 * Thomas Friebel <tf13@os.inf.tu-dresden.de>
7 * economic rights: Technische Universitaet Dresden (Germany)
9 * This file is part of TUD:OS and distributed under the terms of the
10 * GNU General Public License 2.
11 * Please see the COPYING-GPL-2 file for details.
14 #include <l4/dde/ddekit/lock.h>
15 #include <l4/dde/ddekit/memory.h>
16 #include <l4/dde/ddekit/panic.h>
17 #include <l4/dde/ddekit/assert.h>
19 #include <pthread-l4.h> // pthread_l4_cap
20 #include <bits/pthreadtypes.h> // mutex->__m_owner
22 #include "internals.h"
24 #define DDEKIT_DEBUG_LOCKS 1
26 void ddekit_lock_init (ddekit_lock_t *mtx)
28 *mtx = ddekit_simple_malloc(sizeof(struct ddekit_lock));
29 Assert(pthread_mutex_init(&(*mtx)->mtx, NULL) == 0);
33 void ddekit_lock_deinit (ddekit_lock_t *mtx)
35 pthread_mutex_destroy(&(*mtx)->mtx);
36 ddekit_simple_free(*mtx);
40 void ddekit_lock_lock (ddekit_lock_t *mtx)
42 int ret = pthread_mutex_lock(&(*mtx)->mtx);
47 int ddekit_lock_try_lock(ddekit_lock_t *mtx)
49 return pthread_mutex_trylock(&(*mtx)->mtx);
53 void ddekit_lock_unlock (ddekit_lock_t *mtx)
55 int ret = pthread_mutex_unlock(&(*mtx)->mtx);
60 int ddekit_lock_owner(ddekit_lock_t *mtx)
62 return (int)((*mtx)->mtx.__m_owner);
66 int ddekit_lock_is_locked(ddekit_lock_t *mtx)
68 return (*mtx)->mtx.__m_lock.__status;