14
14
#include <pcilib/kmem.h>
15
15
#include <pcilib/lock.h>
17
typedef uint32_t pcilib_lock_id_t;
17
typedef uint32_t pcilib_lock_id_t; /**< type to represent the index of a lock in the table of locks in the kernel space*/
19
19
typedef struct pcilib_locking_s pcilib_locking_t;
22
* structure defining the kernel space used for locks
20
24
struct pcilib_locking_s {
21
pcilib_kmem_handle_t *kmem; /**< kmem used to store mutexes */
22
pcilib_lock_t *locking; /**< lock used while intializing other locks */
23
// pcilib_lock_t *mmap; /**< lock used to protect mmap operation */
25
pcilib_kmem_handle_t *kmem; /**< kmem used to store mutexes */
26
pcilib_lock_t *locking; /**< lock used while intializing kernel space */
27
// pcilib_lock_t *mmap; /**< lock used to protect mmap operation */
35
*this function gets the kernel space for the locks : if this space have been already initialized, then the previous space is returned. If not, the space is created. this function has to be protected, in order to avoid the simultaneous creation of 2 kernel spaces. For that, we use pcilib_lock_global.
36
*@param[in,out] ctx - the pcilib_t structure running, getting filled with a ref to locks' kernel space
30
38
int pcilib_init_locking(pcilib_t *ctx);
41
*this function cleans the memory from all locks : the kernel space is freed, and locks references in pcilib_t are destroyed by setting memory to 0
42
*@param[in,out] ctx - the pcilib_t structure running
31
44
void pcilib_free_locking(pcilib_t *ctx);
47
* this function use flock locking mechanism on the ALPS platform device file, to make sure to not create two kernel spaces for locks
48
*@param[in,out] ctx - the pcilib_t structure running
33
50
int pcilib_lock_global(pcilib_t *ctx);
53
*function to remove the lock created by flock on the ALPS platform device file
54
*@param[in,out] ctx - the pcilib_t structure running
34
56
void pcilib_unlock_global(pcilib_t *ctx);
59
* this function returns the lock at the index in the kernel space equal to id
60
*@param[in] ctx - the pcilib_t structure running
61
*@param[in] id - the index of the lock
62
*@return the lock structure corresponding
36
64
pcilib_lock_t *pcilib_get_lock_by_id(pcilib_t *ctx, pcilib_lock_id_t id);
67
*this function verify if the lock requested exists in the kernel space. If yes, then nothing is done, else we create the lock in the kernel space. This function also gives the number of processes that may request the lock afterwards, including the one that just created it.
68
*@param[in] ctx - the pcilib_t structure running
69
*@param[in] flags - the flag defining the property of the lock
70
*@param[in@ lock_id - the identifier name for the lock
71
*@return the corresponding lock, or a new one if it did not exist before
38
73
pcilib_lock_t *pcilib_get_lock(pcilib_t *ctx, pcilib_lock_flags_t flags, const char *lock_id, ...);
76
*this function is to decrement the variable in a lock containing the number of processes that may access to this lock(refs)
77
*@param[in] ctx - the pcilib_t structure running
78
*@param[in] flags - the flag defining the property of the lock
79
*@param[in] lock - pointer to the lock we want to modify
39
81
void pcilib_return_lock(pcilib_t *ctx, pcilib_lock_flags_t flags, pcilib_lock_t *lock);
84
* this function destroy all the locks that have been created(unref the locks + set memory to 0), and so is used when we want to clean properly the kernel space. If force is set to 1, then we don't care about other processes that may request locks. If not, if there is locks that may be requested by other processes, then the operation is stopped. Of course, destroying locks that may be requested by other processes results in an undefined behaviour. Thus, it is user responsibility to issue this command with force set to 1
85
*@param[in,out] ctx - the pcilib_t structure running
86
*@param[in] force - should the operation be forced or not
87
* @return error code : 0 if everything was ok
41
89
int pcilib_destroy_all_locks(pcilib_t *ctx, int force);