Module: kamailio
Branch: master
Commit: 2d117b8ce6ae97a7220369160b1eeb8b264bcac8
URL:
https://github.com/kamailio/kamailio/commit/2d117b8ce6ae97a7220369160b1eeb8…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-03-12T17:09:43+01:00
core: locking - added api functions for recursive lock sets
---
Modified: src/core/locking.c
Modified: src/core/locking.h
---
Diff:
https://github.com/kamailio/kamailio/commit/2d117b8ce6ae97a7220369160b1eeb8…
Patch:
https://github.com/kamailio/kamailio/commit/2d117b8ce6ae97a7220369160b1eeb8…
---
diff --git a/src/core/locking.c b/src/core/locking.c
index ebe4a9ab3c..fc267b008f 100644
--- a/src/core/locking.c
+++ b/src/core/locking.c
@@ -92,3 +92,65 @@ void rec_lock_release(rec_lock_t* rlock)
rlock->rec_lock_level--;
}
}
+
+/**
+ *
+ */
+rec_lock_set_t* rec_lock_set_alloc(int n)
+{
+ rec_lock_set_t* ls;
+ ls=(rec_lock_set_t*)shm_malloc(sizeof(rec_lock_set_t)+n*sizeof(rec_lock_t));
+ if (ls==0){
+ LM_CRIT("could not allocate rec_lock_set\n");
+ }else{
+ ls->locks=(rec_lock_t*)((char*)ls+sizeof(rec_lock_set_t));
+ ls->size=n;
+ }
+ return ls;
+ return NULL;
+}
+
+/**
+ *
+ */
+rec_lock_set_t* rec_lock_set_init(rec_lock_set_t* lset)
+{
+ int r;
+ for (r=0; r<lset->size; r++) if (rec_lock_init(&lset->locks[r])==0) return
0;
+ return lset;
+}
+
+/**
+ *
+ */
+void rec_lock_set_destroy(rec_lock_set_t* lset)
+{
+ return;
+}
+
+/**
+ *
+ */
+void rec_lock_set_dealloc(rec_lock_set_t* lset)
+{
+ shm_free((void*)lset);
+ return;
+}
+
+/**
+ *
+ */
+void rec_lock_set_get(rec_lock_set_t* lset, int i)
+{
+ rec_lock_get(&lset->locks[i]);
+ return;
+}
+
+/**
+ *
+ */
+void rec_lock_set_release(rec_lock_set_t* lset, int i)
+{
+ rec_lock_release(&lset->locks[i]);
+ return;
+}
\ No newline at end of file
diff --git a/src/core/locking.h b/src/core/locking.h
index c00e49e12b..1ae16d01de 100644
--- a/src/core/locking.h
+++ b/src/core/locking.h
@@ -84,4 +84,16 @@ void rec_lock_dealloc(rec_lock_t* lock);
void rec_lock_get(rec_lock_t* lock);
void rec_lock_release(rec_lock_t* lock);
+typedef struct rec_lock_set {
+ int size;
+ rec_lock_t *locks;
+} rec_lock_set_t;
+
+rec_lock_set_t* rec_lock_set_alloc(int n);
+rec_lock_set_t* rec_lock_set_init(rec_lock_set_t* lset);
+void rec_lock_set_destroy(rec_lock_set_t* lset);
+void rec_lock_set_dealloc(rec_lock_set_t* lset);
+void rec_lock_set_get(rec_lock_set_t* lset, int i);
+void rec_lock_set_release(rec_lock_set_t* lset, int i);
+
#endif