Ver código fonte

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
Daniel-Constantin Mierla 10 anos atrás
pai
commit
96b84ba4d7
4 arquivos alterados com 28 adições e 8 exclusões
  1. 3 1
      modules/tm/h_table.h
  2. 16 4
      modules/tm/lock.c
  3. 9 0
      modules/tm/t_suspend.c
  4. 0 3
      modules/tm/t_suspend.h

+ 3 - 1
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

+ 16 - 4
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 @@ again:
 			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 @@ again:
 			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 @@ again:
 			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;
 }
 

+ 9 - 0
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.

+ 0 - 3
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,