/[svn]/linuxsampler/trunk/src/plugins/InstrumentEditor.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/plugins/InstrumentEditor.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3766 - (show annotations) (download)
Mon Apr 6 12:41:49 2020 UTC (4 years ago) by schoenebeck
File size: 5335 byte(s)
Fixed deadlocks (e.g. when restarting engines).

* Individual thread implementations (e.g. disk thread, etc.):
  Disable thread cancellation on critical sections, e.g. when holding
  mutex locks, to prevent deadlocks if thread is stopped and/or
  restarted.

* Added TestCancel() calls to thread implementations if missing.

* No need to wrap Thread::TestCancel() calls into
  CONFIG_PTHREAD_TESTCANCEL macro conditions (since TestCancel() is
  already a stub on systems which don't have pthread_testcancel()
  available).

* If compiled for debugging: give each thread a human readable name
  to simplify debugging of multi-threading issues.

* DiskThreadBase: TestCancel() and pthread_testcancel() calls are
  per-se redundant, so only call TestCancel().

* Added missing override keywords to silent compiler warnings.

* Bumped version (2.1.1.svn54).

1 /***************************************************************************
2 * *
3 * Copyright (C) 2007 - 2020 Christian Schoenebeck *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18 * MA 02111-1307 USA *
19 ***************************************************************************/
20
21 #include "InstrumentEditor.h"
22
23 #include "../common/global_private.h"
24
25 #include <algorithm>
26 #include <functional>
27
28 namespace LinuxSampler {
29
30 InstrumentEditor::InstrumentEditor() : Thread(false, false, -1, 0) {
31 pInstrument = NULL;
32 pUserData = NULL;
33 pEngineChannel = NULL;
34 }
35
36 InstrumentEditor::~InstrumentEditor() {
37 }
38
39 void InstrumentEditor::Launch(EngineChannel* pEngineChannel, void* pInstrument, String sTypeName, String sTypeVersion, void* pUserData) {
40 dmsg(1,("InstrumentEditor::Launch(instr=%p,type=%s,version=%s)\n", pInstrument, sTypeName.c_str(), sTypeVersion.c_str()));
41 // prepare the editor's mandatory parameters
42 this->pInstrument = pInstrument;
43 this->sTypeName = sTypeName;
44 this->sTypeVersion = sTypeVersion;
45 this->pUserData = pUserData;
46 this->pEngineChannel = pEngineChannel;
47 // start the editor in its own thread
48 StartThread();
49 }
50
51 int InstrumentEditor::Main() {
52 dmsg(1,("InstrumentEditor::Main()\n"));
53
54 #if DEBUG
55 Thread::setNameOfCaller("InstrEditorPlug");
56 #endif
57
58 // run the editor's main loop
59 int iResult = Main(pInstrument, sTypeName, sTypeVersion, pUserData);
60 // reset editor parameters
61 this->pInstrument = NULL;
62 this->sTypeName = "";
63 this->sTypeVersion = "";
64 this->pUserData = NULL;
65 dmsg(1,("Instrument editor '%s' returned with exit status %d\n", Name().c_str(), iResult));
66 // notify all registered listeners
67 std::for_each(
68 listeners.begin(), listeners.end(),
69 [this](InstrumentEditorListener* listener) {
70 listener->OnInstrumentEditorQuit(this);
71 }
72 );
73 // done
74 StopThread();
75 return iResult;
76 }
77
78 EngineChannel* InstrumentEditor::GetEngineChannel() {
79 return pEngineChannel;
80 }
81
82 void InstrumentEditor::AddListener(InstrumentEditorListener* pListener) {
83 listeners.insert(pListener);
84 }
85
86 void InstrumentEditor::RemoveListener(InstrumentEditorListener* pListener) {
87 listeners.erase(pListener);
88 }
89
90 void InstrumentEditor::NotifySamplesToBeRemoved(std::set<void*> Samples) {
91 for ( // notify all registered listeners
92 std::set<InstrumentEditorListener*>::iterator iter = listeners.begin();
93 iter != listeners.end(); iter++
94 ) (*iter)->OnSamplesToBeRemoved(Samples, this);
95 }
96
97 void InstrumentEditor::NotifySamplesRemoved() {
98 for ( // notify all registered listeners
99 std::set<InstrumentEditorListener*>::iterator iter = listeners.begin();
100 iter != listeners.end(); iter++
101 ) (*iter)->OnSamplesRemoved(this);
102 }
103
104 void InstrumentEditor::NotifyDataStructureToBeChanged(void* pStruct, String sStructType) {
105 for ( // notify all registered listeners
106 std::set<InstrumentEditorListener*>::iterator iter = listeners.begin();
107 iter != listeners.end(); iter++
108 ) (*iter)->OnDataStructureToBeChanged(pStruct, sStructType, this);
109 }
110
111 void InstrumentEditor::NotifyDataStructureChanged(void* pStruct, String sStructType) {
112 for ( // notify all registered listeners
113 std::set<InstrumentEditorListener*>::iterator iter = listeners.begin();
114 iter != listeners.end(); iter++
115 ) (*iter)->OnDataStructureChanged(pStruct, sStructType, this);
116 }
117
118 void InstrumentEditor::NotifySampleReferenceChanged(void* pOldSample, void* pNewSample) {
119 for ( // notify all registered listeners
120 std::set<InstrumentEditorListener*>::iterator iter = listeners.begin();
121 iter != listeners.end(); iter++
122 ) (*iter)->OnSampleReferenceChanged(pOldSample, pNewSample, this);
123 }
124
125 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC