action: support ATOMIC_INIT
authorBrian Norris <banorris@uci.edu>
Sat, 7 Jul 2012 00:09:17 +0000 (17:09 -0700)
committerBrian Norris <banorris@uci.edu>
Sat, 7 Jul 2012 00:30:57 +0000 (17:30 -0700)
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.

action.cc
action.h
libatomic.cc

index 68a34aad8c76476084052c8fa615c5c54a502e1f..d5131f0b03dfc9c7c9b86c901ca4215fbfac8245 100644 (file)
--- 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";
        }
index 4903f37b7720c4116943f5c542bcfa06ae92c8a8..f9c6d417084e62d39956ad1b1775c236b7bc48b8 100644 (file)
--- 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;
index 507f6853ca503e75664a86a5711f8f03c5cbc10a..a07653303c86348dfc5fe16fee790f137e478a11 100644 (file)
@@ -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));
 }