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

Subversion Repositories c0or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#ifndef __LIB_SPINLOCK_H__
2
#define __LIB_SPINLOCK_H__
3
 
4
#include <l4/lib/string.h>
5
#include <l4/generic/preempt.h>
6
#include INC_ARCH(irq.h)
7
#include INC_ARCH(mutex.h)
8
 
9
struct spinlock {
10
        unsigned int lock;
11
};
12
 
13
#define DECLARE_SPINLOCK(lockname)      \
14
        struct spinlock lockname = {    \
15
                .lock = 0,               \
16
        }
17
 
18
void spin_lock_record_check(void *lock_addr);
19
void spin_unlock_delete_check(void *lock_addr);
20
 
21
static inline void spin_lock_init(struct spinlock *s)
22
{
23
        memset(s, 0, sizeof(struct spinlock));
24
}
25
 
26
/*
27
 * - Guards from deadlock against local processes, but not local irqs.
28
 * - To be used for synchronising against processes on *other* cpus.
29
 */
30
static inline void spin_lock(struct spinlock *s)
31
{
32
        preempt_disable();      /* This must disable local preempt */
33
#if defined(CONFIG_SMP)
34
 
35
#if defined (CONFIG_DEBUG_SPINLOCKS)
36
        spin_lock_record_check(s);
37
#endif
38
        __spin_lock(&s->lock);
39
#endif
40
}
41
 
42
static inline void spin_unlock(struct spinlock *s)
43
{
44
#if defined(CONFIG_SMP)
45
 
46
#if defined (CONFIG_DEBUG_SPINLOCKS)
47
        spin_unlock_delete_check(s);
48
#endif
49
        __spin_unlock(&s->lock);
50
#endif
51
        preempt_enable();
52
}
53
 
54
/*
55
 * - Guards from deadlock against local processes *and* local irqs.
56
 * - To be used for synchronising against processes and irqs
57
 *   on other cpus.
58
 */
59
static inline void spin_lock_irq(struct spinlock *s,
60
                                 unsigned long *state)
61
{
62
        irq_local_disable_save(state);
63
#if defined(CONFIG_SMP)
64
#if defined (CONFIG_DEBUG_SPINLOCKS)
65
        spin_lock_record_check(s);
66
#endif
67
 
68
        __spin_lock(&s->lock);
69
#endif
70
}
71
 
72
static inline void spin_unlock_irq(struct spinlock *s,
73
                                   unsigned long state)
74
{
75
#if defined(CONFIG_SMP)
76
 
77
#if defined (CONFIG_DEBUG_SPINLOCKS)
78
        spin_unlock_delete_check(s);
79
#endif
80
 
81
        __spin_unlock(&s->lock);
82
#endif
83
        irq_local_restore(state);
84
}
85
#endif /* __LIB__SPINLOCK_H__ */

powered by: WebSVN 2.1.0

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