Browse code

htable: make locking to access a slot re-entrant for a process

- proper functionality for sht_lock()/sht_unlock()

(cherry picked from commit 4f07daab9cb95e13c7c89a9a566d4a8c88b9145e)

Daniel-Constantin Mierla authored on 08/11/2014 09:57:00
Showing 4 changed files
... ...
@@ -140,6 +140,37 @@ void keyvalue_destroy(keyvalue_t *res)
140 140
 	memset(res, 0, sizeof(keyvalue_t));
141 141
 }
142 142
 
143
+/**
144
+ * recursive/re-entrant lock of the slot in hash table
145
+ */
146
+void ht_slot_lock(ht_t *ht, int idx)
147
+{
148
+	int mypid;
149
+
150
+	mypid = my_pid();
151
+	if (likely(atomic_get(&ht->entries[idx].locker_pid) != mypid)) {
152
+		lock_get(&ht->entries[idx].lock);
153
+		atomic_set(&ht->entries[idx].locker_pid, mypid);
154
+	} else {
155
+		/* locked within the same process that executed us */
156
+		ht->entries[idx].rec_lock_level++;
157
+	}
158
+}
159
+
160
+/**
161
+ * recursive/re-entrant unlock of the slot in hash table
162
+ */
163
+void ht_slot_unlock(ht_t *ht, int idx)
164
+{
165
+	if (likely(ht->entries[idx].rec_lock_level == 0)) {
166
+		atomic_set(&ht->entries[idx].locker_pid, 0);
167
+		lock_release(&ht->entries[idx].lock);
168
+	} else  {
169
+		/* recursive locked => decrease lock count */
170
+		ht->entries[idx].rec_lock_level--;
171
+	}
172
+}
173
+
143 174
 ht_cell_t* ht_cell_new(str *name, int type, int_str *val, unsigned int cellid)
144 175
 {
145 176
 	ht_cell_t *cell;
... ...
@@ -393,7 +424,7 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
393 424
 	if(ht->htexpire>0)
394 425
 		now = time(NULL);
395 426
 	prev = NULL;
396
-	if(mode) lock_get(&ht->entries[idx].lock);
427
+	if(mode) ht_slot_lock(ht, idx);
397 428
 	it = ht->entries[idx].first;
398 429
 	while(it!=NULL && it->cellid < hid)
399 430
 	{
... ...
@@ -425,7 +456,7 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
425 456
 						if(cell == NULL)
426 457
 						{
427 458
 							LM_ERR("cannot create new cell\n");
428
-							if(mode) lock_release(&ht->entries[idx].lock);
459
+							if(mode) ht_slot_unlock(ht, idx);
429 460
 							return -1;
430 461
 						}
431 462
 						cell->next = it->next;
... ...
@@ -446,7 +477,7 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
446 477
 					if(ht->updateexpire)
447 478
 						it->expire = now + ht->htexpire;
448 479
 				}
449
-				if(mode) lock_release(&ht->entries[idx].lock);
480
+				if(mode) ht_slot_unlock(ht, idx);
450 481
 				return 0;
451 482
 			} else {
452 483
 				if(type&AVP_VAL_STR)
... ...
@@ -456,7 +487,7 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
456 487
 					if(cell == NULL)
457 488
 					{
458 489
 						LM_ERR("cannot create new cell.\n");
459
-						if(mode) lock_release(&ht->entries[idx].lock);
490
+						if(mode) ht_slot_unlock(ht, idx);
460 491
 						return -1;
461 492
 					}
462 493
 					cell->expire = now + ht->htexpire;
... ...
@@ -475,7 +506,7 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
475 506
 					if(ht->updateexpire)
476 507
 						it->expire = now + ht->htexpire;
477 508
 				}
478
-				if(mode) lock_release(&ht->entries[idx].lock);
509
+				if(mode) ht_slot_unlock(ht, idx);
479 510
 				return 0;
