From b7cdecaf719f26c12c0e77c2dc3699cb503cd708 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Wed, 20 Mar 2024 16:16:15 -0700 Subject: [PATCH] Document thread-safety in terms of constness --- ConflictSet.cpp | 6 ++++++ include/ConflictSet.h | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 8b97b75..f7b9b9e 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -2639,6 +2639,12 @@ ConflictSet_getBytes(void *cs) { } } +// Make sure abi is well-defined +static_assert(std::is_standard_layout_v); +static_assert(std::is_standard_layout_v); +static_assert(std::is_standard_layout_v); +static_assert(std::is_standard_layout_v); + namespace { std::string getSearchPathPrintable(Node *n) { diff --git a/include/ConflictSet.h b/include/ConflictSet.h index fff03fe..eeef03a 100644 --- a/include/ConflictSet.h +++ b/include/ConflictSet.h @@ -26,7 +26,7 @@ limitations under the License. * - It's safe to operate on two different ConflictSets in two different * threads concurrently * - It's safe to have multiple threads operating on the same ConflictSet - * concurrently if and only if all threads only call `check`. + * concurrently if and only if all threads only call const methods */ struct __attribute__((__visibility__("default"))) ConflictSet { enum Result { @@ -110,7 +110,8 @@ private: * - It's safe to operate on two different ConflictSets in two different * threads concurrently * - It's safe to have multiple threads operating on the same ConflictSet - * concurrently if and only if all threads only call `check`. + * concurrently if and only if all threads only call functions that accept a + * const ConflictSet pointer */ typedef struct ConflictSet ConflictSet; @@ -150,7 +151,8 @@ typedef struct { } ConflictSet_WriteRange; /** The result of checking reads[i] is written in results[i] */ -void ConflictSet_check(ConflictSet *cs, const ConflictSet_ReadRange *reads, +void ConflictSet_check(const ConflictSet *cs, + const ConflictSet_ReadRange *reads, ConflictSet_Result *results, int count); /** `writes` must be sorted ascending, and must not have adjacent or @@ -173,6 +175,6 @@ ConflictSet *ConflictSet_create(int64_t oldestVersion); void ConflictSet_destroy(ConflictSet *cs); /** Returns the total bytes in use by this ConflictSet */ -int64_t ConflictSet_getBytes(ConflictSet *cs); +int64_t ConflictSet_getBytes(const ConflictSet *cs); #endif