Kill off register-queue
This commit is contained in:
parent
1cd3e3d004
commit
670f92c3f8
3 changed files with 0 additions and 120 deletions
|
@ -1,118 +0,0 @@
|
|||
#ifndef _library__register_queue__hpp__included__
|
||||
#define _library__register_queue__hpp__included__
|
||||
|
||||
#include "threads.hpp"
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
/**
|
||||
* Object registration queue.
|
||||
*/
|
||||
template<class G, class O>
|
||||
class register_queue
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Register an object.
|
||||
*
|
||||
* Parameter group: The group to register to.
|
||||
* Parameter name: The name for object.
|
||||
* Parameter object: The object to register.
|
||||
*/
|
||||
static void do_register(G& group, const std::string& name, O& object)
|
||||
{
|
||||
{
|
||||
threads::alock h(get_mutex());
|
||||
if(get_ready().count(&group)) {
|
||||
group.do_register(name, object);
|
||||
return;
|
||||
}
|
||||
queue_entry<G, O> ent;
|
||||
ent.group = &group;
|
||||
ent.name = name;
|
||||
ent.object = &object;
|
||||
get_pending().push_back(ent);
|
||||
}
|
||||
run();
|
||||
}
|
||||
/**
|
||||
* Unregister an object.
|
||||
*
|
||||
* Parameter group: The group to unregister from.
|
||||
* Parameter name: The name for object.
|
||||
*/
|
||||
static void do_unregister(G& group, const std::string& name)
|
||||
{
|
||||
threads::alock h(get_mutex());
|
||||
auto& x = get_pending();
|
||||
auto i = x.begin();
|
||||
O* obj = NULL;
|
||||
while(i != x.end()) {
|
||||
auto e = i++;
|
||||
if(&group == e->group && name == e->name)
|
||||
x.erase(e);
|
||||
}
|
||||
if(get_ready().count(&group))
|
||||
group.do_unregister(name, obj);
|
||||
}
|
||||
/**
|
||||
* Mark group ready/not ready.
|
||||
*
|
||||
* Parameter group: The group.
|
||||
* Parameter ready: True if ready, false if not.
|
||||
*/
|
||||
static void do_ready(G& group, bool ready)
|
||||
{
|
||||
{
|
||||
threads::alock h(get_mutex());
|
||||
if(ready)
|
||||
get_ready().insert(&group);
|
||||
else
|
||||
get_ready().erase(&group);
|
||||
}
|
||||
run();
|
||||
}
|
||||
private:
|
||||
template<class G2, class O2>
|
||||
struct queue_entry
|
||||
{
|
||||
G2* group;
|
||||
std::string name;
|
||||
O2* object;
|
||||
};
|
||||
static std::set<G*>& get_ready()
|
||||
{
|
||||
static std::set<G*> x;
|
||||
return x;
|
||||
}
|
||||
static std::list<queue_entry<G, O>>& get_pending()
|
||||
{
|
||||
static std::list<queue_entry<G, O>> x;
|
||||
return x;
|
||||
}
|
||||
static threads::lock& get_mutex()
|
||||
{
|
||||
static bool init = false;
|
||||
static threads::lock* x;
|
||||
if(!init)
|
||||
x = new threads::lock;
|
||||
init = true;
|
||||
return *x;
|
||||
}
|
||||
static void run()
|
||||
{
|
||||
threads::alock h(get_mutex());
|
||||
auto& x = get_pending();
|
||||
auto i = x.begin();
|
||||
while(i != x.end()) {
|
||||
auto e = i++;
|
||||
if(get_ready().count(e->group)) {
|
||||
e->group->do_register(e->name, *e->object);
|
||||
x.erase(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -3,7 +3,6 @@
|
|||
#include "interface/callbacks.hpp"
|
||||
#include "library/minmax.hpp"
|
||||
#include "library/string.hpp"
|
||||
#include "library/register-queue.hpp"
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "interface/setting.hpp"
|
||||
#include "library/register-queue.hpp"
|
||||
#include "library/string.hpp"
|
||||
|
||||
core_setting_value::core_setting_value(const core_setting_value_param& p) throw(std::bad_alloc)
|
||||
|
|
Loading…
Add table
Reference in a new issue