Mercurial > hg > freeDiameter
comparison libfreeDiameter/sessions.c @ 557:85ab58cc427c
Committed this by error
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 15 Sep 2010 18:34:17 +0900 |
parents | 8c9028ec02bf |
children | 95a784729cac |
comparison
equal
deleted
inserted
replaced
556:8c9028ec02bf | 557:85ab58cc427c |
---|---|
91 int eyec; /* Eyecatcher, SI_EYEC */ | 91 int eyec; /* Eyecatcher, SI_EYEC */ |
92 | 92 |
93 char * sid; /* The \0-terminated Session-Id */ | 93 char * sid; /* The \0-terminated Session-Id */ |
94 uint32_t hash; /* computed hash of sid */ | 94 uint32_t hash; /* computed hash of sid */ |
95 struct fd_list chain_h;/* chaining in the hash table of sessions. */ | 95 struct fd_list chain_h;/* chaining in the hash table of sessions. */ |
96 int rc; /* Reference counter on this object, freed only when it reaches 0. */ | |
97 | 96 |
98 struct timespec timeout;/* Timeout date for the session */ | 97 struct timespec timeout;/* Timeout date for the session */ |
99 struct fd_list expire; /* List of expiring sessions, ordered by timeouts. */ | 98 struct fd_list expire; /* List of expiring sessions, ordered by timeouts. */ |
100 | 99 |
101 pthread_mutex_t stlock; /* A lock to protect the list of states associated with this session */ | 100 pthread_mutex_t stlock; /* A lock to protect the list of states associated with this session */ |
102 struct fd_list states; /* Sentinel for the list of states of this session. */ | 101 struct fd_list states; /* Sentinel for the list of states of this session. */ |
102 int msg_cnt;/* Reference counter for the messages pointing to this session */ | |
103 }; | 103 }; |
104 | 104 |
105 /* Sessions hash table, to allow fast sid to session retrieval */ | 105 /* Sessions hash table, to allow fast sid to session retrieval */ |
106 static struct { | 106 static struct { |
107 struct fd_list sentinel; /* sentinel element for this sublist */ | 107 struct fd_list sentinel; /* sentinel element for this sublist */ |
108 pthread_rwlock_t rwlock; /* the rwlock for this sublist */ | 108 pthread_mutex_t lock; /* the mutex for this sublist -- we might probably change it to rwlock for a little optimization */ |
109 } sess_hash [ 1 << SESS_HASH_SIZE ] ; | 109 } sess_hash [ 1 << SESS_HASH_SIZE ] ; |
110 #define H_MASK( __hash ) ((__hash) & (( 1 << SESS_HASH_SIZE ) - 1)) | 110 #define H_MASK( __hash ) ((__hash) & (( 1 << SESS_HASH_SIZE ) - 1)) |
111 #define H_LIST( _hash ) (&(sess_hash[H_MASK(_hash)].sentinel)) | 111 #define H_LIST( _hash ) (&(sess_hash[H_MASK(_hash)].sentinel)) |
112 #define H_RWLOCK( _hash ) (&(sess_hash[H_MASK(_hash)].rwlock )) | 112 #define H_LOCK( _hash ) (&(sess_hash[H_MASK(_hash)].lock )) |
113 | 113 |
114 /* The following are used to generate sid values that are eternaly unique */ | 114 /* The following are used to generate sid values that are eternaly unique */ |
115 static uint32_t sid_h; /* initialized to the current time in fd_sess_init */ | 115 static uint32_t sid_h; /* initialized to the current time in fd_sess_init */ |
116 static uint32_t sid_l; /* incremented each time a session id is created */ | 116 static uint32_t sid_l; /* incremented each time a session id is created */ |
117 static pthread_mutex_t sid_lock = PTHREAD_MUTEX_INITIALIZER; | 117 static pthread_mutex_t sid_lock = PTHREAD_MUTEX_INITIALIZER; |
124 | 124 |
125 /* Hierarchy of the locks, to avoid deadlocks: | 125 /* Hierarchy of the locks, to avoid deadlocks: |
126 * hash lock > state lock > expiry lock | 126 * hash lock > state lock > expiry lock |
127 * i.e. state lock can be taken while holding the hash lock, but not while holding the expiry lock. | 127 * i.e. state lock can be taken while holding the hash lock, but not while holding the expiry lock. |
128 * As well, the hash lock cannot be taken while holding a state lock. | 128 * As well, the hash lock cannot be taken while holding a state lock. |
129 * Never try to take another lock while holding the expiry one. | |
130 */ | 129 */ |
131 | 130 |
132 /********************************************************************************************************/ | 131 /********************************************************************************************************/ |
133 | 132 |
134 /* Initialize a session object. It is not linked now. sid must be already malloc'ed. */ | 133 /* Initialize a session object. It is not linked now. sid must be already malloc'ed. */ |
145 sess->eyec = SI_EYEC; | 144 sess->eyec = SI_EYEC; |
146 | 145 |
147 sess->sid = sid; | 146 sess->sid = sid; |
148 sess->hash = fd_hash(sid, sidlen); | 147 sess->hash = fd_hash(sid, sidlen); |
149 fd_list_init(&sess->chain_h, sess); | 148 fd_list_init(&sess->chain_h, sess); |
150 sess->rc = 0; | |
151 | 149 |
152 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &sess->timeout), return NULL ); | 150 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &sess->timeout), return NULL ); |
153 sess->timeout.tv_sec += SESS_DEFAULT_LIFETIME; | 151 sess->timeout.tv_sec += SESS_DEFAULT_LIFETIME; |
154 fd_list_init(&sess->expire, sess); | 152 fd_list_init(&sess->expire, sess); |
155 | 153 |