diff options
| author | eunhhu <[email protected]> | 2026-09-26 17:29:16 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-26 17:29:16 +0100 |
| commit | f563f3da1de1e551b2f7e9fe825f9b19fa13d481 (patch) | |
| tree | 1e1f7b589fea8c21fd8961dc13f72f66e38fc6c9 /prototypes/connections | |
| parent | 3d277c7714d7a8e2e0e7f9eb627722b83991effd (diff) | |
| download | pure-f563f3da1de1e551b2f7e9fe825f9b19fa13d481.tar.gz pure-f563f3da1de1e551b2f7e9fe825f9b19fa13d481.zip | |
Count a store mapping's references atomically
A read's lent extents hold the store mapping until its answer is sent;
with an owner thread running the app and connection threads answering,
the last reference may drop on a thread other than the one that took it.
Diffstat (limited to 'prototypes/connections')
| -rw-r--r-- | prototypes/connections/store-tree.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/prototypes/connections/store-tree.c b/prototypes/connections/store-tree.c index a5d24c2..45d470e 100644 --- a/prototypes/connections/store-tree.c +++ b/prototypes/connections/store-tree.c @@ -378,8 +378,10 @@ static bool map_tree(int fd, const struct stat *file, const Head *head, Tree *tr return true; } +/* A lent mapping may be released on another thread (a host that answers on + * its connection threads): its count is atomic. */ static void release_mapping(Mapping *mapping) { - if (!mapping || --mapping->refs) return; + if (!mapping || __atomic_sub_fetch(&mapping->refs, 1, __ATOMIC_ACQ_REL)) return; munmap((void *)mapping->map, (size_t)mapping->end); free(mapping); } @@ -1345,7 +1347,7 @@ static PureResult rebase(PureDraft *draft) { bool found; if (!find(&tree, (Entry){store->head.catalog, store->head.catalog_bytes}, draft->key, &index, &found, &document, &revision)) return PURE_STORE_ERROR; - ++mapping->refs; + __atomic_add_fetch(&mapping->refs, 1, __ATOMIC_RELAXED); release_tree(&draft->tree); draft->tree = tree; draft->device = store->device; @@ -1379,7 +1381,7 @@ void pure_store_close(PureStore *store) { PureMapping *pure_draft_mapping(const PureDraft *draft) { Mapping *mapping = draft->tree.shared; - if (mapping) ++mapping->refs; + if (mapping) __atomic_add_fetch(&mapping->refs, 1, __ATOMIC_RELAXED); return mapping; } |
