diff options
Diffstat (limited to 'pcilib/locking.h')
-rw-r--r-- | pcilib/locking.h | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/pcilib/locking.h b/pcilib/locking.h index 3727380..ae2f368 100644 --- a/pcilib/locking.h +++ b/pcilib/locking.h @@ -3,47 +3,46 @@ * @brief this file is the header file for functions that touch all locks allocated for software registers. * @details for more details about implementation choice, please read the file lock.h */ -#define _XOPEN_SOURCE 700 +#ifndef _PCILIB_LOCKING_H +#define _PCILIB_LOCKING_H -#ifndef _LOCKING_ -#define _LOCKING_ +#define PCILIB_MAX_LOCKS 64 /**< number of maximum locks*/ +#define PCILIB_LOCKS_PER_PAGE (PCILIB_KMEM_PAGE_SIZE/PCILIB_LOCK_SIZE) /**< number of locks per page of kernel memory */ +#define PCILIB_LOCK_PAGES ((PCILIB_MAX_LOCKS * PCILIB_LOCK_SIZE)/PCILIB_KMEM_PAGE_SIZE) /**< number of pages allocated for locks in kernel memory */ -#include <pthread.h> -/** number of maximum locks*/ -#define PCILIB_MAX_NUMBER_LOCKS 64 +#include <pcilib/kmem.h> +#include <pcilib/lock.h> -/**size of one lock, determine so the size of the protocol_name in the way locks are registered. 40 bytes are necessary for the mutex structure, so we have a protocol name of length LOCK_SIZE-40*/ -#define PCILIB_LOCK_SIZE 128 +typedef uint32_t pcilib_lock_id_t; -/** number of locks per page of kernel memory*/ -#define PCILIB_LOCKS_PER_PAGE PCILIB_KMEM_PAGE_SIZE/PCILIB_LOCK_SIZE +typedef struct pcilib_locking_s pcilib_locking_t; +struct pcilib_locking_s { + pcilib_kmem_handle_t *kmem; /**< kmem used to store mutexes */ + pcilib_lock_t *locking; /**< lock used while intializing other locks */ + pcilib_lock_t *mmap; /**< lock used to protect mmap operation */ +}; -/** number of pages allocated for locks in kernel memory*/ -#define PCILIB_NUMBER_OF_LOCK_PAGES (PCILIB_MAX_NUMBER_LOCKS*PCILIB_LOCK_SIZE)/PCILIB_KMEM_PAGE_SIZE +#ifdef __cplusplus +extern "C" { +#endif +int pcilib_init_locking(pcilib_t *ctx); +void pcilib_free_locking(pcilib_t *ctx); -/** -* new type to define a semaphore. It was made to differentiate from the library type. -*/ -typedef pthread_mutex_t pcilib_lock_t; +int pcilib_lock_global(pcilib_t *ctx); +void pcilib_unlock_global(pcilib_t *ctx); -/** - * this function destroy all locks created - *@param[in] ctx, the pcilib_t running - */ -void pcilib_clean_all_locks(pcilib_t* ctx); +pcilib_lock_t *pcilib_get_lock_by_id(pcilib_t *ctx, pcilib_lock_id_t id); -/** -* this function initialize the kmem pages containing locks -*@param[in] ctx the pcilib_t running -*/ -int pcilib_init_locking(pcilib_t* ctx, ...); +pcilib_lock_t *pcilib_get_lock(pcilib_t *ctx, pcilib_lock_flags_t flags, const char *lock_id, ...); +void pcilib_return_lock(pcilib_t *ctx, pcilib_lock_flags_t flags, pcilib_lock_t *lock); -/** - * this function destroys all locks and then free the kernel memory allocated for them before - * @param[in] ctx the pcilib_t running - */ -void pcilib_free_all_locks(pcilib_t* ctx); +int pcilib_destroy_all_locks(pcilib_t *ctx, int force); + + +#ifdef __cplusplus +} +#endif -#endif /* _LOCK_GLOBAL_ */ +#endif /* _PCILIB_LOCKING_H */ |