• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file medlock.h
3  *
4  * @brief Provides the device lock class.
5  * @note Copyright (C) 2006 Meilhaus Electronic GmbH (support@meilhaus.de)
6  * @author Guenter Gebhardt
7  */
8 
9 #ifndef _MEDLOCK_H_
10 #define _MEDLOCK_H_
11 
12 #include <linux/spinlock.h>
13 
14 #ifdef __KERNEL__
15 
16 /**
17  * @brief The device lock class.
18  */
19 typedef struct me_dlock {
20 	struct file *filep;		/**< Pointer to file structure holding the device. */
21 	int count;				/**< Number of tasks which are inside the device. */
22 	spinlock_t spin_lock;	/**< Spin lock protecting the attributes from concurrent access. */
23 } me_dlock_t;
24 
25 /**
26  * @brief Tries to enter a device.
27  *
28  * @param dlock The device lock instance.
29  * @param filep The file structure identifying the calling process.
30  *
31  * @return 0 on success.
32  */
33 int me_dlock_enter(struct me_dlock *dlock, struct file *filep);
34 
35 /**
36  * @brief Exits a device.
37  *
38  * @param dlock The device lock instance.
39  * @param filep The file structure identifying the calling process.
40  *
41  * @return 0 on success.
42  */
43 int me_dlock_exit(struct me_dlock *dlock, struct file *filep);
44 
45 /**
46  * @brief Tries to perform a locking action on a device.
47  *
48  * @param dlock The device lock instance.
49  * @param filep The file structure identifying the calling process.
50  * @param The action to be done.
51  * @param flags Flags from user space.
52  * @param slist The subdevice list of the device.
53  *
54  * @return 0 on success.
55  */
56 int me_dlock_lock(struct me_dlock *dlock,
57 		  struct file *filep, int lock, int flags, me_slist_t * slist);
58 
59 /**
60  * @brief Initializes a lock structure.
61  *
62  * @param dlock The lock structure to initialize.
63  * @return 0 on success.
64  */
65 int me_dlock_init(me_dlock_t * dlock);
66 
67 /**
68  * @brief Deinitializes a lock structure.
69  *
70  * @param dlock The lock structure to deinitialize.
71  * @return 0 on success.
72  */
73 void me_dlock_deinit(me_dlock_t * dlock);
74 
75 #endif
76 #endif
77