diff --git a/src/ckdb.h b/src/ckdb.h index 51c5e1e8..2414a40a 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -58,7 +58,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.7" -#define CKDB_VERSION DB_VERSION"-2.713" +#define CKDB_VERSION DB_VERSION"-2.714" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index fb77bbdc..18e61693 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -3348,7 +3348,7 @@ static char *cmd_heartbeat(__maybe_unused PGconn *conn, char *cmd, char *id, goto pulse; } - hq_store = k_new_store(heartbeatqueue_free); + hq_store = k_new_store_locked(heartbeatqueue_free); k_list_transfer_to_head(heartbeatqueue_store, hq_store); K_WUNLOCK(heartbeatqueue_free); diff --git a/src/klist.c b/src/klist.c index cdad46c5..105b7b4e 100644 --- a/src/klist.c +++ b/src/klist.c @@ -191,7 +191,7 @@ static void k_alloc_items(K_LIST *list, KLIST_FFL_ARGS) list->count_up = allocate; } -K_STORE *_k_new_store(K_LIST *list, KLIST_FFL_ARGS) +K_STORE *_k_new_store(K_LIST *list, bool gotlock, KLIST_FFL_ARGS) { K_STORE *store; @@ -212,14 +212,16 @@ K_STORE *_k_new_store(K_LIST *list, KLIST_FFL_ARGS) store->next_store = NULL; store->master->stores++; } else { - K_WLOCK(list); + if (!gotlock) + K_WLOCK(list); // In the master list, next is the head if (list->next_store) list->next_store->prev_store = store; store->next_store = list->next_store; list->next_store = store; list->stores++; - K_WUNLOCK(list); + if (!gotlock) + K_WUNLOCK(list); } return store; diff --git a/src/klist.h b/src/klist.h index e009d708..2d9ed190 100644 --- a/src/klist.h +++ b/src/klist.h @@ -668,8 +668,9 @@ static inline K_ITEM *list_rtail(K_LIST *list) extern void _dsp_kstore(K_STORE *store, char *filename, char *msg, KLIST_FFL_ARGS); #define dsp_kstore(_store, _file, _msg) _dsp_kstore(_store, _file, _msg, KLIST_FFL_HERE) -extern K_STORE *_k_new_store(K_LIST *list, KLIST_FFL_ARGS); -#define k_new_store(_list) _k_new_store(_list, KLIST_FFL_HERE) +extern K_STORE *_k_new_store(K_LIST *list, bool gotlock, KLIST_FFL_ARGS); +#define k_new_store(_list) _k_new_store(_list, false, KLIST_FFL_HERE) +#define k_new_store_locked(_list) _k_new_store(_list, true, KLIST_FFL_HERE) extern K_LIST *_k_new_list(const char *name, size_t siz, int allocate, int limit, bool do_tail, bool lock_only, bool without_lock, bool local_list,