480 511
 			}
481 512
 		}
... ...
@@ -487,7 +518,7 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
487 518
 	if(cell == NULL)
488 519
 	{
489 520
 		LM_ERR("cannot create new cell.\n");
490
-		if(mode) lock_release(&ht->entries[idx].lock);
521
+		if(mode) ht_slot_unlock(ht, idx);
491 522
 		return -1;
492 523
 	}
493 524
 	cell->expire = now + ht->htexpire;
... ...
@@ -507,7 +538,7 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
507 538
 		prev->next = cell;
508 539
 	}
509 540
 	ht->entries[idx].esize++;
510
-	if(mode) lock_release(&ht->entries[idx].lock);
541
+	if(mode) ht_slot_unlock(ht, idx);
511 542
 	return 0;
512 543
 }
513 544
 
... ...
@@ -528,7 +559,7 @@ int ht_del_cell(ht_t *ht, str *name)
528 559
 	if(ht->entries[idx].first==NULL)
529 560
 		return 0;
530 561
 	
531
-	lock_get(&ht->entries[idx].lock);
562
+	ht_slot_lock(ht, idx);
532 563
 	it = ht->entries[idx].first;
533 564
 	while(it!=NULL && it->cellid < hid)
534 565
 		it = it->next;
... ...
@@ -545,13 +576,13 @@ int ht_del_cell(ht_t *ht, str *name)
545 576
 			if(it->next)
546 577
 				it->next->prev = it->prev;
547 578
 			ht->entries[idx].esize--;
548
-			lock_release(&ht->entries[idx].lock);
579
+			ht_slot_unlock(ht, idx);
549 580
 			ht_cell_free(it);
550 581
 			return 0;
551 582
 		}
552 583
 		it = it->next;
553 584
 	}
554
-	lock_release(&ht->entries[idx].lock);
585
+	ht_slot_unlock(ht, idx);
555 586
 	return 0;
556 587
 }
557 588
 
... ...
@@ -575,7 +606,7 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, int mode,
575 606
 	if(ht->htexpire>0)
576 607
 		now = time(NULL);
577 608
 	prev = NULL;
578
-	if(mode) lock_get(&ht->entries[idx].lock);
609
+	if(mode) ht_slot_lock(ht, idx);
579 610
 	it = ht->entries[idx].first;
580 611
 	while(it!=NULL && it->cellid < hid)
581 612
 	{
... ...
@@ -606,7 +637,7 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, int mode,
606 637
 					if(it->next)
607 638
 						it->next->prev = it->prev;
608 639
 					ht->entries[idx].esize--;
609
-					if(mode) lock_release(&ht->entries[idx].lock);
640
+					if(mode) ht_slot_unlock(ht, idx);
610 641
 					ht_cell_free(it);
611 642
 					return NULL;
612 643
 				}
... ...
@@ -615,7 +646,7 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, int mode,
615 646
 			if(it->flags&AVP_VAL_STR)
616 647
 			{
617 648
 				/* string value cannot be incremented */
618
-				if(mode) lock_release(&ht->entries[idx].lock);
649
+				if(mode) ht_slot_unlock(ht, idx);
619 650
 				return NULL;
620 651
 			} else {
621 652
 				it->value.n += val;
... ...
@@ -625,7 +656,7 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, int mode,
625 656
 					if(old->msize>=it->msize)
626 657
 					{
627 658
 						memcpy(old, it, it->msize);
628
-						if(mode) lock_release(&ht->entries[idx].lock);
659
+						if(mode) ht_slot_unlock(ht, idx);
629 660
 						return old;
630 661
 					}
631 662
 				}
... ...
@@ -633,7 +664,7 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, int mode,
633 664
 				if(cell!=NULL)
634 665
 					memcpy(cell, it, it->msize);
635 666
 
636
-				if(mode) lock_release(&ht->entries[idx].lock);
667
+				if(mode) ht_slot_unlock(ht, idx);
637 668
 				return cell;
