MEDIUM: stick-table: switch the table lock to rwlock
Right now a spinlock is used, but most accesses are for reads, so let's
switch the lock to an rwlock and switch all accesses to exclusive locks
for now. There should be no visible difference at this point.
diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c
index 0046e9e..975ed24 100644
--- a/src/hlua_fcn.c
+++ b/src/hlua_fcn.c
@@ -649,9 +649,9 @@
lua_settable(L, -3);
hlua_stktable_entry(L, t, ts);
- HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
+ HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock);
ts->ref_cnt--;
- HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
+ HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock);
return 1;
}
@@ -761,16 +761,16 @@
lua_newtable(L);
- HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
+ HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock);
eb = ebmb_first(&t->keys);
for (n = eb; n; n = ebmb_next(n)) {
ts = ebmb_entry(n, struct stksess, key);
if (!ts) {
- HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
+ HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock);
return 1;
}
ts->ref_cnt++;
- HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
+ HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock);
/* multi condition/value filter */
skip_entry = 0;
@@ -810,7 +810,7 @@
}
if (skip_entry) {
- HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
+ HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock);
ts->ref_cnt--;
continue;
}
@@ -834,10 +834,10 @@
lua_newtable(L);
hlua_stktable_entry(L, t, ts);
lua_settable(L, -3);
- HA_SPIN_LOCK(STK_TABLE_LOCK, &t->lock);
+ HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->lock);
ts->ref_cnt--;
}
- HA_SPIN_UNLOCK(STK_TABLE_LOCK, &t->lock);
+ HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->lock);
return 1;
}