summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-06-11 08:16:44 +0200
committerTyge Løvset <[email protected]>2021-06-11 08:16:44 +0200
commitc7944e2ddb51819dfaee9dd8d3708df54bd5a5d1 (patch)
treed7efc621b9e9008359f9cf1a6e21f1582d7e5c88
parent5c8fc711e839287935b4090a55079496901d4626 (diff)
downloadSTC-modified-c7944e2ddb51819dfaee9dd8d3708df54bd5a5d1.tar.gz
STC-modified-c7944e2ddb51819dfaee9dd8d3708df54bd5a5d1.zip
Added missing csptr_X_init() and csptr_X_use_count().
-rw-r--r--docs/csptr_api.md17
-rw-r--r--include/stc/csptr.h6
2 files changed, 15 insertions, 8 deletions
diff --git a/docs/csptr_api.md b/docs/csptr_api.md
index 96cc34d5..10d3bb77 100644
--- a/docs/csptr_api.md
+++ b/docs/csptr_api.md
@@ -36,18 +36,19 @@ Use *csptr_X_clone(p)* when sharing ownership of the pointed-to object. See exam
The *csptr_X_compare()*, *csptr_X_equals()* and *csptr_X_del()* methods are defined based on the *valeCompare* and *valueDel* arguments passed to the **using**-macro.
```c
-csptr_X csptr_X_from(Value* p); // constructor
-csptr_X csptr_X_make(Value val); // make_shared; fast
+csptr_X csptr_X_init(); // empty constructor
+csptr_X csptr_X_make(Value val); // make_shared constructor, fast
+csptr_X csptr_X_from(Value* p); // construct from raw pointer
+csptr_X csptr_X_clone(csptr_X ptr); // clone shared (increase use count)
+csptr_X csptr_X_move(csptr_X* self); // fast transfer ownership to another sptr.
+
+void csptr_X_del(csptr_X* self); // destruct (decrease use count, free at 0)
+long csptr_X_use_count(csptr_X ptr);
void csptr_X_reset(csptr_X* self);
-csptr_X_value_t* csptr_X_reset_with(csptr_X* self, Value* p); // slower than reset_make().
csptr_X_value_t* csptr_X_reset_make(csptr_X* self, Value val); // assign new sptr with value
-
+csptr_X_value_t* csptr_X_reset_with(csptr_X* self, Value* p); // slower than reset_make().
csptr_X_value_t* csptr_X_copy(csptr_X* self, CX other); // copy shared (increase use count)
-csptr_X csptr_X_clone(csptr_X ptr); // clone shared (increase use count)
-
-csptr_X csptr_X_move(csptr_X* self); // fast transfer ownership to another sptr.
-void csptr_X_del(csptr_X* self); // destruct: decrease use count, free at 0
int csptr_X_compare(const csptr_X* x, const csptr_X* y);
bool csptr_X_equals(const csptr_X* x, const csptr_X* y);
diff --git a/include/stc/csptr.h b/include/stc/csptr.h
index 70bd87f0..c6c36fb0 100644
--- a/include/stc/csptr.h
+++ b/include/stc/csptr.h
@@ -96,6 +96,12 @@ typedef long atomic_count_t;
struct CX##_rep_ {atomic_count_t cnt; CX##_value_t val;}; \
\
STC_INLINE CX \
+ CX##_init() { return c_make(CX){NULL, NULL}; } \
+\
+ STC_INLINE atomic_count_t \
+ CX##_use_count(CX ptr) { return ptr.use_count ? *ptr.use_count : 0; } \
+\
+ STC_INLINE CX \
CX##_from(CX##_value_t* p) { \
CX ptr = {p}; \
if (p) *(ptr.use_count = c_new(atomic_count_t)) = 1; \