28 using namespace basis;
36 callback_data_block::~callback_data_block() {}
40 class live_object_info
45 live_object_info() : _references(1) {}
50 static bool _live_objects_are_gone =
false;
54 class global_live_objects :
public virtual root_object
60 ~global_live_objects() { _live_objects_are_gone =
true; }
65 bool listed(
void *
object) {
68 return _objects.find(
object, loi);
72 void add(
void *
object) {
75 if (!_objects.find(
object, loi)) {
77 _objects.add(
object,
new live_object_info);
86 void remove(
void *
object) {
89 if (!_objects.find(
object, loi)) {
95 if (!loi->_references) {
109 safe_callback::safe_callback()
111 _callback_lock(new
mutex)
112 { begin_availability(); }
118 "the derived safe_callback has not called end_availability() yet.\r\n"
119 "this violates caveat two of safe_callback (see header).");
120 WHACK(_callback_lock);
132 if (_live_objects_are_gone)
return;
133 _invocables().add(
this);
138 if (_decoupled)
return;
139 if (_live_objects_are_gone) {
144 _callback_lock->
lock();
150 WHACK(_callback_lock);
159 if (_decoupled)
return false;
auto_synchronizer simplifies concurrent code by automatically unlocking.
void lock()
Clamps down on the mutex, if possible.
void unlock()
Gives up the possession of the mutex.
a simple place-holder that anonymizes the type passed to the callback.
A reasonably easy way to make callbacks safe from shutdown ordering issues.
bool invoke_callback(callback_data_block &new_data)
this function is invoked by a user of the safe_callback derived object.
virtual void real_callback(callback_data_block &new_data)=0
derived classes implement this to provide their callback functionality.
void end_availability()
prepares to shut down this object.
virtual ~safe_callback()
actually destroys the object.
global_live_objects & _invocables()
provides access to the program-wide list of healthy callback objects.
Implements a hashing algorithm based on the contents stored in an object.
#define non_continuable_error(c, f, i)
an extra piece of information used, if available, in bounds_halt below.
#define NULL_POINTER
The value representing a pointer to nothing.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.
#define SAFE_STATIC(type, func_name, parms)
Statically defines a singleton object whose scope is the program's lifetime.