Subversion Repositories Kolibri OS

Rev

Rev 1964 | Rev 2161 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1616 serge 1
/*
2
 * Mutexes: blocking mutual exclusion locks
3
 *
4
 * started by Ingo Molnar:
5
 *
6
 *  Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar 
7
 *
8
 * This file contains the main data structure and API definitions.
9
 */
10
#ifndef __LINUX_MUTEX_H
11
#define __LINUX_MUTEX_H
12
 
13
#include 
14
#include 
15
 
16
/*
17
 * Simple, straightforward mutexes with strict semantics:
18
 *
19
 * - only one task can hold the mutex at a time
20
 * - only the owner can unlock the mutex
21
 * - multiple unlocks are not permitted
22
 * - recursive locking is not permitted
23
 * - a mutex object must be initialized via the API
24
 * - a mutex object must not be initialized via memset or copying
25
 * - task may not exit with mutex held
26
 * - memory areas where held locks reside must not be freed
27
 * - held mutexes must not be reinitialized
28
 * - mutexes may not be used in hardware or software interrupt
29
 *   contexts such as tasklets and timers
30
 *
31
 * These semantics are fully enforced when DEBUG_MUTEXES is
32
 * enabled. Furthermore, besides enforcing the above rules, the mutex
33
 * debugging code also implements a number of additional features
34
 * that make lock debugging easier and faster:
35
 *
36
 * - uses symbolic names of mutexes, whenever they are printed in debug output
37
 * - point-of-acquire tracking, symbolic lookup of function names
38
 * - list of all locks held in the system, printout of them
39
 * - owner tracking
40
 * - detects self-recursing locks and prints out all relevant info
41
 * - detects multi-task circular deadlocks and prints out all affected
42
 *   locks and tasks (and only those tasks)
43
 */
44
struct mutex {
45
	/* 1: unlocked, 0: locked, negative: locked, possible waiters */
1964 serge 46
	atomic_t		count;
1616 serge 47
	struct list_head	wait_list;
48
};
49
 
50
/*
51
 * This is the control structure for tasks blocked on mutex,
52
 * which resides on the blocked task's kernel stack:
53
 */
54
struct mutex_waiter {
55
	struct list_head	list;
56
    int                *task;
57
};
58
 
1967 serge 59
 
60
#define __MUTEX_INITIALIZER(lockname) \
61
                { .count = ATOMIC_INIT(1) \
62
                , .wait_list = LIST_HEAD_INIT(lockname.wait_list) }
63
 
64
#define DEFINE_MUTEX(mutexname) \
65
        struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
66
 
1616 serge 67
void __attribute__ ((fastcall)) __attribute__ ((dllimport))
68
     mutex_init(struct mutex*)__asm__("MutexInit");
69
void __attribute__ ((fastcall)) __attribute__ ((dllimport))
70
     mutex_lock(struct mutex*)__asm__("MutexLock");
71
void __attribute__ ((fastcall)) __attribute__ ((dllimport))
72
     mutex_unlock(struct mutex*)__asm__("MutexUnlock");
73
 
74
/**
75
 * mutex_is_locked - is the mutex locked
76
 * @lock: the mutex to be queried
77
 *
78
 * Returns 1 if the mutex is locked, 0 if unlocked.
79
 */
80
static inline int mutex_is_locked(struct mutex *lock)
81
{
82
	return atomic_read(&lock->count) != 1;
83
}
84
 
85
#endif