diff options
Diffstat (limited to 'include/litmus/locking.h')
-rw-r--r-- | include/litmus/locking.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/include/litmus/locking.h b/include/litmus/locking.h new file mode 100644 index 00000000000..968ba6fa828 --- /dev/null +++ b/include/litmus/locking.h | |||
@@ -0,0 +1,46 @@ | |||
1 | #ifndef LITMUS_LOCKING_H | ||
2 | #define LITMUS_LOCKING_H | ||
3 | |||
4 | #include <litmus/fdso.h> | ||
5 | |||
6 | struct litmus_lock_ops; | ||
7 | |||
8 | extern struct fdso_ops generic_lock_ops; | ||
9 | |||
10 | /* Generic base struct for LITMUS^RT userspace semaphores. | ||
11 | * This structure should be embedded in protocol-specific semaphores. | ||
12 | */ | ||
13 | struct litmus_lock { | ||
14 | struct litmus_lock_ops *ops; | ||
15 | int type; | ||
16 | }; | ||
17 | |||
18 | struct litmus_lock_ops { | ||
19 | /* Current task tries to obtain / drop a reference to a lock. | ||
20 | * Optional methods, allowed by default. */ | ||
21 | int (*open)(struct litmus_lock*, void* __user); | ||
22 | int (*close)(struct litmus_lock*); | ||
23 | |||
24 | /* Current tries to lock/unlock this lock (mandatory methods). */ | ||
25 | int (*lock)(struct litmus_lock*); | ||
26 | int (*unlock)(struct litmus_lock*); | ||
27 | |||
28 | int (*dynamic_group_lock)(struct litmus_lock*, resource_mask_t); | ||
29 | int (*dynamic_group_unlock)(struct litmus_lock*, resource_mask_t); | ||
30 | |||
31 | /* The lock is no longer being referenced (mandatory method). */ | ||
32 | void (*deallocate)(struct litmus_lock*); | ||
33 | }; | ||
34 | |||
35 | static inline bool is_lock(struct od_table_entry* entry) | ||
36 | { | ||
37 | return entry->class == &generic_lock_ops; | ||
38 | } | ||
39 | |||
40 | static inline struct litmus_lock* get_lock(struct od_table_entry* entry) | ||
41 | { | ||
42 | BUG_ON(!is_lock(entry)); | ||
43 | return (struct litmus_lock*) entry->obj->obj; | ||
44 | } | ||
45 | |||
46 | #endif | ||