Ver código fonte

- locking fixes

Andrei Pelinescu-Onciul 23 anos atrás
pai
commit
657a5566b2
4 arquivos alterados com 31 adições e 29 exclusões
  1. 16 14
      modules/tm/lock.c
  2. 10 10
      modules/tm/t_funcs.c
  3. 4 4
      modules/tm/timer.c
  4. 1 1
      modules/tm/timer.h

+ 16 - 14
modules/tm/lock.c

@@ -55,7 +55,6 @@ static int
 static int sem_nr;
 /* timer group locks */
 
-ser_lock_t timer_group_lock[TG_NR];
 
 
 /* return -1 if semget failed, -2 if semctl failed */
@@ -118,23 +117,30 @@ tryagain:
 #endif  /* !FAST_LOCK*/
 
 
+static ser_lock_t* timer_group_lock; /* pointer to a TG_NR lock array,
+								    it's safer if we alloc this in shared mem 
+									( required for fast lock ) */
 
 /* intitialize the locks; return 0 on success, -1 otherwise
 */
-#ifdef FAST_LOCK
-int lock_initialize()
-{
-	return 0;
-}
-#else
 int lock_initialize()
 {
 	int i;
+#ifndef FAST_LOCK
 	int probe_run;
+#endif
 
 	/* first try allocating semaphore sets with fixed number of semaphores */
 	DBG("DEBUG: lock_initialize: lock initialization started\n");
 
+	timer_group_lock=shm_malloc(TG_NR*sizeof(ser_lock_t));
+	if (timer_group_lock==0){
+		LOG(L_CRIT, "ERROR: lock_initialize: out of shm mem\n");
+		goto error;
+	}
+#ifdef FAST_LOCK
+	for(i=0;i<TG_NR;i++) init_lock(timer_group_lock[i]);
+#else
 	/* transaction timers */
 	if ((timer_semaphore= init_semaphore_set( TG_NR ) ) < 0) {
 		LOG(L_CRIT, "ERROR: lock_initialize:  "
@@ -234,13 +240,13 @@ again:
 
 	/* return success */
 	LOG(L_INFO, "INFO: semaphore arrays of size %d allocated\n", sem_nr );
+#endif /* FAST_LOCK*/
 	return 0;
 error:
 	lock_cleanup();
 	return -1;
 }
 
-#endif /*FAST_LOCK*/
 
 #ifdef FAST_LOCK
 void lock_cleanup()
@@ -281,7 +287,7 @@ void lock_cleanup()
 #endif /*FAST_LOCK*/
 
 
-/* lock sempahore s */
+/* lock semaphore s */
 #ifdef DBG_LOCK
 inline int _lock( ser_lock_t* s , char *file, char *function, unsigned int line )
 #else
@@ -351,17 +357,13 @@ int init_entry_lock( struct s_table* hash_table, struct entry *entry )
 
 int init_timerlist_lock( struct s_table* hash_table, enum lists timerlist_id)
 {
-#ifdef FAST_LOCK
-	init_lock(hash_table->timers[timerlist_id].mutex);
-#else
 	/* each timer list has its own semaphore */
 	/*
 	hash_table->timers[timerlist_id].mutex.semaphore_set=timer_semaphore;
 	hash_table->timers[timerlist_id].mutex.semaphore_index=timer_group[timerlist_id];
 	*/
 
-	hash_table->timers[timerlist_id].mutex=timer_group_lock[ timer_group[timerlist_id] ];
-#endif
+	hash_table->timers[timerlist_id].mutex=&(timer_group_lock[ timer_group[timerlist_id] ]);
 	return 0;
 }
 

+ 10 - 10
modules/tm/t_funcs.c

@@ -51,23 +51,23 @@ inline void set_timer( struct s_table *hash_table,
 	add_to_tail_of_timer_list( &(hash_table->timers[ list_id ]),
 		new_tl,get_ticks()+timeout);
 */
-	lock(&(list->mutex));
+	lock(list->mutex);
 	/* make sure I'm not already on a list */
 	remove_timer_unsafe( new_tl );
 	add_timer_unsafe( list, new_tl, get_ticks()+timeout);
-	unlock(&(list->mutex));
+	unlock(list->mutex);
 }
 
 /* remove from timer list */
 inline void reset_timer( struct s_table *hash_table,
 	struct timer_link* tl )
 {
-	/* lock(&(timer_group_lock[ tl->tg ])); */
+	/* lock(timer_group_lock[ tl->tg ]); */
 	/* hack to work arround this timer group thing*/
-	lock(&(hash_table->timers[timer_group[tl->tg]].mutex));
+	lock(hash_table->timers[timer_group[tl->tg]].mutex);
 	remove_timer_unsafe( tl );
-	unlock(&(hash_table->timers[timer_group[tl->tg]].mutex));
-	/*unlock(&(timer_group_lock[ tl->tg ]));*/
+	unlock(hash_table->timers[timer_group[tl->tg]].mutex);
+	/*unlock(timer_group_lock[ tl->tg ]);*/
 }
 
 static inline void reset_retr_timers( struct s_table *h_table,
@@ -79,23 +79,23 @@ static inline void reset_retr_timers( struct s_table *h_table,
 	DBG("DEBUG:stop_RETR_and_FR_timers : start \n");
 	/* lock the first timer list of the FR group -- all other
 	   lists share the same lock*/
-	lock(&(hash_table->timers[RT_T1_TO_1].mutex));
+	lock(hash_table->timers[RT_T1_TO_1].mutex);
 	remove_timer_unsafe( & p_cell->outbound_response.retr_timer );
 	for( ijk=0 ; ijk<(p_cell)->nr_of_outgoings ; ijk++ )  {
 			if ( rb = p_cell->outbound_request[ijk] ) {
 				remove_timer_unsafe( & rb->retr_timer );
 			}
 		}
-	unlock(&(hash_table->timers[RT_T1_TO_1].mutex));
+	unlock(hash_table->timers[RT_T1_TO_1].mutex);
 
-	lock(&(hash_table->timers[FR_TIMER_LIST].mutex));
+	lock(hash_table->timers[FR_TIMER_LIST].mutex);
 	remove_timer_unsafe( & p_cell->outbound_response.fr_timer );
 	for( ijk=0 ; ijk<(p_cell)->nr_of_outgoings ; ijk++ )  {
 			if ( rb = p_cell->outbound_request[ijk] ) {
 				remove_timer_unsafe( & rb->fr_timer );
 			}
 		}
-	unlock(&(hash_table->timers[FR_TIMER_LIST].mutex));
+	unlock(hash_table->timers[FR_TIMER_LIST].mutex);
 	DBG("DEBUG:stop_RETR_and_FR_timers : stop\n");
 }
 

+ 4 - 4
modules/tm/timer.c

@@ -63,7 +63,7 @@ void add_timer_unsafe( struct timer *timer_list,
 {
 	/*	remove_from_timer_list( tl ); */
 	/* the entire timer list is locked now -- noone else can manipulate it */
-	/* lock( &(timer_list->mutex) ); */
+	/* lock( timer_list->mutex ); */
 	tl->time_out = time_out;
 	tl->prev_tl = timer_list->last_tl.prev_tl;
 	tl->next_tl = & timer_list->last_tl;
@@ -77,7 +77,7 @@ void add_timer_unsafe( struct timer *timer_list,
 		}
 #	endif
 	/* give the list lock away */
-	/* unlock( &(timer_list->mutex) ); */
+	/* unlock( timer_list->mutex ); */
 	DBG("DEBUG: add_to_tail_of_timer[%d]: %p\n",timer_list->id,tl);
 }
 
@@ -95,7 +95,7 @@ struct timer_link  *check_and_split_time_list( struct timer *timer_list, int tim
 			return NULL;
 
 	/* the entire timer list is locked now -- noone else can manipulate it */
-	lock( &(timer_list->mutex) );
+	lock(timer_list->mutex);
 
 	end = &timer_list->last_tl;
 	tl = timer_list->first_tl.next_tl;
@@ -118,7 +118,7 @@ struct timer_link  *check_and_split_time_list( struct timer *timer_list, int tim
 	}
 
    /* give the list lock away */
-   unlock( &(timer_list->mutex) );
+   unlock(timer_list->mutex);
 
    return ret;
 }

+ 1 - 1
modules/tm/timer.h

@@ -46,7 +46,7 @@ typedef struct  timer
 {
    struct timer_link first_tl;
    struct timer_link last_tl;
-   ser_lock_t             mutex;
+   ser_lock_t*         mutex;
    enum lists id;
    void                      (*timeout_handler)(void*);
 } timer_type;