[sr-dev] git:master:96b84ba4: tm: disabled use of dedicated mutex for async continue

Daniel-Constantin Mierla miconda at gmail.com
Sun May 10 18:20:58 CEST 2015


Module: kamailio
Branch: master
Commit: 96b84ba4d7f5ee4a763fe7db81bbf4f9a6a3ef77
URL: https://github.com/kamailio/kamailio/commit/96b84ba4d7f5ee4a763fe7db81bbf4f9a6a3ef77

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-05-10T18:20:49+02:00

tm: disabled use of dedicated mutex for async continue

- it can be enabled by defining ENABLE_ASYNC_MUTEX
- reply mutex is re-entrant and protects better the transaction
  strucutre
- a dedicated lock for async continue exposes a race on removing from
  timer when suspended transaction is resument at the same time when the
  timer fires expiration event

---

Modified: modules/tm/h_table.h
Modified: modules/tm/lock.c
Modified: modules/tm/t_suspend.c
Modified: modules/tm/t_suspend.h

---

Diff:  https://github.com/kamailio/kamailio/commit/96b84ba4d7f5ee4a763fe7db81bbf4f9a6a3ef77.diff
Patch: https://github.com/kamailio/kamailio/commit/96b84ba4d7f5ee4a763fe7db81bbf4f9a6a3ef77.patch

---

diff --git a/modules/tm/h_table.h b/modules/tm/h_table.h
index 1838245..db35212 100644
--- a/modules/tm/h_table.h
+++ b/modules/tm/h_table.h
@@ -433,9 +433,11 @@ typedef struct cell
 	/* recursive reply lock count */
 	int reply_rec_lock_level;
 
+#ifdef ENABLE_ASYNC_MUTEX
 	/* protect against concurrent async continues */
 	ser_lock_t   async_mutex;
-		
+#endif
+
 	ticks_t fr_timeout;     /* final response interval for retr_bufs */
 	ticks_t fr_inv_timeout; /* final inv. response interval for retr_bufs */
 #ifdef TM_DIFF_RT_TIMEOUT
diff --git a/modules/tm/lock.c b/modules/tm/lock.c
index fdd0865..53c65b0 100644
--- a/modules/tm/lock.c
+++ b/modules/tm/lock.c
@@ -55,8 +55,10 @@
 static int sem_nr;
 gen_lock_set_t* entry_semaphore=0;
 gen_lock_set_t* reply_semaphore=0;
+#ifdef ENABLE_ASYNC_MUTEX
 gen_lock_set_t* async_semaphore=0;
 #endif
+#endif
 
 
 /* initialize the locks; return 0 on success, -1 otherwise
@@ -85,11 +87,12 @@ int lock_initialize()
 			lock_set_destroy(reply_semaphore);
 			lock_set_dealloc(reply_semaphore);
 		}
+#ifdef ENABLE_ASYNC_MUTEX
 		if (async_semaphore!=0){
 			lock_set_destroy(async_semaphore);
 			lock_set_dealloc(async_semaphore);
 		}
-		
+#endif
 		if (i==0){
 			LOG(L_CRIT, "lock_initialize: could not allocate semaphore"
 					" sets\n");
@@ -143,6 +146,7 @@ int lock_initialize()
 			i--;
 			goto again;
 	}
+#ifdef ENABLE_ASYNC_MUTEX
 	i++;
 	if (((async_semaphore=lock_set_alloc(i))==0)||
 		(lock_set_init(async_semaphore)==0)){
@@ -156,7 +160,7 @@ int lock_initialize()
 			i--;
 			goto again;
 	}
-	
+#endif
 
 	/* return success */
 	LOG(L_INFO, "INFO: semaphore arrays of size %d allocated\n", sem_nr );
@@ -196,11 +200,14 @@ void lock_cleanup()
 		lock_set_destroy(reply_semaphore);
 		lock_set_dealloc(reply_semaphore);
 	};
+#ifdef ENABLE_ASYNC_MUTEX
 	if (async_semaphore !=0) {
 		lock_set_destroy(async_semaphore);
 		lock_set_dealloc(async_semaphore);
-	};
-	entry_semaphore =  reply_semaphore = async_semaphore = 0;
+	}
+	async_semaphore = 0;
+#endif
+	entry_semaphore =  reply_semaphore = 0;
 
 }
 #endif /*GEN_LOCK_T_PREFERED*/
@@ -238,12 +245,17 @@ int init_entry_lock( struct s_table* ht, struct entry *entry )
 
 int init_async_lock( struct cell *cell )
 {
+#ifdef ENABLE_ASYNC_MUTEX
+
 #ifdef GEN_LOCK_T_PREFERED
 	lock_init(&cell->async_mutex);
 #else
 	cell->async_mutex.semaphore_set=async_semaphore;
 	cell->async_mutex.semaphore_index = cell->hash_index % sem_nr;
 #endif /* GEN_LOCK_T_PREFERED */
+
+#endif /* ENABLE_ASYNC_MUTEX */
+
 	return 0;
 }
 
diff --git a/modules/tm/t_suspend.c b/modules/tm/t_suspend.c
index 3fa8f2e..c4887cd 100644
--- a/modules/tm/t_suspend.c
+++ b/modules/tm/t_suspend.c
@@ -38,6 +38,15 @@
 #include "../../data_lump.h"
 #include "../../data_lump_rpl.h"
 
+
+#ifdef ENABLE_ASYNC_MUTEX
+#define LOCK_ASYNC_CONTINUE(_t) lock(&(_t)->async_mutex )
+#define UNLOCK_ASYNC_CONTINUE(_t) unlock(&(_t)->async_mutex )
+#else
+#define LOCK_ASYNC_CONTINUE(_t) LOCK_REPLIES(_t)
+#define UNLOCK_ASYNC_CONTINUE(_t) UNLOCK_REPLIES(_t)
+#endif
+
 /* Suspends the transaction for later use.
  * Save the returned hash_index and label to get
  * back to the SIP request processing, see the readme.
diff --git a/modules/tm/t_suspend.h b/modules/tm/t_suspend.h
index dfe79e0..df19f22 100644
--- a/modules/tm/t_suspend.h
+++ b/modules/tm/t_suspend.h
@@ -22,9 +22,6 @@
 #ifndef _T_SUSPEND_H
 #define _T_SUSPEND_H
 
-#define LOCK_ASYNC_CONTINUE(_t) lock(&(_t)->async_mutex )
-#define UNLOCK_ASYNC_CONTINUE(_t) unlock(&(_t)->async_mutex )
-
 int t_suspend(struct sip_msg *msg,
 		unsigned int *hash_index, unsigned int *label);
 typedef int (*t_suspend_f)(struct sip_msg *msg,




More information about the sr-dev mailing list