8#include <cx/thread/atomic.h>
73 intptr (*
_cmp)(
void *self,
void *other, uint32 flags);
76 uint32 (*
_hash)(
void *self, uint32 flags);
86#define objClassInfoName(cname) cname##_clsinfo
128#define Weak(clsname) clsname##_WeakRef
136#define ObjInst(inst) ((ObjInst*)(unused_noeval(&((inst)->_is_ObjInst)), (inst)))
144#define ObjInst_WeakRef(ref) ((ObjInst_WeakRef*)(unused_noeval(&((ref)->_is_ObjInst_WeakRef)), (ref)))
152#define objInstBase(inst) ObjInst(inst)
160#define objWeakRefBase(ref) ObjInst_WeakRef(ref)
168#define objClsInfo(inst) (inst->_clsinfo)
176_meta_inline
void _objAcquire(_In_opt_
ObjInst *inst)
179 atomicFetchAdd(uintptr, &inst->_ref, 1, Relaxed);
199#define objAcquire(inst) (_objAcquire(objInstBase(inst)), (inst))
201_At_(*instp, _Pre_maybenull_ _Post_null_)
202void _objRelease(_Inout_
ObjInst **instp);
223#define objRelease(pinst) (unused_noeval(&((*(pinst))->_is_ObjInst)), _objRelease((ObjInst**)(pinst)))
237#define objClassIf(clsname, ifname) ((ifname*)_objClassIf(&objClassInfoName(clsname), objIfBase(&objIfTmplName(ifname))))
259#define objInstIf(inst, ifname) ((ifname*)_objInstIf(objInstBase(inst), objIfBase(&objIfTmplName(ifname))))
273#define objGetWeak(clsname, inst) ((Weak(clsname)*)_objGetWeak((ObjInst*)clsname(inst)))
285#define objCloneWeak(ref) (_objCloneWeak(objWeakRefBase(ref)))
303#define objDestroyWeak(pref) (unused_noeval(&((*(pref))->_is_ObjInst_WeakRef)), _objDestroyWeak((ObjInst_WeakRef**)(pref)))
328#define objAcquireFromWeak(clsname, ref) ((clsname*)_objAcquireFromWeak((ObjInst_WeakRef*)Weak(clsname)(ref)))
350#define objDynCast(clsname, inst) ((clsname*)_objDynCast(objInstBase(inst), &objClassInfoName(clsname)))
364#define objAcquireFromWeakDyn(clsname, ref) ((clsname*)_objAcquireFromWeakDyn(objWeakRefBase(ref), &objClassInfoName(clsname)))
void _objDestroy(ObjInst *inst)
#define ObjInst_WeakRef(ref)
Hash table container with type-safe generic key-value storage.
Interface definitions and management for the object system.
Reader-writer lock synchronization primitive.
bool(* init)(void *_self)
bool _abstract
True if this is an abstract class (cannot be instantiated)
uint32(* _hash)(void *self, uint32 flags)
Cached function pointer for Hashable.hash interface (NULL if not implemented)
hashtable _tmpl
Maps interface templates to populated implementations.
ObjClassInfo * parent
Parent class (NULL if no parent)
ObjIface * classif
Class interface (methods specific to this class, optional)
ObjIface ** ifimpl
NULL-terminated array of interface implementations.
void(* destroy)(void *_self)
size_t instsize
Size in bytes of a class instance.
intptr(* _cmp)(void *self, void *other, uint32 flags)
Cached function pointer for Sortable.cmp interface (NULL if not implemented)
sa_ObjIface _impl
Storage for hydrated interface implementations.
RWLock _lock
Protects access during object destruction.
ObjInst * _inst
Pointer to the referenced object (NULL if destroyed)
atomic(uintptr) _ref
Reference count for the weak reference itself.
void * _is_ObjInst_WeakRef
Type marker for compile-time validation.
void * _is_ObjInst
Type marker for compile-time validation.
ObjIface * _classif
Class interface (vtable) - called _ in generated class code.
atomic(ptr) _weakref
Associated weak reference object (NULL if none exist)
atomic(uintptr) _ref
Reference count for memory management.
ObjClassInfo * _clsinfo
Pointer to class metadata.
Macros for suppressing compiler warnings.