libatomic: add atomic_init()
authorBrian Norris <banorris@uci.edu>
Thu, 26 Apr 2012 23:16:23 +0000 (16:16 -0700)
committerBrian Norris <banorris@uci.edu>
Thu, 26 Apr 2012 23:16:23 +0000 (16:16 -0700)
libatomic.cc
libatomic.h
userprog.c

index 6734148dc2cdd117998c111903c83b2457b4be29..f552d93dd80a127b32a4f7ea76ec7cc3e8d5d6c6 100644 (file)
@@ -15,3 +15,8 @@ int atomic_load_explicit(struct atomic_object *obj, memory_order order)
        model->switch_to_master(new ModelAction(ATOMIC_READ, order, obj, VALUE_NONE));
        return obj->value;
 }
+
+void atomic_init(struct atomic_object *obj, int value)
+{
+       obj->value = value;
+}
index 684b213d11fc2dc3d6dc9ce307855445f4939c04..1806f21968b75405c1675a9456b4e79afa6f421f 100644 (file)
@@ -24,6 +24,8 @@ extern "C" {
        int atomic_load_explicit(struct atomic_object *obj, memory_order order);
 #define atomic_load(A) atomic_load_explicit((A), memory_order_seq_cst)
 
+       void atomic_init(struct atomic_object *obj, int value);
+
 #ifdef __cplusplus
 }
 #endif
index bab9f982a614c209c37acd84a06f41ffe061b35b..2847c1af8e55d69acfe4d7cffc65924bd0b96f46 100644 (file)
@@ -28,6 +28,8 @@ void user_main()
        thrd_t t1, t2;
        atomic_int obj;
 
+       atomic_init(&obj, 0);
+
        printf("Creating 2 threads\n");
        thrd_create(&t1, (thrd_start_t)&a, &obj);
        thrd_create(&t2, (thrd_start_t)&a, &obj);