diff options
| author | Tyge Løvset <[email protected]> | 2021-12-22 12:35:36 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-12-22 12:35:36 +0100 |
| commit | 79c83eba7933f49e766dbeb85f9c40ee17e06edf (patch) | |
| tree | e43a84d18b79956a8e22b9403358811b6865f344 /include | |
| parent | 7a30e2853792870a1d85087861e46a1ae1ca6b0e (diff) | |
| download | STC-modified-79c83eba7933f49e766dbeb85f9c40ee17e06edf.tar.gz STC-modified-79c83eba7933f49e766dbeb85f9c40ee17e06edf.zip | |
Renamed csptr to carc. i_key/val_ref renamed to i_key/val_sptr. Change inspired by Rust Arc/Rc. cbox name is taken from Rust Box type.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/carc.h (renamed from include/stc/csptr.h) | 30 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 2 | ||||
| -rw-r--r-- | include/stc/forward.h | 4 | ||||
| -rw-r--r-- | include/stc/template.h | 16 |
4 files changed, 26 insertions, 26 deletions
diff --git a/include/stc/csptr.h b/include/stc/carc.h index 0718a4cc..505b47d9 100644 --- a/include/stc/csptr.h +++ b/include/stc/carc.h @@ -21,7 +21,7 @@ * SOFTWARE.
*/
-/* csptr: shared_ptr type
+/* carc: atomic reference counted shared_ptr
#include <stc/cstr.h>
typedef struct { cstr name, last; } Person;
@@ -37,19 +37,19 @@ void Person_drop(Person* p) { #define i_tag person
#define i_val Person
#define i_valdrop Person_drop
-#include <stc/csptr.h>
+#include <stc/carc.h>
int main() {
- csptr_person p = csptr_person_new(Person_new("John", "Smiths"));
- csptr_person q = csptr_person_clone(p); // share the pointer
+ carc_person p = carc_person_from(Person_new("John", "Smiths"));
+ carc_person q = carc_person_clone(p); // share the pointer
printf("%s %s. uses: %zu\n", q.get->name.str, q.get->last.str, *q.use_count);
- c_drop(csptr_person, &p, &q);
+ c_drop(carc_person, &p, &q);
}
*/
-#ifndef CSPTR_H_INCLUDED
-#define CSPTR_H_INCLUDED
+#ifndef CARC_H_INCLUDED
+#define CARC_H_INCLUDED
#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
@@ -67,12 +67,12 @@ int main() { #define c_atomic_dec_and_test(v) (atomic_fetch_sub(v, 1) == 1)
#endif
-#define csptr_null {NULL, NULL}
-#define _cx_csptr_rep struct _cx_memb(_rep_)
-#endif // CSPTR_H_INCLUDED
+#define carc_null {NULL, NULL}
+#define _cx_carc_rep struct _cx_memb(_rep_)
+#endif // CARC_H_INCLUDED
#ifndef _i_prefix
-#define _i_prefix csptr_
+#define _i_prefix carc_
#endif
#define _i_has_internal_clone
#include "template.h"
@@ -86,9 +86,9 @@ typedef i_valraw _cx_raw; #define _i_atomic_dec_and_test(v) !(--*(v))
#endif
#if !c_option(c_is_fwd)
-_cx_deftypes(_c_csptr_types, _cx_self, i_val);
+_cx_deftypes(_c_carc_types, _cx_self, i_val);
#endif
-_cx_csptr_rep { long counter; i_val value; };
+_cx_carc_rep { long counter; i_val value; };
STC_INLINE _cx_self
_cx_memb(_init)(void) { return c_make(_cx_self){NULL, NULL}; }
@@ -105,7 +105,7 @@ _cx_memb(_from_ptr)(_cx_value* p) { STC_INLINE _cx_self
_cx_memb(_from)(i_val val) {
- _cx_self ptr; _cx_csptr_rep *rep = c_alloc(_cx_csptr_rep);
+ _cx_self ptr; _cx_carc_rep *rep = c_alloc(_cx_carc_rep);
*(ptr.use_count = &rep->counter) = 1;
*(ptr.get = &rep->value) = val;
return ptr;
@@ -126,7 +126,7 @@ STC_INLINE void _cx_memb(_drop)(_cx_self* self) {
if (self->use_count && _i_atomic_dec_and_test(self->use_count)) {
i_valdrop(self->get);
- if (self->get != &((_cx_csptr_rep *)self->use_count)->value)
+ if (self->get != &((_cx_carc_rep *)self->use_count)->value)
c_free(self->get);
c_free(self->use_count);
}
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index ac6e9d31..4e2ee97d 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -199,7 +199,7 @@ STC_INLINE uint64_t c_default_hash(const void* key, size_t len) { for (size_t index = 0; index < _n; ++index) \
{ const T v = _c_arr[index]; method; } \
} while (0)
-#define c_apply_it(v, method, C, ...) do { \
+#define c_apply_cnt(v, method, C, ...) do { \
size_t index = 0; \
c_foreach (_it, C, __VA_ARGS__) \
{ const C##_value v = *_it.ref; method; ++index; } \
diff --git a/include/stc/forward.h b/include/stc/forward.h index bf2ba698..9a37297e 100644 --- a/include/stc/forward.h +++ b/include/stc/forward.h @@ -34,7 +34,7 @@ #define forward_cset(CX, KEY) _c_chash_types(CX, cset, KEY, KEY, c_false, c_true)
#define forward_csset(CX, KEY) _c_aatree_types(CX, KEY, KEY, c_false, c_true)
#define forward_cbox(CX, VAL) _c_cbox_types(CX, VAL)
-#define forward_csptr(CX, VAL) _c_csptr_types(CX, VAL)
+#define forward_carc(CX, VAL) _c_carc_types(CX, VAL)
#define forward_cpque(CX, VAL) _c_cpque_types(CX, VAL)
#define forward_cstack(CX, VAL) _c_cstack_types(CX, VAL)
#define forward_cqueue(CX, VAL) _c_cdeq_types(CX, VAL)
@@ -132,7 +132,7 @@ SELF##_value* get; \
} SELF
-#define _c_csptr_types(SELF, VAL) \
+#define _c_carc_types(SELF, VAL) \
typedef VAL SELF##_value; \
\
typedef struct { \
diff --git a/include/stc/template.h b/include/stc/template.h index 1d1551fa..5efe3772 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -61,9 +61,9 @@ #ifndef i_tag
#define i_tag str
#endif
-#elif defined i_key_ref
- #define i_key_bind i_key_ref
- #define i_keyraw c_PASTE(i_key_ref, _value)
+#elif defined i_key_sptr
+ #define i_key_bind i_key_sptr
+ #define i_keyraw c_PASTE(i_key_sptr, _value)
#endif
#ifdef i_key_bind
@@ -120,9 +120,9 @@ #if !defined i_tag && !defined i_key
#define i_tag str
#endif
-#elif defined i_val_ref
- #define i_val_bind i_val_ref
- #define i_valraw c_PASTE(i_val_ref, _value)
+#elif defined i_val_sptr
+ #define i_val_bind i_val_sptr
+ #define i_valraw c_PASTE(i_val_sptr, _value)
#endif
#ifdef i_val_bind
@@ -219,7 +219,7 @@ #undef i_val
#undef i_val_str
-#undef i_val_ref
+#undef i_val_sptr
#undef i_val_bind
#undef i_valraw
#undef i_valfrom
@@ -228,7 +228,7 @@ #undef i_key
#undef i_key_str
-#undef i_key_ref
+#undef i_key_sptr
#undef i_key_bind
#undef i_keyraw
#undef i_keyfrom
|
