push accessing the DiagnosticContext down one layer
accessing the DiagnosticContext now inline when providing the paramters for calling the C-functions. No change in functionality, but saves us a lot of syntactic noise.
This commit is contained in:
parent
3466793976
commit
b41bd20de4
1 changed files with 436 additions and 409 deletions
171
src/lib/sync.hpp
171
src/lib/sync.hpp
|
|
@ -87,144 +87,179 @@ using boost::noncopyable;
|
||||||
|
|
||||||
namespace lib {
|
namespace lib {
|
||||||
|
|
||||||
|
|
||||||
/** Helpers and building blocks for Monitor based synchronisation */
|
/** Helpers and building blocks for Monitor based synchronisation */
|
||||||
namespace sync {
|
namespace sync {
|
||||||
|
|
||||||
|
|
||||||
|
namespace { // implementation shortcuts...
|
||||||
|
|
||||||
|
inline DiagnosticContext&
|
||||||
|
_accessContext()
|
||||||
|
{
|
||||||
|
return DiagnosticContext::access();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ========== adaptation layer for accessing the backend code ============== */
|
/* ========== adaptation layer for accessing the backend code ============== */
|
||||||
|
|
||||||
struct Wrapped_LumieraExcMutex
|
struct Wrapped_LumieraExcMutex
|
||||||
{
|
{
|
||||||
lumiera_mutex self;
|
lumiera_mutex self_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Wrapped_LumieraExcMutex(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
Wrapped_LumieraExcMutex()
|
||||||
{ lumiera_mutex_init (&self, "Obj.Monitor ExclMutex", &NOBUG_FLAG(sync), ctx); }
|
{ //TODO: currently passing no lineno/function info, put planning to use the DiagnosticContext to provide something in place of that later...
|
||||||
|
lumiera_mutex_init (&self_, "Obj.Monitor ExclMutex", &NOBUG_FLAG(sync), NOBUG_CONTEXT_NOFUNC);
|
||||||
|
}
|
||||||
~Wrapped_LumieraExcMutex()
|
~Wrapped_LumieraExcMutex()
|
||||||
{ lumiera_mutex_destroy (&self, &NOBUG_FLAG(sync), NOBUG_CONTEXT); }
|
|
||||||
|
|
||||||
bool lock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
|
||||||
{
|
{
|
||||||
return !!lumiera_mutex_lock (&self, &NOBUG_FLAG(sync), handle, ctx);
|
lumiera_mutex_destroy (&self_, &NOBUG_FLAG(sync), NOBUG_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void unlock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
bool
|
||||||
|
lock()
|
||||||
{
|
{
|
||||||
lumiera_mutex_unlock (&self, &NOBUG_FLAG(sync), handle, ctx);
|
return !!lumiera_mutex_lock (&self_, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
LumieraReccondition myreccond () {throw "bullshit"; return NULL;} // placeholder, brainstorm
|
void
|
||||||
|
unlock()
|
||||||
|
{
|
||||||
|
lumiera_mutex_unlock (&self_, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct Wrapped_LumieraRecMutex
|
struct Wrapped_LumieraRecMutex
|
||||||
{
|
{
|
||||||
lumiera_recmutex self;
|
lumiera_recmutex self_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Wrapped_LumieraRecMutex(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
Wrapped_LumieraRecMutex()
|
||||||
{ lumiera_recmutex_init (&self, "Obj.Monitor RecMutex", &NOBUG_FLAG(sync), ctx); }
|
{
|
||||||
|
lumiera_recmutex_init (&self_, "Obj.Monitor RecMutex", &NOBUG_FLAG(sync), NOBUG_CONTEXT_NOFUNC);
|
||||||
|
}
|
||||||
~Wrapped_LumieraRecMutex()
|
~Wrapped_LumieraRecMutex()
|
||||||
{ lumiera_recmutex_destroy (&self, &NOBUG_FLAG(sync), NOBUG_CONTEXT); }
|
|
||||||
|
|
||||||
bool lock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
|
||||||
{
|
{
|
||||||
return !!lumiera_recmutex_lock (&self, &NOBUG_FLAG(sync), handle, ctx);
|
lumiera_recmutex_destroy (&self_, &NOBUG_FLAG(sync), NOBUG_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void unlock (struct nobug_resource_user** handle,
|
bool
|
||||||
const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
lock()
|
||||||
{
|
{
|
||||||
lumiera_recmutex_unlock (&self, &NOBUG_FLAG(sync), handle, ctx);
|
return !!lumiera_recmutex_lock (&self_, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
LumieraReccondition myreccond () {throw "bullshit"; return NULL;} // placeholder, brainstorm
|
void
|
||||||
|
unlock()
|
||||||
|
{
|
||||||
|
lumiera_recmutex_unlock (&self_, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct Wrapped_LumieraExcCond
|
struct Wrapped_LumieraExcCond
|
||||||
{
|
{
|
||||||
lumiera_condition self;
|
lumiera_condition self_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Wrapped_LumieraExcCond(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
Wrapped_LumieraExcCond()
|
||||||
{ lumiera_condition_init (&self, "Obj.Monitor ExclCondition", &NOBUG_FLAG(sync), ctx); }
|
{
|
||||||
|
lumiera_condition_init (&self_, "Obj.Monitor ExclCondition", &NOBUG_FLAG(sync), NOBUG_CONTEXT_NOFUNC);
|
||||||
|
}
|
||||||
~Wrapped_LumieraExcCond()
|
~Wrapped_LumieraExcCond()
|
||||||
{ lumiera_condition_destroy (&self, &NOBUG_FLAG(sync), NOBUG_CONTEXT); }
|
|
||||||
|
|
||||||
bool lock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
|
||||||
{
|
{
|
||||||
return !!lumiera_condition_lock (&self, &NOBUG_FLAG(sync), handle, ctx);
|
lumiera_condition_destroy (&self_, &NOBUG_FLAG(sync), NOBUG_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wait (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
bool
|
||||||
|
lock()
|
||||||
{
|
{
|
||||||
return !!lumiera_condition_wait (&self, &NOBUG_FLAG(sync), handle, ctx);
|
return !!lumiera_condition_lock (&self_, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool timedwait (const struct timespec* timeout,
|
void
|
||||||
struct nobug_resource_user** handle,
|
unlock()
|
||||||
const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
|
||||||
{
|
{
|
||||||
return !!lumiera_condition_timedwait (&self, timeout, &NOBUG_FLAG(sync), handle, ctx);
|
lumiera_condition_unlock (&self_, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void signal(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
bool
|
||||||
|
wait()
|
||||||
{
|
{
|
||||||
lumiera_condition_signal (&self, &NOBUG_FLAG(sync), ctx);
|
return !!lumiera_condition_wait (&self_, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcast(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
bool
|
||||||
|
timedwait (const struct timespec* timeout)
|
||||||
{
|
{
|
||||||
lumiera_condition_broadcast (&self, &NOBUG_FLAG(sync), ctx);
|
return !!lumiera_condition_timedwait (&self_, timeout, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void unlock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
void
|
||||||
|
signal()
|
||||||
{
|
{
|
||||||
lumiera_condition_unlock (&self, &NOBUG_FLAG(sync), handle, ctx);
|
lumiera_condition_signal (&self_, &NOBUG_FLAG(sync), NOBUG_CONTEXT_NOFUNC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
broadcast()
|
||||||
|
{
|
||||||
|
lumiera_condition_broadcast (&self_, &NOBUG_FLAG(sync), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct Wrapped_LumieraRecCond
|
struct Wrapped_LumieraRecCond
|
||||||
{
|
{
|
||||||
lumiera_reccondition self;
|
lumiera_reccondition self_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Wrapped_LumieraRecCond(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
Wrapped_LumieraRecCond()
|
||||||
{ lumiera_reccondition_init (&self, "Obj.Monitor RecCondition", &NOBUG_FLAG(sync), ctx); }
|
{
|
||||||
|
lumiera_reccondition_init (&self_, "Obj.Monitor RecCondition", &NOBUG_FLAG(sync), NOBUG_CONTEXT_NOFUNC);
|
||||||
|
}
|
||||||
~Wrapped_LumieraRecCond()
|
~Wrapped_LumieraRecCond()
|
||||||
{ lumiera_reccondition_destroy (&self, &NOBUG_FLAG(sync), NOBUG_CONTEXT); }
|
|
||||||
|
|
||||||
bool lock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
|
||||||
{
|
{
|
||||||
return !!lumiera_reccondition_lock (&self, &NOBUG_FLAG(sync), handle, ctx);
|
lumiera_reccondition_destroy (&self_, &NOBUG_FLAG(sync), NOBUG_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wait (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
bool
|
||||||
|
lock()
|
||||||
{
|
{
|
||||||
return !!lumiera_reccondition_wait (&self, &NOBUG_FLAG(sync), handle, ctx);
|
return !!lumiera_reccondition_lock (&self_, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool timedwait (const struct timespec* timeout,
|
void
|
||||||
struct nobug_resource_user** handle,
|
unlock ()
|
||||||
const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
|
||||||
{
|
{
|
||||||
return !!lumiera_reccondition_timedwait (&self, timeout, &NOBUG_FLAG(sync), handle, ctx);
|
lumiera_reccondition_unlock (&self_, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void signal(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
bool
|
||||||
|
wait()
|
||||||
{
|
{
|
||||||
lumiera_reccondition_signal (&self, &NOBUG_FLAG(sync), ctx);
|
return !!lumiera_reccondition_wait (&self_, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcast(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
bool
|
||||||
|
timedwait (const struct timespec* timeout)
|
||||||
{
|
{
|
||||||
lumiera_reccondition_broadcast (&self, &NOBUG_FLAG(sync), ctx);
|
return !!lumiera_reccondition_timedwait (&self_, timeout, &NOBUG_FLAG(sync), _accessContext(), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void unlock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC)
|
void
|
||||||
|
signal()
|
||||||
{
|
{
|
||||||
lumiera_reccondition_unlock (&self, &NOBUG_FLAG(sync), handle, ctx);
|
lumiera_reccondition_signal (&self_, &NOBUG_FLAG(sync), NOBUG_CONTEXT_NOFUNC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
broadcast()
|
||||||
|
{
|
||||||
|
lumiera_reccondition_broadcast (&self_, &NOBUG_FLAG(sync), NOBUG_CONTEXT_NOFUNC);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -238,12 +273,6 @@ namespace lib {
|
||||||
: protected MTX
|
: protected MTX
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
DiagnosticContext&
|
|
||||||
_usage()
|
|
||||||
{
|
|
||||||
return DiagnosticContext::access();
|
|
||||||
}
|
|
||||||
|
|
||||||
~Mutex () { }
|
~Mutex () { }
|
||||||
Mutex () { }
|
Mutex () { }
|
||||||
Mutex (const Mutex&); ///< noncopyable...
|
Mutex (const Mutex&); ///< noncopyable...
|
||||||
|
|
@ -253,13 +282,13 @@ namespace lib {
|
||||||
void
|
void
|
||||||
acquire()
|
acquire()
|
||||||
{
|
{
|
||||||
MTX::lock (_usage());
|
MTX::lock ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
release()
|
release()
|
||||||
{
|
{
|
||||||
MTX::unlock (_usage());
|
MTX::unlock ();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -291,9 +320,9 @@ namespace lib {
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
while (ok && !predicate())
|
while (ok && !predicate())
|
||||||
if (waitEndTime)
|
if (waitEndTime)
|
||||||
ok = CDX::timedwait (&waitEndTime, this->_usage());
|
ok = CDX::timedwait (&waitEndTime);
|
||||||
else
|
else
|
||||||
ok = CDX::wait (this->_usage());
|
ok = CDX::wait ();
|
||||||
|
|
||||||
if (!ok && lumiera_error_expect(LUMIERA_ERROR_LOCK_TIMEOUT)) return false;
|
if (!ok && lumiera_error_expect(LUMIERA_ERROR_LOCK_TIMEOUT)) return false;
|
||||||
lumiera::throwOnError(); // any other error thows
|
lumiera::throwOnError(); // any other error thows
|
||||||
|
|
@ -508,8 +537,6 @@ namespace lib {
|
||||||
Monitor&
|
Monitor&
|
||||||
accessMonitor() { return mon_; }
|
accessMonitor() { return mon_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue