Document thread-safety in terms of constness

This commit is contained in:
2024-03-20 16:16:15 -07:00
parent cda28643a6
commit b7cdecaf71
2 changed files with 12 additions and 4 deletions

View File

@@ -2639,6 +2639,12 @@ ConflictSet_getBytes(void *cs) {
} }
} }
// Make sure abi is well-defined
static_assert(std::is_standard_layout_v<ConflictSet::Result>);
static_assert(std::is_standard_layout_v<ConflictSet::Key>);
static_assert(std::is_standard_layout_v<ConflictSet::ReadRange>);
static_assert(std::is_standard_layout_v<ConflictSet::WriteRange>);
namespace { namespace {
std::string getSearchPathPrintable(Node *n) { std::string getSearchPathPrintable(Node *n) {

View File

@@ -26,7 +26,7 @@ limitations under the License.
* - It's safe to operate on two different ConflictSets in two different * - It's safe to operate on two different ConflictSets in two different
* threads concurrently * threads concurrently
* - It's safe to have multiple threads operating on the same ConflictSet * - 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 { struct __attribute__((__visibility__("default"))) ConflictSet {
enum Result { enum Result {
@@ -110,7 +110,8 @@ private:
* - It's safe to operate on two different ConflictSets in two different * - It's safe to operate on two different ConflictSets in two different
* threads concurrently * threads concurrently
* - It's safe to have multiple threads operating on the same ConflictSet * - 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; typedef struct ConflictSet ConflictSet;
@@ -150,7 +151,8 @@ typedef struct {
} ConflictSet_WriteRange; } ConflictSet_WriteRange;
/** The result of checking reads[i] is written in results[i] */ /** 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); ConflictSet_Result *results, int count);
/** `writes` must be sorted ascending, and must not have adjacent or /** `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); void ConflictSet_destroy(ConflictSet *cs);
/** Returns the total bytes in use by this ConflictSet */ /** Returns the total bytes in use by this ConflictSet */
int64_t ConflictSet_getBytes(ConflictSet *cs); int64_t ConflictSet_getBytes(const ConflictSet *cs);
#endif #endif