13
0

triggerbox: initial implementation of thread-based deleter for Triggers

Uses a custom deleter for the shared_ptr<Trigger>'s that we create. Will
likely evolve to use an allocator so that we can use make_shared's
cousin allocate_shared().
This commit is contained in:
Paul Davis 2021-12-24 14:12:13 -07:00
parent 7afc8f7a31
commit 401411d5c3
2 changed files with 39 additions and 2 deletions

View File

@ -244,6 +244,8 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
virtual SegmentDescriptor get_segment_descriptor () const = 0;
static void request_trigger_delete (Trigger* t);
protected:
struct UIRequests {
std::atomic<bool> stop;
@ -432,6 +434,7 @@ class LIBARDOUR_API TriggerBoxThread
static void init_request_pool() { Request::init_pool(); }
void set_region (TriggerBox&, uint32_t slot, boost::shared_ptr<Region>);
void request_delete_trigger (Trigger* t);
void summon();
void stop();
@ -443,7 +446,8 @@ class LIBARDOUR_API TriggerBoxThread
enum RequestType {
Quit,
SetRegion
SetRegion,
DeleteTrigger
};
struct Request {
@ -455,6 +459,8 @@ class LIBARDOUR_API TriggerBoxThread
TriggerBox* box;
uint32_t slot;
boost::shared_ptr<Region> region;
/* for DeleteTrigger */
Trigger* trigger;
void* operator new (size_t);
void operator delete (void* ptr, size_t);
@ -468,6 +474,7 @@ class LIBARDOUR_API TriggerBoxThread
CrossThreadChannel _xthread;
void queue_request (Request*);
void delete_trigger (Trigger*);
};
@ -620,6 +627,10 @@ class LIBARDOUR_API TriggerBox : public Processor
Type type;
/* cannot use a union here because we need Request to have a
* "trivial" constructor.
*/
TriggerPtr trigger;
void* ptr;
int32_t slot;

View File

@ -110,6 +110,13 @@ Trigger::Trigger (uint32_t n, TriggerBox& b)
add_property (_isolated);
}
void
Trigger::request_trigger_delete (Trigger* t)
{
std::cerr << "RTD\n";
TriggerBox::worker->request_delete_trigger (t);
}
void
Trigger::set_pending (Trigger* t)
{
@ -2735,7 +2742,7 @@ TriggerBox::set_state (const XMLNode& node, int version)
TriggerPtr trig;
if (_data_type == DataType::AUDIO) {
trig = boost::make_shared<AudioTrigger> (all_triggers.size(), *this);
trig.reset (new AudioTrigger (all_triggers.size(), *this), Trigger::request_trigger_delete);
all_triggers.push_back (trig);
trig->set_state (**t, version);
} else if (_data_type == DataType::MIDI) {
@ -2918,6 +2925,9 @@ TriggerBoxThread::thread_work ()
case SetRegion:
req->box->set_region (req->slot, req->region);
break;
case DeleteTrigger:
delete_trigger (req->trigger);
break;
default:
break;
}
@ -2976,3 +2986,19 @@ TriggerBoxThread::set_region (TriggerBox& box, uint32_t slot, boost::shared_ptr<
queue_request (req);
}
void
TriggerBoxThread::request_delete_trigger (Trigger* t)
{
std::cerr << "RDT\n";
TriggerBoxThread::Request* req = new TriggerBoxThread::Request (DeleteTrigger);
req->trigger = t;
queue_request (req);
}
void
TriggerBoxThread::delete_trigger (Trigger* t)
{
std::cerr << "trigger delete for " << t << endl;
delete t;
}