summaryrefslogtreecommitdiffstats
path: root/pcilib/locking.h
diff options
context:
space:
mode:
authorzilio nicolas <nicolas.zilio@kit.edu>2015-07-07 11:12:52 +0200
committerzilio nicolas <nicolas.zilio@kit.edu>2015-07-07 11:12:52 +0200
commitf923add0a9b6bd17d43f72c21eec4e01e19240cf (patch)
tree8f737e8bd5faa360dfef5b33c52a0f58679c4b8d /pcilib/locking.h
parente2515f6e1a7b17addda4c558a0a6ca05b4ec6e55 (diff)
downloadpcitool-f923add0a9b6bd17d43f72c21eec4e01e19240cf.tar.gz
pcitool-f923add0a9b6bd17d43f72c21eec4e01e19240cf.tar.bz2
pcitool-f923add0a9b6bd17d43f72c21eec4e01e19240cf.tar.xz
pcitool-f923add0a9b6bd17d43f72c21eec4e01e19240cf.zip
clean version for locks
Diffstat (limited to 'pcilib/locking.h')
-rw-r--r--pcilib/locking.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/pcilib/locking.h b/pcilib/locking.h
new file mode 100644
index 0000000..f7570f6
--- /dev/null
+++ b/pcilib/locking.h
@@ -0,0 +1,44 @@
+/**
+ * @file lock_global.h
+ * @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 _LOCKING_
+#define _LOCKING_
+
+#include <pthread.h>
+
+/** number of maximum locks*/
+#define PCILIB_MAX_NUMBER_LOCKS 64
+
+/**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
+
+#define PCILIB_LOCKS_PER_PAGE PCILIB_KMEM_PAGE_SIZE/PCILIB_LOCK_SIZE
+
+#define PCILIB_NUMBER_OF_LOCK_PAGES (PCILIB_MAX_NUMBER_LOCKS*PCILIB_LOCK_SIZE)/PCILIB_KMEM_PAGE_SIZE
+
+
+/**
+* new type to define a semaphore. It was made to differentiate from the library type.
+*/
+typedef pthread_mutex_t pcilib_lock_t;
+
+/**
+ * this function destroy all locks created
+ *@param[in] ctx, the pcilib_t running
+ */
+void pcilib_clean_all_locks(pcilib_t* ctx);
+
+/**
+* this function initialize the kmem pages containing locks
+*@param[in] ctx the pcilib_t running
+*/
+int pcilib_init_locking(pcilib_t* ctx, ...);
+
+
+void pcilib_free_all_locks(pcilib_t* ctx);
+
+#endif /* _LOCK_GLOBAL_ */