OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [include/] [l4/] [lib/] [mutex.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * The elementary concurrency constructs.
3
 *
4
 * Copyright (C) 2007 Bahadir Balban
5
 */
6
 
7
#ifndef __LIB_MUTEX_H__
8
#define __LIB_MUTEX_H__
9
 
10
#include <l4/lib/string.h>
11
#include <l4/lib/spinlock.h>
12
#include <l4/lib/list.h>
13
#include <l4/lib/printk.h>
14
#include <l4/lib/wait.h>
15
#include INC_ARCH(mutex.h)
16
 
17
/* A mutex is a binary semaphore that can sleep. */
18
struct mutex {
19
        struct waitqueue_head wqh;
20
        unsigned int lock;
21
};
22
 
23
static inline void mutex_init(struct mutex *mutex)
24
{
25
        memset(mutex, 0, sizeof(struct mutex));
26
        waitqueue_head_init(&mutex->wqh);
27
}
28
 
29
int mutex_trylock(struct mutex *mutex);
30
int mutex_lock(struct mutex *mutex);
31
void mutex_unlock(struct mutex *mutex);
32
void mutex_unlock_async(struct mutex *mutex);
33
 
34
/* NOTE: Since spinlocks guard mutex acquiring & sleeping, no locks needed */
35
static inline int mutex_inc(unsigned int *cnt)
36
{
37
        return ++*cnt;
38
}
39
 
40
static inline int mutex_dec(unsigned int *cnt)
41
{
42
        return --*cnt;
43
}
44
 
45
#endif /* __LIB_MUTEX_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.