diff options
| -rw-r--r-- | builtins/array.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/builtins/array.h b/builtins/array.h index 0cbc12f8..9e74c41d 100644 --- a/builtins/array.h +++ b/builtins/array.h @@ -17,10 +17,12 @@ #define $Array_get_unchecked(type, x, i) ({ const array_t *$arr = x; int64_t $index = (int64_t)(i); \ int64_t $off = $index + ($index < 0) * ($arr->length + 1) - 1; \ *(type*)($arr->data + $arr->stride * $off);}) +#define $is_atomic(x) _Generic(x, bool: true, int8_t: true, int16_t: true, int32_t: true, int64_t: true, float: true, double: true, default: false) #define $Array(x, ...) ({ __typeof(x) $items[] = {x, __VA_ARGS__}; \ (array_t){.length=sizeof($items)/sizeof($items[0]), \ .stride=(int64_t)&$items[1] - (int64_t)&$items[0], \ - .data=memcpy(GC_MALLOC(sizeof($items)), $items, sizeof($items)), \ + .data=memcpy($is_atomic(x) ? GC_MALLOC_ATOMIC(sizeof($items)) : GC_MALLOC(sizeof($items)), $items, sizeof($items)), \ + .atomic=$is_atomic(x), \ .copy_on_write=1}; }) void Array__insert(array_t *arr, const void *item, int64_t index, const TypeInfo *type); |
