Browse Source

ckdb - allow creating a store inside a list lock

master
kanoi 8 years ago
parent
commit
7cedce99d0
  1. 2
      src/ckdb.h
  2. 2
      src/ckdb_cmd.c
  3. 4
      src/klist.c
  4. 5
      src/klist.h

2
src/ckdb.h

@ -58,7 +58,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.7" #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 " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #define WHERE_FFL_HERE __FILE__, __func__, __LINE__

2
src/ckdb_cmd.c

@ -3348,7 +3348,7 @@ static char *cmd_heartbeat(__maybe_unused PGconn *conn, char *cmd, char *id,
goto pulse; 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_list_transfer_to_head(heartbeatqueue_store, hq_store);
K_WUNLOCK(heartbeatqueue_free); K_WUNLOCK(heartbeatqueue_free);

4
src/klist.c

@ -191,7 +191,7 @@ static void k_alloc_items(K_LIST *list, KLIST_FFL_ARGS)
list->count_up = allocate; 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; K_STORE *store;
@ -212,6 +212,7 @@ K_STORE *_k_new_store(K_LIST *list, KLIST_FFL_ARGS)
store->next_store = NULL; store->next_store = NULL;
store->master->stores++; store->master->stores++;
} else { } else {
if (!gotlock)
K_WLOCK(list); K_WLOCK(list);
// In the master list, next is the head // In the master list, next is the head
if (list->next_store) if (list->next_store)
@ -219,6 +220,7 @@ K_STORE *_k_new_store(K_LIST *list, KLIST_FFL_ARGS)
store->next_store = list->next_store; store->next_store = list->next_store;
list->next_store = store; list->next_store = store;
list->stores++; list->stores++;
if (!gotlock)
K_WUNLOCK(list); K_WUNLOCK(list);
} }

5
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); 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) #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); extern K_STORE *_k_new_store(K_LIST *list, bool gotlock, KLIST_FFL_ARGS);
#define k_new_store(_list) _k_new_store(_list, KLIST_FFL_HERE) #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, extern K_LIST *_k_new_list(const char *name, size_t siz, int allocate,
int limit, bool do_tail, bool lock_only, int limit, bool do_tail, bool lock_only,
bool without_lock, bool local_list, bool without_lock, bool local_list,

Loading…
Cancel
Save