638 669
 			}
639 670
 		}
... ...
@@ -648,7 +679,7 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, int mode,
648 679
 	if(it == NULL)
649 680
 	{
650 681
 		LM_ERR("cannot create new cell.\n");
651
-		if(mode) lock_release(&ht->entries[idx].lock);
682
+		if(mode) ht_slot_unlock(ht, idx);
652 683
 		return NULL;
653 684
 	}
654 685
 	it->expire = now + ht->htexpire;
... ...
@@ -673,7 +704,7 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, int mode,
673 704
 		if(old->msize>=it->msize)
674 705
 		{
675 706
 			memcpy(old, it, it->msize);
676
-			if(mode) lock_release(&ht->entries[idx].lock);
707
+			if(mode) ht_slot_unlock(ht, idx);
677 708
 			return old;
678 709
 		}
679 710
 	}
... ...
@@ -681,7 +712,7 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, int mode,
681 712
 	if(cell!=NULL)
682 713
 		memcpy(cell, it, it->msize);
683 714
 
684
-	if(mode) lock_release(&ht->entries[idx].lock);
715
+	if(mode) ht_slot_unlock(ht, idx);
685 716
 	return cell;
686 717
 }
687 718
 
... ...
@@ -703,7 +734,7 @@ ht_cell_t* ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old)
703 734
 	if(ht->entries[idx].first==NULL)
704 735
 		return NULL;
705 736
 	
706
-	lock_get(&ht->entries[idx].lock);
737
+	ht_slot_lock(ht, idx);
707 738
 	it = ht->entries[idx].first;
708 739
 	while(it!=NULL && it->cellid < hid)
709 740
 		it = it->next;
... ...
@@ -724,7 +755,7 @@ ht_cell_t* ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old)
724 755
 				if(it->next)
725 756
 					it->next->prev = it->prev;
726 757
 				ht->entries[idx].esize--;
727
-				lock_release(&ht->entries[idx].lock);
758
+				ht_slot_unlock(ht, idx);
728 759
 				ht_cell_free(it);
729 760
 				return NULL;
730 761
 			}
... ...
@@ -733,19 +764,19 @@ ht_cell_t* ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old)
733 764
 				if(old->msize>=it->msize)
734 765
 				{
735 766
 					memcpy(old, it, it->msize);
736
-					lock_release(&ht->entries[idx].lock);
767
+					ht_slot_unlock(ht, idx);
737 768
 					return old;
738 769
 				}
739 770
 			}
740 771
 			cell = (ht_cell_t*)pkg_malloc(it->msize);
741 772
 			if(cell!=NULL)
742 773
 				memcpy(cell, it, it->msize);
743
-			lock_release(&ht->entries[idx].lock);
774
+			ht_slot_unlock(ht, idx);
744 775
 			return cell;
745 776
 		}
746 777
 		it = it->next;
747 778
 	}
748
-	lock_release(&ht->entries[idx].lock);
779
+	ht_slot_unlock(ht, idx);
749 780
 	return NULL;
750 781
 }
751 782
 
... ...
@@ -762,7 +793,7 @@ int ht_dbg(void)
762 793
 				ht->name.s, ht->htid, ht->htexpire);
763 794
 		for(i=0; i<ht->htsize; i++)
764 795
 		{
765
-			lock_get(&ht->entries[i].lock);
796
+			ht_slot_lock(ht, i);
766 797
 			LM_ERR("htable[%d] -- <%d>\n", i, ht->entries[i].esize);
767 798
 			it = ht->entries[i].first;
768 799
 			while(it)
... ...
@@ -776,7 +807,7 @@ int ht_dbg(void)
776 807
 					LM_ERR("\tv-i:%d\n", it->value.n);
777 808
 				it = it->next;
778 809
 			}
