}
stkctr_set_entry(stkctr, NULL);
- stksess_kill_if_expired(stkctr->table, ts, 1);
+ stksess_kill_if_expired(stkctr->table, ts);
}
}
struct stksess *stksess_new(struct stktable *t, struct stktable_key *key);
void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key);
void stksess_free(struct stktable *t, struct stksess *ts);
-int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcount);
+int stksess_kill(struct stktable *t, struct stksess *ts);
int stktable_get_key_shard(struct stktable *t, const void *key, size_t len);
int stktable_init(struct stktable *t, char **err_msg);
return 0;
}
-static inline void stksess_kill_if_expired(struct stktable *t, struct stksess *ts, int decrefcnt)
+/*
+ * Decrease the refcount of a stksess and relase it if the refcount falls to 0
+ * _AND_ if the session expired. Note,, the refcount is always decremented.
+ *
+ * This function locks the corresponding table shard to proceed. When this
+ * function is called, the caller must be sure it owns a reference on the
+ * stksess (refcount >= 1).
+ */
+static inline void stksess_kill_if_expired(struct stktable *t, struct stksess *ts)
{
uint shard;
size_t len;
ALREADY_CHECKED(shard);
HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
- if (!decrefcnt || !HA_ATOMIC_SUB_FETCH(&ts->ref_cnt, 1))
+ if (!HA_ATOMIC_SUB_FETCH(&ts->ref_cnt, 1))
__stksess_kill_if_expired(t, ts);
HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
}
- else if (decrefcnt)
+ else
HA_ATOMIC_SUB_FETCH(&ts->ref_cnt, 1);
}
stktable_touch_local(s->stkctr[i].table, ts, 0);
}
stkctr_set_entry(&s->stkctr[i], NULL);
- stksess_kill_if_expired(s->stkctr[i].table, ts, 1);
+ stksess_kill_if_expired(s->stkctr[i].table, ts);
}
}
stktable_touch_local(s->stkctr[i].table, ts, 0);
}
stkctr_set_entry(&s->stkctr[i], NULL);
- stksess_kill_if_expired(s->stkctr[i].table, ts, 1);
+ stksess_kill_if_expired(s->stkctr[i].table, ts);
}
}
}
/*
- * Decrease the refcount if decrefcnt is not 0, and try to kill the stksess.
+ * Decrease the refcount of a stksess and relase it if the refcount falls to 0.
* Returns non-zero if deleted, zero otherwise.
- * This function locks the table
+ *
+ * This function locks the corresponding table shard to proceed. When this
+ * function is called, the caller must be sure it owns a reference on the
+ * stksess (refcount >= 1).
*/
-int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcnt)
+int stksess_kill(struct stktable *t, struct stksess *ts)
{
uint shard;
size_t len;
ALREADY_CHECKED(shard);
HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
- if (!decrefcnt || !HA_ATOMIC_SUB_FETCH(&ts->ref_cnt, 1))
+ if (!HA_ATOMIC_SUB_FETCH(&ts->ref_cnt, 1))
ret = __stksess_kill(t, ts);
HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
break;
case STK_CLI_ACT_CLR:
- if (!stksess_kill(t, ts, 1)) {
+ if (!stksess_kill(t, ts)) {
/* don't delete an entry which is currently referenced */
return cli_err(appctx, "Entry currently in use, cannot remove\n");
}
struct show_table_ctx *ctx = appctx->svcctx;
if (ctx->state == STATE_DUMP) {
- stksess_kill_if_expired(ctx->t, ctx->entry, 1);
+ stksess_kill_if_expired(ctx->t, ctx->entry);
}
}