preliminary implementation using pthread primitives. Locking test pass.
This commit is contained in:
parent
9240da002f
commit
67e95884d5
3 changed files with 40 additions and 22 deletions
|
|
@ -88,6 +88,7 @@ namespace lumiera {
|
|||
NOBUG_DECLARE_FLAG (render); ///< logging channel focusing on the render engine's workings
|
||||
NOBUG_DECLARE_FLAG (config); ///< logging channel covering application and session configuration
|
||||
NOBUG_DECLARE_FLAG (memory); ///< logging channel covering memory management issues
|
||||
NOBUG_DECLARE_FLAG (sync); ///< especially for tracing synchronisation
|
||||
NOBUG_DECLARE_FLAG (test);
|
||||
|
||||
|
||||
|
|
@ -109,6 +110,7 @@ namespace lumiera {
|
|||
NOBUG_CPP_DEFINE_FLAG_PARENT (operate, lumiera);
|
||||
NOBUG_CPP_DEFINE_FLAG_PARENT_LIMIT (render, lumiera, LOG_WARNING);
|
||||
NOBUG_CPP_DEFINE_FLAG_PARENT_LIMIT (memory, lumiera, LOG_WARNING);
|
||||
NOBUG_CPP_DEFINE_FLAG_PARENT_LIMIT (sync, memory, LOG_WARNING);
|
||||
NOBUG_CPP_DEFINE_FLAG_PARENT_LIMIT (test, all, LOG_ERR);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -47,14 +47,43 @@ extern "C" {
|
|||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
#include <iostream> ///////////////////////////TODO
|
||||
using std::cerr;
|
||||
|
||||
|
||||
namespace lib {
|
||||
|
||||
using boost::scoped_ptr;
|
||||
|
||||
|
||||
namespace sync { // Helpers for Monitor based synchronisation
|
||||
|
||||
class RecMutex
|
||||
{
|
||||
lumiera_mutex mtx_;
|
||||
|
||||
public:
|
||||
RecMutex() { lumiera_recmutex_init (&mtx_, "Obj.Monitor RecMutex", &NOBUG_FLAG (sync)); }
|
||||
~RecMutex() { lumiera_mutex_destroy (&mtx_, &NOBUG_FLAG (sync)); }
|
||||
|
||||
void acquire()
|
||||
{
|
||||
TODO ("Record we may block on mutex");
|
||||
|
||||
if (pthread_mutex_lock (&mtx_.mutex))
|
||||
throw lumiera::error::State("Mutex acquire failed."); ///////TODO capture the error-code
|
||||
|
||||
TODO ("Record we successfully acquired the mutex");
|
||||
}
|
||||
void release()
|
||||
{
|
||||
TODO ("Record we are releasing the mutex");
|
||||
pthread_mutex_unlock (&mtx_.mutex);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace sync
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Facility for monitor object based locking.
|
||||
* To be attached either on a per class base or per object base.
|
||||
|
|
@ -70,19 +99,12 @@ namespace lib {
|
|||
{
|
||||
struct Monitor
|
||||
{
|
||||
lumiera_mutex mtx_;
|
||||
sync::RecMutex mtx_;
|
||||
Monitor() {}
|
||||
~Monitor() {}
|
||||
|
||||
Monitor()
|
||||
{
|
||||
lumiera_recmutex_init (&mtx_, "Monitor object", &NOBUG_FLAG (memory));
|
||||
}
|
||||
~Monitor()
|
||||
{
|
||||
lumiera_mutex_destroy (&mtx_, &NOBUG_FLAG (memory));
|
||||
}
|
||||
|
||||
void acquireLock() { cerr << "acquire Thread Lock\n"; }
|
||||
void releaseLock() { cerr << "release Thread Lock\n"; }
|
||||
void acquireLock() { mtx_.acquire(); }
|
||||
void releaseLock() { mtx_.release(); }
|
||||
};
|
||||
|
||||
Monitor objectMonitor_;
|
||||
|
|
|
|||
|
|
@ -22,21 +22,14 @@
|
|||
|
||||
|
||||
#include "lib/test/run.hpp"
|
||||
//#include "common/util.hpp"
|
||||
#include "include/error.hpp"
|
||||
|
||||
#include "lib/concurrency.hpp"
|
||||
|
||||
#include <glibmm.h>
|
||||
|
||||
//#include <boost/lexical_cast.hpp>
|
||||
//#include <boost/format.hpp>
|
||||
#include <iostream>
|
||||
|
||||
//using boost::lexical_cast;
|
||||
//using boost::format;
|
||||
//using util::isnil;
|
||||
//using std::string;
|
||||
using std::cout;
|
||||
using test::Test;
|
||||
|
||||
|
|
@ -178,7 +171,8 @@ namespace lib {
|
|||
class ConcurrencyLocking_test : public Test
|
||||
{
|
||||
|
||||
virtual void run(Arg arg)
|
||||
virtual void
|
||||
run (Arg)
|
||||
{
|
||||
if (!Glib::thread_supported())
|
||||
Glib::thread_init();
|
||||
|
|
|
|||
Loading…
Reference in a new issue