779
-			lock_release(&ht->entries[i].lock);
810
+			ht_slot_unlock(ht, i);
780 811
 		}
781 812
 		ht = ht->next;
782 813
 	}
... ...
@@ -945,7 +976,7 @@ void ht_timer(unsigned int ticks, void *param)
945 976
 			for(i=0; i<ht->htsize; i++)
946 977
 			{
947 978
 				/* free entries */
948
-				lock_get(&ht->entries[i].lock);
979
+				ht_slot_lock(ht, i);
949 980
 				it = ht->entries[i].first;
950 981
 				while(it)
951 982
 				{
... ...
@@ -965,7 +996,7 @@ void ht_timer(unsigned int ticks, void *param)
965 996
 					}
966 997
 					it = it0;
967 998
 				}
968
-				lock_release(&ht->entries[i].lock);
999
+				ht_slot_unlock(ht, i);
969 1000
 			}
970 1001
 		}
971 1002
 		ht = ht->next;
... ...
@@ -1040,7 +1071,7 @@ int ht_set_cell_expire(ht_t *ht, str *name, int type, int_str *val)
1040 1071
 	LM_DBG("set auto-expire to %u (%d)\n", (unsigned int)now,
1041 1072
 			val->n);
1042 1073
 
1043
-	lock_get(&ht->entries[idx].lock);
1074
+	ht_slot_lock(ht, idx);
1044 1075
 	it = ht->entries[idx].first;
1045 1076
 	while(it!=NULL && it->cellid < hid)
1046 1077
 		it = it->next;
... ...
@@ -1051,12 +1082,12 @@ int ht_set_cell_expire(ht_t *ht, str *name, int type, int_str *val)
1051 1082
 		{
1052 1083
 			/* update value */
1053 1084
 			it->expire = now;
1054
-			lock_release(&ht->entries[idx].lock);
1085
+			ht_slot_unlock(ht, idx);
1055 1086
 			return 0;
1056 1087
 		}
1057 1088
 		it = it->next;
1058 1089
 	}
1059
-	lock_release(&ht->entries[idx].lock);
1090
+	ht_slot_unlock(ht, idx);
1060 1091
 	return 0;
1061 1092
 }
1062 1093
 
... ...
@@ -1080,7 +1111,7 @@ int ht_get_cell_expire(ht_t *ht, str *name, unsigned int *val)
1080 1111
 	idx = ht_get_entry(hid, ht->htsize);
1081 1112
 
1082 1113
 	now = time(NULL);
1083
-	lock_get(&ht->entries[idx].lock);
1114
+	ht_slot_lock(ht, idx);
1084 1115
 	it = ht->entries[idx].first;
1085 1116
 	while(it!=NULL && it->cellid < hid)
1086 1117
 		it = it->next;
... ...
@@ -1091,12 +1122,12 @@ int ht_get_cell_expire(ht_t *ht, str *name, unsigned int *val)
1091 1122
 		{
1092 1123
 			/* update value */
1093 1124
 			*val = (unsigned int)(it->expire - now);
1094
-			lock_release(&ht->entries[idx].lock);
1125
+			ht_slot_unlock(ht, idx);
1095 1126
 			return 0;
1096 1127
 		}
1097 1128
 		it = it->next;
1098 1129
 	}
1099
-	lock_release(&ht->entries[idx].lock);
1130
+	ht_slot_unlock(ht, idx);
1100 1131
 	return 0;
1101 1132
 }
1102 1133
 
... ...
@@ -1121,7 +1152,7 @@ int ht_rm_cell_re(str *sre, ht_t *ht, int mode)
1121 1152
 	for(i=0; i<ht->htsize; i++)
1122 1153
 	{
1123 1154
 		/* free entries */
1124
-		lock_get(&ht->entries[i].lock);
1155
+		ht_slot_lock(ht, i);
1125 1156
 		it = ht->entries[i].first;
1126 1157
 		while(it)
1127 1158
 		{
... ...
@@ -1149,7 +1180,7 @@ int ht_rm_cell_re(str *sre, ht_t *ht, int mode)
1149 1180
 			}
1150 1181
 			it = it0;
1151 1182
 		}
