Browse code

rtpengine: reworked condition around locking for easier pairing

- inside rtpengine_hash_table_insert()

Daniel-Constantin Mierla authored on 08/04/2021 09:54:33
Showing 1 changed files
... ...
@@ -221,16 +221,16 @@ int rtpengine_hash_table_insert(str callid, str viabranch, struct rtpengine_hash
221 221
 	// get entry list
222 222
 	hash_index = str_hash(callid);
223 223
 	entry = rtpengine_hash_table->row_entry_list[hash_index];
224
-	last_entry = entry;
225 224
 
226
-	// lock
227
-	if (rtpengine_hash_table->row_locks[hash_index]) {
228
-		lock_get(rtpengine_hash_table->row_locks[hash_index]);
229
-	} else {
230
-		LM_ERR("NULL rtpengine_hash_table->row_locks[%d]\n", hash_index);
225
+	if (entry==NULL || rtpengine_hash_table->row_locks[hash_index]==NULL) {
226
+		LM_ERR("NULL entry or lock for hash table slot[%d]\n", hash_index);
231 227
 		return 0;
232 228
 	}
233 229
 
230
+	last_entry = entry;
231
+	// lock
232
+	lock_get(rtpengine_hash_table->row_locks[hash_index]);
233
+
234 234
 	while (entry) {
235 235
 		// if found, don't add new entry
236 236
 		if (str_equal(entry->callid, new_entry->callid) &&