SafeTypes2
|
The object base type and auxiliary definitions for all of SafeTypes2. More...
#include "common.h"
Classes | |
struct | s2ctx_iter |
The struct s2ctx_iter defines publically visible members of the iterator base type structure. More... | |
Macros | |
#define | s2obj_base struct { s2obj_t base; s2obj_t *pobj; intptr_t ctxinfo; } |
Base header for objects. | |
Typedefs | |
typedef T | s2obj_t |
the working context for the base object type s2obj_t . In the following prose, s2obj_t will be abbreviated as T . | |
typedef struct s2ctx_iter | s2iter_t |
The base type of various iterators. | |
typedef int(* | s2iter_stepfunc_t) (s2iter_t *restrict ctx) |
The iterator stepping function. | |
typedef void(* | s2iter_final_func_t) (s2iter_t *restrict ctx) |
frees up resources used by the iterator. | |
typedef s2iter_t *(* | s2func_iter_create_t) (T *restrict ctx) |
typedef void(* | s2func_final_t) (T *restrict ctx) |
subroutine type for the finalizer slot. | |
Functions | |
T * | s2gc_obj_alloc (s2obj_typeid_t type, size_t sz) |
Allocates memory for an object. Invoked by type implementations. | |
void | s2gc_obj_dealloc (T *restrict obj) |
Deallocates memory for the object. Invoked by type implementations. | |
void | s2gc_set_threading (bool enabled) |
enable or disable threading support in garbage collector. | |
void | s2gc_collect (void) |
Explicitly invoke SafeTypes2 garbage collection. Applications that never creates reference cycles don't need this. | |
T * | s2obj_retain (T *restrict obj) |
Increases reference count. Invoked by the application. | |
T * | s2obj_keep (T *restrict obj) |
Increases 'kept' count. Invoked by container implementations. | |
void | s2obj_release (T *restrict obj) |
Decreases reference count. Invoked by the application. | |
void | s2obj_leave (T *restrict obj) |
Decreases 'kept' count. Invoked by container implementations. | |
s2iter_t * | s2obj_iter_create (T *restrict obj) |
creates an iterator by invoking the internal itercreatf . | |
int | s2gc_thrd_lock () |
To obtain a "reader" lock for the application thread. ("thrd" is a fortunate portmanteau of "thread-reading".) | |
int | s2gc_thrd_unlock () |
To release the "reader" lock from a application thread. | |
The object base type and auxiliary definitions for all of SafeTypes2.
Base header for objects.
This is the base object header to be placed at the beginning of all types derived from s2obj_t
.
pobj
field will point to the beginning address of the object, which make it easy to refer to the object itself as an s2obj_t
.ctxinfo
can hold contextual information for arbitrary purpose. typedef void(* s2func_final_t) (T *restrict ctx) |
subroutine type for the finalizer slot.
ctx | the handle pointer to the object to finalize. |
When both the reference and the kept count of an object is zero, its finalization routine is invoked and object is freed.
typedef s2iter_t *(* s2func_iter_create_t) (T *restrict ctx) |
typedef void(* s2iter_final_func_t) (s2iter_t *restrict ctx) |
frees up resources used by the iterator.
ctx | the pointer handle to the iterator |
typedef int(* s2iter_stepfunc_t) (s2iter_t *restrict ctx) |
The iterator stepping function.
ctx | the pointer handle to the iterator. |
Iterator creator functions doen't set the position, a initial call to step function is needed to initialize the position of the iterator.
void s2gc_collect | ( | void | ) |
Explicitly invoke SafeTypes2 garbage collection. Applications that never creates reference cycles don't need this.
T * s2gc_obj_alloc | ( | s2obj_typeid_t | type, |
size_t | sz ) |
Allocates memory for an object. Invoked by type implementations.
type | the type id for the object, see Type Identifier Name Space. |
void s2gc_obj_dealloc | ( | T *restrict | obj | ) |
Deallocates memory for the object. Invoked by type implementations.
obj | the object to deallocate. |
additional resources are released by finalizer.
void s2gc_set_threading | ( | bool | enabled | ) |
enable or disable threading support in garbage collector.
enabled | true to enable threading, and false to disable it. |
2024-03-09: It is assumed that this will only be called when there's only 1 thread. By default, threading is enabled for GC, and this function is provided for single-threaded applications to avoid synchronization overheads.
int s2gc_thrd_lock | ( | ) |
To obtain a "reader" lock for the application thread. ("thrd" is a fortunate portmanteau of "thread-reading".)
int s2gc_thrd_unlock | ( | ) |
To release the "reader" lock from a application thread.
s2iter_t * s2obj_iter_create | ( | T *restrict | obj | ) |
creates an iterator by invoking the internal itercreatf
.
obj | the object of which the iterator is created. |
T * s2obj_keep | ( | T *restrict | obj | ) |
Increases 'kept' count. Invoked by container implementations.
s2obj_retain
in builds without GC. void s2obj_leave | ( | T *restrict | obj | ) |
Decreases 'kept' count. Invoked by container implementations.
s2obj_release
in builds without GC. T * s2obj_retain | ( | T *restrict | obj | ) |
Increases reference count. Invoked by the application.