1152
-		lock_release(&ht->entries[i].lock);
1183
+		ht_slot_unlock(ht, i);
1153 1184
 	}
1154 1185
 	regfree(&re);
1155 1186
 	return 0;
... ...
@@ -1167,7 +1198,7 @@ int ht_reset_content(ht_t *ht)
1167 1198
 	for(i=0; i<ht->htsize; i++)
1168 1199
 	{
1169 1200
 		/* free entries */
1170
-		lock_get(&ht->entries[i].lock);
1201
+		ht_slot_lock(ht, i);
1171 1202
 		it = ht->entries[i].first;
1172 1203
 		while(it)
1173 1204
 		{
... ...
@@ -1182,7 +1213,7 @@ int ht_reset_content(ht_t *ht)
1182 1213
 			ht_cell_free(it);
1183 1214
 			it = it0;
1184 1215
 		}
1185
-		lock_release(&ht->entries[i].lock);
1216
+		ht_slot_unlock(ht, i);
1186 1217
 	}
1187 1218
 	return 0;
1188 1219
 }
... ...
@@ -1285,7 +1316,7 @@ int ht_count_cells_re(str *sre, ht_t *ht, int mode)
1285 1316
 	for(i=0; i<ht->htsize; i++)
1286 1317
 	{
1287 1318
 		/* free entries */
1288
-		lock_get(&ht->entries[i].lock);
1319
+		ht_slot_lock(ht, i);
1289 1320
 		it = ht->entries[i].first;
1290 1321
 		while(it)
1291 1322
 		{
... ...
@@ -1332,7 +1363,7 @@ int ht_count_cells_re(str *sre, ht_t *ht, int mode)
1332 1363
 			}
1333 1364
 			it = it0;
1334 1365
 		}
1335
-		lock_release(&ht->entries[i].lock);
1366
+		ht_slot_unlock(ht, i);
1336 1367
 	}
1337 1368
 	if(op==1)
1338 1369
 		regfree(&re);
... ...
@@ -1388,7 +1419,7 @@ int ht_iterator_start(str *iname, str *hname)
1388 1419
 		{
1389 1420
 			if(_ht_iterators[k].slot>=0 && _ht_iterators[k].slot<_ht_iterators[k].ht->htsize)
1390 1421
 			{
1391
-				lock_release(&_ht_iterators[k].ht->entries[_ht_iterators[k].slot].lock);
1422
+				ht_slot_unlock(_ht_iterators[k].ht, _ht_iterators[k].slot);
1392 1423
 			}
1393 1424
 		}
1394 1425
 	} else {
... ...
@@ -1457,19 +1488,19 @@ int ht_iterator_next(str *iname)
1457 1488
 		}
1458 1489
 		/* next is not in the same slot - release and try next one */
1459 1490
 		_ht_iterators[k].it = NULL;
1460
-		lock_release(&_ht_iterators[k].ht->entries[_ht_iterators[k].slot].lock);
1491
+		ht_slot_unlock(_ht_iterators[k].ht, _ht_iterators[k].slot);
1461 1492
 		_ht_iterators[k].slot++;
1462 1493
 	}
1463 1494
 
1464 1495
 	for( ; _ht_iterators[k].slot<_ht_iterators[k].ht->htsize; _ht_iterators[k].slot++)
