diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-02-23 13:40:24 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-02-23 13:40:24 -0500 |
| commit | c04b373cb49df5d3505247ae141d77cd84adf1ff (patch) | |
| tree | 06d239f7b9e01abb89ed1da15329206c65102430 | |
| parent | 4df2f8e4cba30b2b38da005926fc8d49ab7ff45e (diff) | |
Set up 'atomic' for arrays
| -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); |
