blob: f42b25c3f622e1a5cb4755a2386c25a2fef8626d [file] [log] [blame]
David Kiliani3fedd142008-11-01 00:39:12 +01001/**
2 * @file meslock.h
3 *
4 * @brief Provides the subdevice lock class.
5 * @note Copyright (C) 2006 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
7 */
8
9#ifndef _MESLOCK_H_
10#define _MESLOCK_H_
11
12#include <linux/spinlock.h>
13
14#ifdef __KERNEL__
15
16/**
17 * @brief The subdevice lock class.
18 */
19typedef struct me_slock {
20 struct file *filep; /**< Pointer to file structure holding the subdevice. */
21 int count; /**< Number of tasks which are inside the subdevice. */
22 spinlock_t spin_lock; /**< Spin lock protecting the attributes from concurrent access. */
23} me_slock_t;
24
25/**
26 * @brief Tries to enter a subdevice.
27 *
28 * @param slock The subdevice lock instance.
29 * @param filep The file structure identifying the calling process.
30 *
31 * @return 0 on success.
32 */
33int me_slock_enter(struct me_slock *slock, struct file *filep);
34
35/**
36 * @brief Exits a subdevice.
37 *
38 * @param slock The subdevice lock instance.
39 * @param filep The file structure identifying the calling process.
40 *
41 * @return 0 on success.
42 */
43int me_slock_exit(struct me_slock *slock, struct file *filep);
44
45/**
46 * @brief Tries to perform a locking action on a subdevice.
47 *
48 * @param slock The subdevice lock instance.
49 * @param filep The file structure identifying the calling process.
50 * @param The action to be done.
51 *
52 * @return 0 on success.
53 */
54int me_slock_lock(struct me_slock *slock, struct file *filep, int lock);
55
56/**
57 * @brief Initializes a lock structure.
58 *
59 * @param slock The lock structure to initialize.
60 * @return 0 on success.
61 */
62int me_slock_init(me_slock_t * slock);
63
64/**
65 * @brief Deinitializes a lock structure.
66 *
67 * @param slock The lock structure to deinitialize.
68 * @return 0 on success.
69 */
70void me_slock_deinit(me_slock_t * slock);
71
72#endif
73#endif