1465 1496
 	{
1466
-		lock_get(&_ht_iterators[k].ht->entries[_ht_iterators[k].slot].lock);
1497
+		ht_slot_lock(_ht_iterators[k].ht, _ht_iterators[k].slot);
1467 1498
 		if(_ht_iterators[k].ht->entries[_ht_iterators[k].slot].first!=NULL)
1468 1499
 		{
1469 1500
 			_ht_iterators[k].it = _ht_iterators[k].ht->entries[_ht_iterators[k].slot].first;
1470 1501
 			return 0;
1471 1502
 		}
1472
-		lock_release(&_ht_iterators[k].ht->entries[_ht_iterators[k].slot].lock);
1503
+		ht_slot_unlock(_ht_iterators[k].ht, _ht_iterators[k].slot);
1473 1504
 	}
1474 1505
 	return -1;
1475 1506
 }
... ...
@@ -1489,7 +1520,7 @@ int ht_iterator_end(str *iname)
1489 1520
 				{
1490 1521
 					if(_ht_iterators[i].slot>=0 && _ht_iterators[i].slot<_ht_iterators[i].ht->htsize)
1491 1522
 					{
1492
-						lock_release(&_ht_iterators[i].ht->entries[_ht_iterators[i].slot].lock);
1523
+						ht_slot_unlock(_ht_iterators[i].ht, _ht_iterators[i].slot);
1493 1524
 					}
1494 1525
 				}
1495 1526
 				memset(&_ht_iterators[i], 0, sizeof(ht_iterator_t));
... ...
@@ -28,6 +28,7 @@
28 28
 #include "../../usr_avp.h"
29 29
 #include "../../locking.h"
30 30
 #include "../../pvar.h"
31
+#include "../../atomic_ops.h"
31 32
 
32 33
 #define ht_compute_hash(_s)        core_case_hash(_s,0,0)
33 34
 #define ht_get_entry(_h,_size)    (_h)&((_size)-1)
... ...
@@ -46,9 +47,11 @@ typedef struct _ht_cell
46 47
 
47 48
 typedef struct _ht_entry
48 49
 {
49
-	unsigned int esize;
50
-	ht_cell_t *first;
51
-	gen_lock_t lock;	
50
+	unsigned int esize;  /* number of items in the slot */
51
+	ht_cell_t *first;    /* first item in the slot */
52
+	gen_lock_t lock;     /* mutex to access items in the slot */
53
+	atomic_t locker_pid; /* pid of the process that holds the lock */
54
+	int rec_lock_level;  /* recursive lock count */
52 55
 } ht_entry_t;
53 56
 
54 57
 typedef struct _ht
... ...
@@ -111,4 +114,6 @@ int ht_iterator_next(str *iname);
111 114
 int ht_iterator_end(str *iname);
112 115
 ht_cell_t* ht_iterator_get_current(str *iname);
113 116
 
117
+void ht_slot_lock(ht_t *ht, int idx);
118
+void ht_slot_unlock(ht_t *ht, int idx);
114 119
 #endif
... ...
@@ -435,7 +435,7 @@ int ht_db_save_table(ht_t *ht, str *dbtable)
435 435
 
436 436
 	for(i=0; i<ht->htsize; i++)
437 437
 	{
438
-		lock_get(&ht->entries[i].lock);
438
+		ht_slot_lock(ht, i);
439 439
 		it = ht->entries[i].first;
440 440
 		while(it)
441 441
 		{
... ...
@@ -495,6 +495,7 @@ int ht_db_save_table(ht_t *ht, str *dbtable)
495 495
 			}
496 496
 			it = it->next;
497 497
 		}
498
+		ht_slot_unlock(ht, i);
498 499
 	}
499 500
 	return 0;
500 501
 }
... ...
@@ -63,8 +63,8 @@ static void destroy(void);
63 63
 static int fixup_ht_key(void** param, int param_no);
64 64
 static int ht_rm_name_re(struct sip_msg* msg, char* key, char* foo);
65 65
 static int ht_rm_value_re(struct sip_msg* msg, char* key, char* foo);
