From: Brian Norris Date: Sat, 7 Jul 2012 00:09:17 +0000 (-0700) Subject: action: support ATOMIC_INIT X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c0182a11fd62cc38f9f5cbe49960d7a9bce8d381;p=cdsspec-compiler.git action: support ATOMIC_INIT For now, atomic_init() will be supported as simply a relaxed write. This doesn't quite match the spec exactly [1, 2], but it is expedient for supporting the common case of checking proper initialization. [1] From C++ N3242, Section 29.6.5, Statement 8: Non-atomically initializes *object with value desired. Note: Concurrent access from another thread, even via an atomic operation, constitutes a data race. [2] Note that for now, my implementation will not flag concurrent atomic_init() and atomic_store() as data races. --- diff --git a/action.cc b/action.cc index 68a34aa..d5131f0 100644 --- a/action.cc +++ b/action.cc @@ -33,7 +33,7 @@ bool ModelAction::is_read() const bool ModelAction::is_write() const { - return type == ATOMIC_WRITE; + return type == ATOMIC_WRITE || type == ATOMIC_INIT; } bool ModelAction::is_rmw() const @@ -41,6 +41,11 @@ bool ModelAction::is_rmw() const return type == ATOMIC_RMW; } +bool ModelAction::is_initialization() const +{ + return type == ATOMIC_INIT; +} + bool ModelAction::is_acquire() const { switch (order) { @@ -166,6 +171,9 @@ void ModelAction::print(void) const case ATOMIC_RMW: type_str = "atomic rmw"; break; + case ATOMIC_INIT: + type_str = "init atomic"; + break; default: type_str = "unknown type"; } diff --git a/action.h b/action.h index 4903f37..f9c6d41 100644 --- a/action.h +++ b/action.h @@ -21,7 +21,8 @@ typedef enum action_type { THREAD_JOIN, ATOMIC_READ, ATOMIC_WRITE, - ATOMIC_RMW + ATOMIC_RMW, + ATOMIC_INIT } action_type_t; /* Forward declaration */ @@ -51,6 +52,7 @@ public: bool is_read() const; bool is_write() const; bool is_rmw() const; + bool is_initialization() const; bool is_acquire() const; bool is_release() const; bool is_seqcst() const; diff --git a/libatomic.cc b/libatomic.cc index 507f685..a076533 100644 --- a/libatomic.cc +++ b/libatomic.cc @@ -19,5 +19,7 @@ int atomic_load_explicit(struct atomic_object *obj, memory_order order) void atomic_init(struct atomic_object *obj, int value) { + DBG(); obj->value = value; + model->switch_to_master(new ModelAction(ATOMIC_INIT, memory_order_relaxed, obj, value)); }