diff libfdproto/sessions.c @ 778:003df4a9ade2

Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
author Sebastien Decugis <sdecugis@nict.go.jp>
date Sat, 21 Jan 2012 16:11:34 +0100
parents 4a9f08d6b6ba
children e780452c6b55
line wrap: on
line diff
--- a/libfdproto/sessions.c	Tue Nov 22 16:37:40 2011 -0800
+++ b/libfdproto/sessions.c	Sat Jan 21 16:11:34 2012 +0100
@@ -114,6 +114,8 @@
 #define H_LIST( _hash ) (&(sess_hash[H_MASK(_hash)].sentinel))
 #define H_LOCK( _hash ) (&(sess_hash[H_MASK(_hash)].lock    ))
 
+static uint32_t		sess_cnt = 0; /* counts all active session (that are in the expiry list) */
+
 /* The following are used to generate sid values that are eternaly unique */
 static uint32_t   	sid_h;	/* initialized to the current time in fd_sess_init */
 static uint32_t   	sid_l;	/* incremented each time a session id is created */
@@ -484,6 +486,7 @@
 			break;
 	}
 	fd_list_insert_after( li, &sess->expire );
+	sess_cnt++;
 
 	/* We added a new expiring element, we must signal */
 	if (li == &exp_sentinel) {
@@ -611,7 +614,10 @@
 	
 	/* Unlink from the expiry list */
 	CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } );
-	fd_list_unlink( &sess->expire ); /* no need to signal the condition here */
+	if (!FD_IS_LIST_EMPTY(&sess->expire)) {
+		sess_cnt--;
+		fd_list_unlink( &sess->expire ); /* no need to signal the condition here */
+	}
 	CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } );
 	
 	/* Now move all states associated to this session into deleted_states */
@@ -889,3 +895,12 @@
 	}
 	fd_log_debug("\t  %*s -- end of handler @%p --\n", level, "", handler);
 }	
+
+int fd_sess_getcount(uint32_t *cnt)
+{
+	CHECK_PARAMS(cnt);
+	CHECK_POSIX( pthread_mutex_lock( &exp_lock ) );
+	*cnt = sess_cnt;
+	CHECK_POSIX( pthread_mutex_unlock( &exp_lock ) );
+	return 0;
+}
"Welcome to our mercurial repository"