66
-static int ht_slot_lock(struct sip_msg* msg, char* key, char* foo);
67
-static int ht_slot_unlock(struct sip_msg* msg, char* key, char* foo);
66
+static int w_ht_slot_lock(struct sip_msg* msg, char* key, char* foo);
67
+static int w_ht_slot_unlock(struct sip_msg* msg, char* key, char* foo);
68 68
 static int ht_reset(struct sip_msg* msg, char* htname, char* foo);
69 69
 static int w_ht_iterator_start(struct sip_msg* msg, char* iname, char* hname);
70 70
 static int w_ht_iterator_next(struct sip_msg* msg, char* iname, char* foo);
... ...
@@ -114,9 +114,9 @@ static cmd_export_t cmds[]={
114 114
 		ANY_ROUTE},
115 115
 	{"sht_rm_value_re", (cmd_function)ht_rm_value_re,  1, fixup_ht_key, 0,
116 116
 		ANY_ROUTE},
117
-	{"sht_lock",        (cmd_function)ht_slot_lock,    1, fixup_ht_key, 0,
117
+	{"sht_lock",        (cmd_function)w_ht_slot_lock,    1, fixup_ht_key, 0,
118 118
 		ANY_ROUTE},
119
-	{"sht_unlock",      (cmd_function)ht_slot_unlock,  1, fixup_ht_key, 0,
119
+	{"sht_unlock",      (cmd_function)w_ht_slot_unlock,  1, fixup_ht_key, 0,
120 120
 		ANY_ROUTE},
121 121
 	{"sht_reset",		(cmd_function)ht_reset,		   1, fixup_spve_null, 0,
122 122
 		ANY_ROUTE},
... ...
@@ -446,7 +446,7 @@ static int w_ht_iterator_end(struct sip_msg* msg, char* iname, char* foo)
446 446
 /**
447 447
  * lock the slot for a given key in a hash table
448 448
  */
449
-static int ht_slot_lock(struct sip_msg* msg, char* key, char* foo)
449
+static int w_ht_slot_lock(struct sip_msg* msg, char* key, char* foo)
450 450
 {
451 451
 	ht_pv_t *hpv;
452 452
 	str skey;
... ...
@@ -480,7 +480,7 @@ static int ht_slot_lock(struct sip_msg* msg, char* key, char* foo)
480 480
 			hpv->htname.len, hpv->htname.s,
481 481
 			idx, skey.len, skey.s);
482 482
 
483
-	lock_get(&hpv->ht->entries[idx].lock);
483
+	ht_slot_lock(hpv->ht, idx);
484 484
 
485 485
 	return 1;
486 486
 }
... ...
@@ -488,7 +488,7 @@ static int ht_slot_lock(struct sip_msg* msg, char* key, char* foo)
488 488
 /**
489 489
  * unlock the slot for a given key in a hash table
490 490
  */
491
-static int ht_slot_unlock(struct sip_msg* msg, char* key, char* foo)
491
+static int w_ht_slot_unlock(struct sip_msg* msg, char* key, char* foo)
492 492
 {
493 493
 	ht_pv_t *hpv;
494 494
 	str skey;
... ...
@@ -522,7 +522,7 @@ static int ht_slot_unlock(struct sip_msg* msg, char* key, char* foo)
522 522
 			hpv->htname.len, hpv->htname.s,
523 523
 			idx, skey.len, skey.s);
524 524
 
525
-	lock_release(&hpv->ht->entries[idx].lock);
525
+	ht_slot_unlock(hpv->ht, idx);
526 526
 
527 527
 	return 1;
528 528
 }
... ...
@@ -609,11 +609,11 @@ static struct mi_root* ht_mi_reload(struct mi_root* cmd_tree, void* param)
609 609
 	/* replace old entries */
610 610
 	for(i=0; i<nht.htsize; i++)
611 611
 	{
612
-		lock_get(&ht->entries[i].lock);
612
+		ht_slot_lock(ht, i);
613 613
 		first = ht->entries[i].first;
614 614
 		ht->entries[i].first = nht.entries[i].first;
615 615
 		ht->entries[i].esize = nht.entries[i].esize;
616
-		lock_release(&ht->entries[i].lock);
616
+		ht_slot_unlock(ht, i);
617 617
 		nht.entries[i].first = first;
618 618
 	}
