summaryrefslogtreecommitdiffstats
path: root/pcilib/locking.c
diff options
context:
space:
mode:
Diffstat (limited to 'pcilib/locking.c')
-rw-r--r--pcilib/locking.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/pcilib/locking.c b/pcilib/locking.c
index 1d6b51e..cbe9533 100644
--- a/pcilib/locking.c
+++ b/pcilib/locking.c
@@ -7,12 +7,13 @@
#include "lock.h"
/*
- * this function clean all locks created by the pcitool program
+ * this function destroys all locks without touching at kernel memory directly
*/
void pcilib_clean_all_locks(pcilib_t* ctx){
int i,j;
void* addr;
i=0;
+ /* iteration on all locks*/
while(i<PCILIB_NUMBER_OF_LOCK_PAGES){
addr=pcilib_kmem_get_block_ua(ctx,ctx->locks_handle,i);
for(j=0;j<PCILIB_LOCKS_PER_PAGE;j++)
@@ -22,6 +23,9 @@ for(j=0;j<PCILIB_LOCKS_PER_PAGE;j++)
}
+/*
+ * this functions destroy all locks and then free the kernel memory allocated for them
+ */
void pcilib_free_locking(pcilib_t* ctx){
pcilib_clean_all_locks(ctx);
pcilib_free_kernel_memory(ctx,ctx->locks_handle,PCILIB_KMEM_FLAG_REUSE);
@@ -38,8 +42,9 @@ int pcilib_init_locking(pcilib_t* ctx, ...){
int err;
pcilib_kmem_reuse_state_t reused;
-
+ /* we flock() to make sure to not have two initialization in the same time (possible long time to init)*/
if((err=flock(ctx->handle,LOCK_EX))==-1) pcilib_warning("can't get flock on /dev/fpga0");
+
handle=pcilib_alloc_kernel_memory(ctx,PCILIB_KMEM_TYPE_PAGE,PCILIB_NUMBER_OF_LOCK_PAGES,PCILIB_KMEM_PAGE_SIZE,0,PCILIB_KMEM_USE(PCILIB_KMEM_USE_MUTEXES,0),PCILIB_KMEM_FLAG_REUSE|PCILIB_KMEM_FLAG_PERSISTENT);
if (!handle) {
@@ -49,10 +54,11 @@ int pcilib_init_locking(pcilib_t* ctx, ...){
ctx->locks_handle=handle;
reused = pcilib_kmem_is_reused(ctx, handle);
- #define DEBUG_REUSE
+//#define DEBUG_REUSE
#ifdef DEBUG_REUSE
reused=0;
#endif
+/* verification about the handling memory got, first use or not, and integrity*/
if ((reused & PCILIB_KMEM_REUSE_REUSED) == 0) {
pcilib_register_t i;
@@ -61,10 +67,11 @@ reused=0;
pcilib_clean_all_locks(ctx);
return 1;
}
+ /* if we get here so this is the first initialization (after some free or new), we so set kernel pages to 0 and initialize then the first lock that will be used when we create other locks*/
for(i=0;i<PCILIB_NUMBER_OF_LOCK_PAGES;i++){
memset(pcilib_kmem_get_block_ua(ctx,handle,i),0,PCILIB_KMEM_PAGE_SIZE);
}
- pcilib_init_lock(ctx,"pcilib_locking",LOCK_INIT);
+ pcilib_init_lock(ctx,PCILIB_NO_LOCK,"%s","pcilib_first_locking");
}