619 619
 	/* free old entries */
... ...
@@ -708,7 +708,7 @@ static struct mi_root* ht_mi_dump(struct mi_root* cmd_tree, void* param)
708 708
 
709 709
 	for(i=0; i<ht->htsize; i++)
710 710
 	{
711
-		lock_get(&ht->entries[i].lock);
711
+		ht_slot_lock(ht, i);
712 712
 		it = ht->entries[i].first;
713 713
 		if(it)
714 714
 		{
... ...
@@ -732,7 +732,7 @@ static struct mi_root* ht_mi_dump(struct mi_root* cmd_tree, void* param)
732 732
 				it = it->next;
733 733
 			}
734 734
 		}
735
-		lock_release(&ht->entries[i].lock);
735
+		ht_slot_unlock(ht, i);
736 736
 	}
737 737
 
738 738
 	return rpl_tree;
... ...
@@ -963,7 +963,7 @@ static void  htable_rpc_dump(rpc_t* rpc, void* c)
963 963
 	}
964 964
 	for(i=0; i<ht->htsize; i++)
965 965
 	{
966
-		lock_get(&ht->entries[i].lock);
966
+		ht_slot_lock(ht, i);
967 967
 		it = ht->entries[i].first;
968 968
 		if(it)
969 969
 		{
... ...
@@ -1009,13 +1009,13 @@ static void  htable_rpc_dump(rpc_t* rpc, void* c)
1009 1009
 				it = it->next;
1010 1010
 			}
1011 1011
 		}
1012
-		lock_release(&ht->entries[i].lock);
1012
+		ht_slot_unlock(ht, i);
1013 1013
 	}
1014 1014
 
1015 1015
 	return;
1016 1016
 
1017 1017
 error:
1018
-	lock_release(&ht->entries[i].lock);
1018
+	ht_slot_unlock(ht, i);
1019 1019
 }
1020 1020
 
1021 1021
 static void  htable_rpc_list(rpc_t* rpc, void* c)
... ...
@@ -1093,13 +1093,13 @@ static void  htable_rpc_stats(rpc_t* rpc, void* c)
1093 1093
 		max = 0;
1094 1094
 		min = 4294967295U;
1095 1095
 		for(i=0; i<ht->htsize; i++) {
1096
-			lock_get(&ht->entries[i].lock);
1096
+			ht_slot_lock(ht, i);
1097 1097
 			if(ht->entries[i].esize<min)
1098 1098
 				min = ht->entries[i].esize;
1099 1099
 			if(ht->entries[i].esize>max)
1100 1100
 				max = ht->entries[i].esize;
1101 1101
 			all += ht->entries[i].esize;
1102
-			lock_release(&ht->entries[i].lock);
1102
+			ht_slot_unlock(ht, i);
1103 1103
 		}
1104 1104
 
1105 1105
 		if(rpc->struct_add(th, "Sddd",
... ...
@@ -1189,11 +1189,11 @@ static void htable_rpc_reload(rpc_t* rpc, void* c)
1189 1189
 	/* replace old entries */
1190 1190
 	for(i=0; i<nht.htsize; i++)
1191 1191
 	{
1192
-		lock_get(&ht->entries[i].lock);
1192
+		ht_slot_lock(ht, i);
1193 1193
 		first = ht->entries[i].first;
1194 1194
 		ht->entries[i].first = nht.entries[i].first;
1195 1195
 		ht->entries[i].esize = nht.entries[i].esize;
1196
-		lock_release(&ht->entries[i].lock);
1196
+		ht_slot_unlock(ht, i);
1197 1197
 		nht.entries[i].first = first;
1198 1198
 	}
1199 1199
 	/* free old entries */