Audacity  3.0.3
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ODManager Class Referencefinal

A singleton that manages currently running Tasks on an arbitrary number of threads. More...

#include <ODManager.h>

Collaboration diagram for ODManager:
[legend]

Classes

class  ODManagerHelperThread
 
class  Pauser
 

Public Member Functions

void DemandTrackUpdate (WaveTrack *track, double seconds)
 changes the tasks associated with this Waveform to process the task from a different point in the track More...
 
void DecrementCurrentThreads ()
 Reduces the count of current threads running. Meant to be called when ODTaskThreads end in their own threads. Thread-safe. More...
 
void AddNewTask (std::unique_ptr< ODTask > &&mtask, bool lockMutex=true)
 Adds a wavetrack, creates a queue member. More...
 
void SignalTaskQueueLoop ()
 Wakes the queue loop up by signalling its condition variable. More...
 
void MakeWaveTrackIndependent (const std::shared_ptr< WaveTrack > &track)
 if it shares a queue/task, creates a NEW queue/task for the track, and removes it from any previously existing tasks. More...
 
bool MakeWaveTrackDependent (const std::shared_ptr< WaveTrack > &dependentTrack, WaveTrack *masterTrack)
 
void ReplaceWaveTrack (Track *oldTrack, const std::shared_ptr< Track > &newTrack)
 replace the wavetrack whose wavecache the gui watches for updates More...
 
void AddTask (ODTask *task)
 Adds a task to the running queue. Thread-safe. More...
 
void RemoveTaskIfInQueue (ODTask *task)
 removes a task from the active task queue More...
 
void FillTipForWaveTrack (const WaveTrack *t, TranslatableString &tip)
 fills in the status bar message for a given track More...
 
float GetOverallPercentComplete ()
 Gets the total percent complete for all tasks combined. More...
 
int GetTotalNumTasks ()
 Get Total Number of Tasks. More...
 

Static Public Member Functions

static ODManagerInstanceFirstTime ()
 Gets the singleton instance. More...
 
static ODManagerInstanceNormal ()
 Gets the singleton instance. More...
 
static void Quit ()
 Kills the ODMananger Thread. More...
 
static void MarkLoadedODFlag ()
 sets a flag that is set if we have loaded some OD blockfiles from PCM. More...
 
static void UnmarkLoadedODFlag ()
 resets a flag that is set if we have loaded some OD blockfiles from PCM. More...
 
static bool HasLoadedODFlag ()
 returns a flag that is set if we have loaded some OD blockfiles from PCM. More...
 
static bool IsInstanceCreated ()
 returns whether or not the singleton instance was created yet More...
 

Static Public Attributes

static ODManager *(* Instance )() = &(ODManager::InstanceFirstTime)
 

Protected Member Functions

 ODManager ()
 
 ~ODManager ()
 
void Init ()
 Launches a thread for the manager and starts accepting Tasks. More...
 
void Start ()
 Start the main loop for the manager. More...
 
void UpdateQueues ()
 Remove references in our array to Tasks that have been completed/Schedule NEW ones. More...
 

Protected Attributes

std::vector< std::unique_ptr< ODWaveTrackTaskQueue > > mQueues
 
ODLock mQueuesMutex
 
std::vector< ODTask * > mTasks
 
ODLock mTasksMutex
 
volatile bool mPause
 
ODLock mPauseLock
 
volatile int mNeedsDraw
 
volatile int mCurrentThreads
 Number of threads currently running. Accessed thru multiple threads. More...
 
ODLock mCurrentThreadsMutex
 
int mMaxThreads
 Maximum number of threads allowed out. More...
 
volatile bool mTerminate
 
ODLock mTerminateMutex
 
volatile bool mTerminated
 
ODLock mTerminatedMutex
 
ODLock mQueueNotEmptyCondLock
 
std::unique_ptr< ODConditionmQueueNotEmptyCond
 

Static Protected Attributes

static std::unique_ptr< ODManagerpMan {}
 

Detailed Description

A singleton that manages currently running Tasks on an arbitrary number of threads.

Definition at line 45 of file ODManager.h.

Constructor & Destructor Documentation

◆ ODManager()

ODManager::ODManager ( )
protected

Definition at line 155 of file ODManager.cpp.

156 {
157  mTerminate = false;
158  mTerminated = false;
159  mPause = gPause;
160 
161  //must set up the queue condition
162  mQueueNotEmptyCond = std::make_unique<ODCondition>(&mQueueNotEmptyCondLock);
163 }

References gPause, mPause, mQueueNotEmptyCond, mQueueNotEmptyCondLock, mTerminate, and mTerminated.

Referenced by InstanceFirstTime().

Here is the caller graph for this function:

◆ ~ODManager()

ODManager::~ODManager ( )
protected

Definition at line 166 of file ODManager.cpp.

167 {
168  mTerminateMutex.Lock();
169  mTerminate = true;
170  mTerminateMutex.Unlock();
171 
172  //This while loop waits for ODTasks to finish and the DELETE removes all tasks from the Queue.
173  //This function is called from the main audacity event thread, so there should not be more requests for pMan
174  mTerminatedMutex.Lock();
175  while (!mTerminated)
176  {
177  mTerminatedMutex.Unlock();
178  wxThread::Sleep(200);
179 
180  //signal the queue not empty condition since the ODMan thread will wait on the queue condition
181  mQueueNotEmptyCondLock.Lock();
182  mQueueNotEmptyCond->Signal();
183  mQueueNotEmptyCondLock.Unlock();
184 
185  mTerminatedMutex.Lock();
186  }
187  mTerminatedMutex.Unlock();
188 
189  //get rid of all the queues. The queues get rid of the tasks, so we don't worry about them.
190  //nothing else should be running on OD related threads at this point, so we don't lock.
191  mQueues.clear();
192 }

References mQueueNotEmptyCond, mQueueNotEmptyCondLock, mQueues, mTerminate, mTerminated, mTerminatedMutex, and mTerminateMutex.

Member Function Documentation

◆ AddNewTask()

void ODManager::AddNewTask ( std::unique_ptr< ODTask > &&  mtask,
bool  lockMutex = true 
)

Adds a wavetrack, creates a queue member.

Adds a NEW task to the queue. Creates a queue if the tracks associated with the task is not in the list

Parameters
taskthe task to add
lockMutexlocks the mutexes if true (default). This function is used within other ODManager calls, which many need to set this to false.

Definition at line 245 of file ODManager.cpp.

246 {
247  auto task = mtask.get();
248  ODWaveTrackTaskQueue* queue = NULL;
249 
250  if(lockMutex)
251  mQueuesMutex.Lock();
252  for(unsigned int i=0;i<mQueues.size();i++)
253  {
254  //search for a task containing the lead track. wavetrack removal is threadsafe and bound to the mQueuesMutex
255  //note that GetWaveTrack is not threadsafe, but we are assuming task is not running on a different thread yet.
256  if(mQueues[i]->ContainsWaveTrack(task->GetWaveTrack(0).get()))
257  queue = mQueues[i].get();
258  }
259 
260  if(queue)
261  {
262  //Add it to the existing queue but keep the lock since this reference can be deleted.
263  queue->AddTask(std::move(mtask));
264  if(lockMutex)
265  mQueuesMutex.Unlock();
266  }
267  else
268  {
269  //Make a NEW one, add it to the local track queue, and to the immediate running task list,
270  //since this task is definitely at the head
271  auto newqueue = std::make_unique<ODWaveTrackTaskQueue>();
272  newqueue->AddTask(std::move(mtask));
273  mQueues.push_back(std::move(newqueue));
274  if(lockMutex)
275  mQueuesMutex.Unlock();
276 
277  AddTask(task);
278  }
279 }

References AddTask(), ODWaveTrackTaskQueue::AddTask(), ODTask::GetWaveTrack(), mQueues, and mQueuesMutex.

Referenced by ODWaveTrackTaskQueue::MakeWaveTrackIndependent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddTask()

void ODManager::AddTask ( ODTask task)

Adds a task to the running queue. Thread-safe.

Adds a task to running queue. Thread-safe.

Definition at line 195 of file ODManager.cpp.

196 {
197  mTasksMutex.Lock();
198  mTasks.push_back(task);
199  mTasksMutex.Unlock();
200  //signal the queue not empty condition.
201  bool paused;
202 
203  mPauseLock.Lock();
204  paused=mPause;
205  mPauseLock.Unlock();
206 
207  //don't signal if we are paused since if we wake up the loop it will start processing other tasks while paused
208  if(!paused)
209  mQueueNotEmptyCond->Signal();
210 }

References mPause, mPauseLock, mQueueNotEmptyCond, mTasks, and mTasksMutex.

Referenced by AddNewTask(), ODTask::DoSome(), and UpdateQueues().

Here is the caller graph for this function:

◆ DecrementCurrentThreads()

void ODManager::DecrementCurrentThreads ( )

Reduces the count of current threads running. Meant to be called when ODTaskThreads end in their own threads. Thread-safe.

Definition at line 334 of file ODManager.cpp.

335 {
336  mCurrentThreadsMutex.Lock();
337  mCurrentThreads--;
338  mCurrentThreadsMutex.Unlock();
339 }

References mCurrentThreads, and mCurrentThreadsMutex.

Referenced by ODTaskThread::Entry().

Here is the caller graph for this function:

◆ DemandTrackUpdate()

void ODManager::DemandTrackUpdate ( WaveTrack track,
double  seconds 
)

changes the tasks associated with this Waveform to process the task from a different point in the track

changes the tasks associated with this Waveform to process the task from a different point in the track

Parameters
trackthe track to update
secondsthe point in the track from which the tasks associated with track should begin processing from.

Definition at line 554 of file ODManager.cpp.

555 {
556  mQueuesMutex.Lock();
557  for(unsigned int i=0;i<mQueues.size();i++)
558  {
559  mQueues[i]->DemandTrackUpdate(track,seconds);
560  }
561  mQueuesMutex.Unlock();
562 }

References mQueues, and mQueuesMutex.

◆ FillTipForWaveTrack()

void ODManager::FillTipForWaveTrack ( const WaveTrack t,
TranslatableString tip 
)

fills in the status bar message for a given track

Definition at line 618 of file ODManager.cpp.

619 {
620  mQueuesMutex.Lock();
621  for(unsigned int i=0;i<mQueues.size();i++)
622  {
623  mQueues[i]->FillTipForWaveTrack(t, tip);
624  }
625  mQueuesMutex.Unlock();
626 }

References mQueues, and mQueuesMutex.

◆ GetOverallPercentComplete()

float ODManager::GetOverallPercentComplete ( )

Gets the total percent complete for all tasks combined.

Definition at line 629 of file ODManager.cpp.

630 {
631  float total=0.0;
632  mQueuesMutex.Lock();
633  for(unsigned int i=0;i<mQueues.size();i++)
634  {
635  total+=mQueues[i]->GetFrontTask()->PercentComplete();
636  }
637  mQueuesMutex.Unlock();
638 
639  //avoid div by zero and be thread smart.
640  int totalTasks = GetTotalNumTasks();
641  return (float) total/(totalTasks>0?totalTasks:1);
642 }

References GetTotalNumTasks(), mQueues, and mQueuesMutex.

Here is the call graph for this function:

◆ GetTotalNumTasks()

int ODManager::GetTotalNumTasks ( )

Get Total Number of Tasks.

Definition at line 645 of file ODManager.cpp.

646 {
647  int ret=0;
648  mQueuesMutex.Lock();
649  for(unsigned int i=0;i<mQueues.size();i++)
650  {
651  ret+=mQueues[i]->GetNumTasks();
652  }
653  mQueuesMutex.Unlock();
654  return ret;
655 }

References mQueues, and mQueuesMutex.

Referenced by GetOverallPercentComplete().

Here is the caller graph for this function:

◆ HasLoadedODFlag()

bool ODManager::HasLoadedODFlag ( )
static

returns a flag that is set if we have loaded some OD blockfiles from PCM.

Definition at line 612 of file ODManager.cpp.

613 {
614  return sHasLoadedOD;
615 }

References sHasLoadedOD.

◆ Init()

void ODManager::Init ( )
protected

Launches a thread for the manager and starts accepting Tasks.

Definition at line 315 of file ODManager.cpp.

316 {
317  mCurrentThreads = 0;
318  mMaxThreads = 5;
319 
320  // wxLogDebug(wxT("Initializing ODManager...Creating manager thread"));
321  // This is a detached thread, so it deletes itself when it finishes
322  // ... except on Mac where we don't use wxThread for reasons unexplained
323  ODManagerHelperThread* startThread = safenew ODManagerHelperThread;
324 
325 // startThread->SetPriority(0);//default of 50.
326  startThread->Create();
327 // wxPrintf("starting thread from init\n");
328  startThread->Run();
329 
330 // wxPrintf("started thread from init\n");
331  //destruction of thread is taken care of by thread library
332 }

References mCurrentThreads, mMaxThreads, and safenew.

◆ InstanceFirstTime()

ODManager * ODManager::InstanceFirstTime ( )
static

Gets the singleton instance.

Definition at line 282 of file ODManager.cpp.

283 {
284  gODInitedMutex.Lock();
285  if(!pMan)
286  {
287  pMan.reset(safenew ODManager());
288  pMan->Init();
289  gManagerCreated = true;
290  }
291  gODInitedMutex.Unlock();
292 
293  //change the accessor function to use the quicker method.
295 
296  return pMan.get();
297 }

References gManagerCreated, gODInitedMutex, Instance, InstanceNormal(), ODManager(), pMan, and safenew.

Here is the call graph for this function:

◆ InstanceNormal()

ODManager * ODManager::InstanceNormal ( )
static

Gets the singleton instance.

Definition at line 300 of file ODManager.cpp.

301 {
302  return pMan.get();
303 }

References pMan.

Referenced by InstanceFirstTime().

Here is the caller graph for this function:

◆ IsInstanceCreated()

bool ODManager::IsInstanceCreated ( )
static

returns whether or not the singleton instance was created yet

Definition at line 305 of file ODManager.cpp.

306 {
307  bool ret;
308  gODInitedMutex.Lock();
309  ret= gManagerCreated;
310  gODInitedMutex.Unlock();
311  return ret;
312 }

References gManagerCreated, and gODInitedMutex.

Referenced by ODManager::Pauser::Pause(), and Quit().

Here is the caller graph for this function:

◆ MakeWaveTrackDependent()

bool ODManager::MakeWaveTrackDependent ( const std::shared_ptr< WaveTrack > &  dependentTrack,
WaveTrack masterTrack 
)

attach the track in question to another, already existing track's queues and tasks. Remove the task/tracks. Returns success if it was possible.. Some ODTask conditions make it impossible until the Tasks finish.

attach the track in question to another, already existing track's queues and tasks. Remove the task/tracks. only works if both tracks exist. Sets needODUpdate flag for the task. This is complicated and will probably need better design in the future.

Returns
returns success. Some ODTask conditions require that the tasks finish before merging. e.g. they have different effects being processed at the same time.

Definition at line 505 of file ODManager.cpp.

509 {
510  //First, check to see if the task lists are mergeable. If so, we can simply add this track to the other task and queue,
511  //then DELETE this one.
512  ODWaveTrackTaskQueue* masterQueue=NULL;
513  ODWaveTrackTaskQueue* dependentQueue=NULL;
514  unsigned int dependentIndex = 0;
515  bool canMerge = false;
516 
517  mQueuesMutex.Lock();
518  for(unsigned int i=0;i<mQueues.size();i++)
519  {
520  if(mQueues[i]->ContainsWaveTrack(masterTrack))
521  {
522  masterQueue = mQueues[i].get();
523  }
524  else if(mQueues[i]->ContainsWaveTrack(dependentTrack.get()))
525  {
526  dependentQueue = mQueues[i].get();
527  dependentIndex = i;
528  }
529 
530  }
531  if(masterQueue&&dependentQueue)
532  canMerge=masterQueue->CanMergeWith(dependentQueue);
533 
534  //otherwise we need to let dependentTrack's queue live on. We'll have to wait till the conflicting tasks are done.
535  if(!canMerge)
536  {
537  mQueuesMutex.Unlock();
538  return false;
539  }
540  //then we add dependentTrack to the masterTrack's queue - this will allow future ODScheduling to affect them together.
541  //this sets the NeedODUpdateFlag since we don't want the head task to finish without haven't dealt with the dependent
542  masterQueue->MergeWaveTrack(dependentTrack);
543 
544  //finally remove the dependent track
545  mQueues.erase(mQueues.begin()+dependentIndex);
546  mQueuesMutex.Unlock();
547  return true;
548 }

References ODWaveTrackTaskQueue::CanMergeWith(), ODWaveTrackTaskQueue::MergeWaveTrack(), mQueues, and mQueuesMutex.

Here is the call graph for this function:

◆ MakeWaveTrackIndependent()

void ODManager::MakeWaveTrackIndependent ( const std::shared_ptr< WaveTrack > &  track)

if it shares a queue/task, creates a NEW queue/task for the track, and removes it from any previously existing tasks.

Definition at line 481 of file ODManager.cpp.

483 {
484  ODWaveTrackTaskQueue* owner=NULL;
485  mQueuesMutex.Lock();
486  for(unsigned int i=0;i<mQueues.size();i++)
487  {
488  if(mQueues[i]->ContainsWaveTrack(track.get()))
489  {
490  owner = mQueues[i].get();
491  break;
492  }
493  }
494  if(owner)
495  owner->MakeWaveTrackIndependent(track);
496 
497  mQueuesMutex.Unlock();
498 }

References ODWaveTrackTaskQueue::MakeWaveTrackIndependent(), mQueues, and mQueuesMutex.

Here is the call graph for this function:

◆ MarkLoadedODFlag()

void ODManager::MarkLoadedODFlag ( )
static

sets a flag that is set if we have loaded some OD blockfiles from PCM.

Definition at line 598 of file ODManager.cpp.

599 {
600  sHasLoadedOD = true;
601 }

References sHasLoadedOD.

◆ Quit()

void ODManager::Quit ( )
static

Kills the ODMananger Thread.

Definition at line 460 of file ODManager.cpp.

461 {
462  if(IsInstanceCreated())
463  {
464  pMan.reset();
465  }
466 }

References IsInstanceCreated(), and pMan.

Here is the call graph for this function:

◆ RemoveTaskIfInQueue()

void ODManager::RemoveTaskIfInQueue ( ODTask task)

removes a task from the active task queue

Definition at line 225 of file ODManager.cpp.

226 {
227  mTasksMutex.Lock();
228  //linear search okay for now, (probably only 1-5 tasks exist at a time.)
229  for(unsigned int i=0;i<mTasks.size();i++)
230  {
231  if(mTasks[i]==task)
232  {
233  mTasks.erase(mTasks.begin()+i);
234  break;
235  }
236  }
237  mTasksMutex.Unlock();
238 
239 }

References mTasks, and mTasksMutex.

Referenced by ODWaveTrackTaskQueue::~ODWaveTrackTaskQueue().

Here is the caller graph for this function:

◆ ReplaceWaveTrack()

void ODManager::ReplaceWaveTrack ( Track oldTrack,
const std::shared_ptr< Track > &  newTrack 
)

replace the wavetrack whose wavecache the gui watches for updates

if oldTrack is being watched, replace the wavetrack whose wavecache the gui watches for updates

Definition at line 469 of file ODManager.cpp.

471 {
472  mQueuesMutex.Lock();
473  for(unsigned int i=0;i<mQueues.size();i++)
474  {
475  mQueues[i]->ReplaceWaveTrack( oldTrack, newTrack );
476  }
477  mQueuesMutex.Unlock();
478 }

References mQueues, and mQueuesMutex.

◆ SignalTaskQueueLoop()

void ODManager::SignalTaskQueueLoop ( )

Wakes the queue loop up by signalling its condition variable.

Definition at line 212 of file ODManager.cpp.

213 {
214  bool paused;
215 
216  mPauseLock.Lock();
217  paused=mPause;
218  mPauseLock.Unlock();
219  //don't signal if we are paused
220  if(!paused)
221  mQueueNotEmptyCond->Signal();
222 }

References mPause, mPauseLock, and mQueueNotEmptyCond.

◆ Start()

void ODManager::Start ( )
protected

Start the main loop for the manager.

Main loop for managing threads and tasks.

Definition at line 342 of file ODManager.cpp.

343 {
344  bool tasksInArray;
345  bool paused;
346  int numQueues=0;
347 
348  mNeedsDraw=0;
349 
350  //wxLog calls not threadsafe. are printfs? thread-messy for sure, but safe?
351 // wxPrintf("ODManager thread strating \n");
352  //TODO: Figure out why this has no effect at all.
353  //wxThread::This()->SetPriority(30);
354  mTerminateMutex.Lock();
355  while(!mTerminate)
356  {
357  mTerminateMutex.Unlock();
358 // wxPrintf("ODManager thread running \n");
359 
360  //we should look at our WaveTrack queues to see if we can process a NEW task to the running queue.
361  UpdateQueues();
362 
363  //start some threads if necessary
364 
365  mTasksMutex.Lock();
366  tasksInArray = mTasks.size()>0;
367  mTasksMutex.Unlock();
368 
369  mPauseLock.Lock();
370  paused=mPause;
371  mPauseLock.Unlock();
372 
373  mCurrentThreadsMutex.Lock();
374  // keep adding tasks if there is work to do, up to the limit.
375  while(!paused && tasksInArray && (mCurrentThreads < mMaxThreads))
376  {
377  mCurrentThreads++;
378  mCurrentThreadsMutex.Unlock();
379 
380  mTasksMutex.Lock();
381  //detach a NEW thread.
382  // This is a detached thread, so it deletes itself when it finishes
383  // ... except on Mac where we don't use wxThread for reasons unexplained
384  auto thread = safenew ODTaskThread(mTasks[0]);//task);
385  //thread->SetPriority(10);//default is 50.
386  thread->Create();
387  thread->Run();
388 
389  mTasks.erase(mTasks.begin());
390  tasksInArray = mTasks.size()>0;
391  mTasksMutex.Unlock();
392 
393  mCurrentThreadsMutex.Lock();
394  }
395 
396  mCurrentThreadsMutex.Unlock();
397  //use a condition variable to block here instead of a sleep.
398 
399  // JKC: If there are no tasks ready to run, or we're paused then
400  // we wait for there to be tasks in the queue.
401  {
402  ODLocker locker{ &mQueueNotEmptyCondLock };
403  if( (!tasksInArray) || paused)
404  mQueueNotEmptyCond->Wait();
405  }
406 
407  //if there is some ODTask running, then there will be something in the queue. If so then redraw to show progress
408  mQueuesMutex.Lock();
409  mNeedsDraw += mQueues.size()>0?1:0;
410  numQueues=mQueues.size();
411  mQueuesMutex.Unlock();
412 
413  //redraw the current project only (ODTasks will send a redraw on complete even if the projects are in the background)
414  //we don't want to redraw at a faster rate when we have more queues because
415  //this means the CPU is already taxed. This if statement normalizes the rate
416  if((mNeedsDraw>numQueues) && numQueues)
417  {
418  mNeedsDraw=0;
419  wxCommandEvent event( EVT_ODTASK_UPDATE );
420  wxTheApp->AddPendingEvent(event);
421  }
422  mTerminateMutex.Lock();
423  }
424  mTerminateMutex.Unlock();
425 
426  mTerminatedMutex.Lock();
427  mTerminated=true;
428  mTerminatedMutex.Unlock();
429 
430  //wxLogDebug Not thread safe.
431  //wxPrintf("ODManager thread terminating\n");
432 }

References mCurrentThreads, mCurrentThreadsMutex, mMaxThreads, mNeedsDraw, mPause, mPauseLock, mQueueNotEmptyCond, mQueueNotEmptyCondLock, mQueues, mQueuesMutex, mTasks, mTasksMutex, mTerminate, mTerminated, mTerminatedMutex, mTerminateMutex, safenew, and UpdateQueues().

Referenced by ODManager::ODManagerHelperThread::Entry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnmarkLoadedODFlag()

void ODManager::UnmarkLoadedODFlag ( )
static

resets a flag that is set if we have loaded some OD blockfiles from PCM.

Definition at line 605 of file ODManager.cpp.

606 {
607  sHasLoadedOD = false;
608 }

References sHasLoadedOD.

◆ UpdateQueues()

void ODManager::UpdateQueues ( )
protected

Remove references in our array to Tasks that have been completed/Schedule NEW ones.

remove tasks from ODWaveTrackTaskQueues that have been done. Schedules NEW ones if they exist Also remove queues that have become empty.

Definition at line 566 of file ODManager.cpp.

567 {
568  mQueuesMutex.Lock();
569  for(unsigned int i=0;i<mQueues.size();i++)
570  {
571  if(mQueues[i]->IsFrontTaskComplete())
572  {
573  //this should DELETE and remove the front task instance.
574  mQueues[i]->RemoveFrontTask();
575  //schedule next.
576  if(!mQueues[i]->IsEmpty())
577  {
578  //we need to release the lock on the queue vector before using the task vector's lock or we deadlock
579  //so get a temp.
580  ODWaveTrackTaskQueue* queue = mQueues[i].get();
581 
582  AddTask(queue->GetFrontTask());
583  }
584  }
585 
586  //if the queue is empty DELETE it.
587  if(mQueues[i]->IsEmpty())
588  {
589  mQueues.erase(mQueues.begin()+i);
590  i--;
591  }
592  }
593  mQueuesMutex.Unlock();
594 }

References AddTask(), ODWaveTrackTaskQueue::GetFrontTask(), mQueues, and mQueuesMutex.

Referenced by Start().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ Instance

pfodman ODManager::Instance = &(ODManager::InstanceFirstTime)
static

Gets the singleton instance - this is a function pointer that points to one of the below two instance calls. Note that it is not a member function pointer since it is a static function. the function pointer swapping is valid as long as the initial calls only happen from the main thread.

Definition at line 51 of file ODManager.h.

Referenced by ODTask::DoSome(), ODManager::ODManagerHelperThread::Entry(), ODTaskThread::Entry(), InstanceFirstTime(), ODWaveTrackTaskQueue::MakeWaveTrackIndependent(), and ODWaveTrackTaskQueue::~ODWaveTrackTaskQueue().

◆ mCurrentThreads

volatile int ODManager::mCurrentThreads
protected

Number of threads currently running. Accessed thru multiple threads.

Definition at line 162 of file ODManager.h.

Referenced by DecrementCurrentThreads(), Init(), and Start().

◆ mCurrentThreadsMutex

ODLock ODManager::mCurrentThreadsMutex
protected

Definition at line 164 of file ODManager.h.

Referenced by DecrementCurrentThreads(), and Start().

◆ mMaxThreads

int ODManager::mMaxThreads
protected

Maximum number of threads allowed out.

Definition at line 167 of file ODManager.h.

Referenced by Init(), and Start().

◆ mNeedsDraw

volatile int ODManager::mNeedsDraw
protected

Definition at line 159 of file ODManager.h.

Referenced by Start().

◆ mPause

volatile bool ODManager::mPause
protected

Definition at line 156 of file ODManager.h.

Referenced by AddTask(), ODManager(), SignalTaskQueueLoop(), and Start().

◆ mPauseLock

ODLock ODManager::mPauseLock
protected

Definition at line 157 of file ODManager.h.

Referenced by AddTask(), SignalTaskQueueLoop(), and Start().

◆ mQueueNotEmptyCond

std::unique_ptr<ODCondition> ODManager::mQueueNotEmptyCond
protected

Definition at line 177 of file ODManager.h.

Referenced by AddTask(), ODManager(), SignalTaskQueueLoop(), Start(), and ~ODManager().

◆ mQueueNotEmptyCondLock

ODLock ODManager::mQueueNotEmptyCondLock
protected

Definition at line 176 of file ODManager.h.

Referenced by ODManager(), Start(), and ~ODManager().

◆ mQueues

std::vector<std::unique_ptr<ODWaveTrackTaskQueue> > ODManager::mQueues
protected

◆ mQueuesMutex

ODLock ODManager::mQueuesMutex
protected

◆ mTasks

std::vector<ODTask*> ODManager::mTasks
protected

Definition at line 151 of file ODManager.h.

Referenced by AddTask(), RemoveTaskIfInQueue(), and Start().

◆ mTasksMutex

ODLock ODManager::mTasksMutex
protected

Definition at line 153 of file ODManager.h.

Referenced by AddTask(), RemoveTaskIfInQueue(), and Start().

◆ mTerminate

volatile bool ODManager::mTerminate
protected

Definition at line 169 of file ODManager.h.

Referenced by ODManager(), Start(), and ~ODManager().

◆ mTerminated

volatile bool ODManager::mTerminated
protected

Definition at line 172 of file ODManager.h.

Referenced by ODManager(), Start(), and ~ODManager().

◆ mTerminatedMutex

ODLock ODManager::mTerminatedMutex
protected

Definition at line 173 of file ODManager.h.

Referenced by Start(), and ~ODManager().

◆ mTerminateMutex

ODLock ODManager::mTerminateMutex
protected

Definition at line 170 of file ODManager.h.

Referenced by Start(), and ~ODManager().

◆ pMan

std::unique_ptr< ODManager > ODManager::pMan {}
staticprotected

Definition at line 144 of file ODManager.h.

Referenced by InstanceFirstTime(), InstanceNormal(), ODManager::Pauser::Pause(), and Quit().


The documentation for this class was generated from the following files:
ODManager::ODManager
ODManager()
Definition: ODManager.cpp:155
ODManager::mCurrentThreads
volatile int mCurrentThreads
Number of threads currently running. Accessed thru multiple threads.
Definition: ODManager.h:162
ODManager::mCurrentThreadsMutex
ODLock mCurrentThreadsMutex
Definition: ODManager.h:164
ODManager::mTerminated
volatile bool mTerminated
Definition: ODManager.h:172
ODManager::mTerminatedMutex
ODLock mTerminatedMutex
Definition: ODManager.h:173
ODManager::mNeedsDraw
volatile int mNeedsDraw
Definition: ODManager.h:159
ODManager::mQueues
std::vector< std::unique_ptr< ODWaveTrackTaskQueue > > mQueues
Definition: ODManager.h:147
ODWaveTrackTaskQueue::GetFrontTask
ODTask * GetFrontTask()
Schedules the front task for immediate execution.
Definition: ODWaveTrackTaskQueue.cpp:294
gPause
static bool gPause
Definition: ODManager.cpp:134
ODTaskThread
A thread that executes a part of the task specified by an ODTask.
Definition: ODManager.cpp:81
ODWaveTrackTaskQueue::AddTask
void AddTask(std::unique_ptr< ODTask > &&mtask)
Add a task to the queue.
Definition: ODWaveTrackTaskQueue.cpp:108
ODManager::InstanceNormal
static ODManager * InstanceNormal()
Gets the singleton instance.
Definition: ODManager.cpp:300
ODManager::IsInstanceCreated
static bool IsInstanceCreated()
returns whether or not the singleton instance was created yet
Definition: ODManager.cpp:305
gManagerCreated
static bool gManagerCreated
Definition: ODManager.cpp:133
ODManager::AddTask
void AddTask(ODTask *task)
Adds a task to the running queue. Thread-safe.
Definition: ODManager.cpp:195
ODManager::mTerminateMutex
ODLock mTerminateMutex
Definition: ODManager.h:170
sHasLoadedOD
static bool sHasLoadedOD
a flag that is set if we have loaded some OD blockfiles from PCM.
Definition: ODManager.cpp:136
ODManager::mQueueNotEmptyCondLock
ODLock mQueueNotEmptyCondLock
Definition: ODManager.h:176
ODWaveTrackTaskQueue::MakeWaveTrackIndependent
void MakeWaveTrackIndependent(const std::shared_ptr< WaveTrack > &track)
Definition: ODWaveTrackTaskQueue.cpp:131
ODManager::mTasksMutex
ODLock mTasksMutex
Definition: ODManager.h:153
ODManager::mTasks
std::vector< ODTask * > mTasks
Definition: ODManager.h:151
ODManager::mPauseLock
ODLock mPauseLock
Definition: ODManager.h:157
ODManager::mQueuesMutex
ODLock mQueuesMutex
Definition: ODManager.h:148
ODManager::GetTotalNumTasks
int GetTotalNumTasks()
Get Total Number of Tasks.
Definition: ODManager.cpp:645
ODWaveTrackTaskQueue::CanMergeWith
bool CanMergeWith(ODWaveTrackTaskQueue *otherQueue)
returns whether or not this queue's task list and another's can merge together, as when we make two m...
Definition: ODWaveTrackTaskQueue.cpp:44
ODLocker
Definition: ODTaskThread.h:120
ODManager::mQueueNotEmptyCond
std::unique_ptr< ODCondition > mQueueNotEmptyCond
Definition: ODManager.h:177
ODManager::pMan
static std::unique_ptr< ODManager > pMan
Definition: ODManager.h:144
ODWaveTrackTaskQueue
A class representing a modular task to be used with the On-Demand structures.
Definition: ODWaveTrackTaskQueue.h:33
ODManager::mTerminate
volatile bool mTerminate
Definition: ODManager.h:169
ODWaveTrackTaskQueue::MergeWaveTrack
void MergeWaveTrack(const std::shared_ptr< WaveTrack > &track)
Definition: ODWaveTrackTaskQueue.cpp:67
gODInitedMutex
static ODLock gODInitedMutex
Definition: ODManager.cpp:132
ODManager::mPause
volatile bool mPause
Definition: ODManager.h:156
ODManager::Instance
static ODManager *(* Instance)()
Definition: ODManager.h:51
safenew
#define safenew
Definition: MemoryX.h:10
ODManager::mMaxThreads
int mMaxThreads
Maximum number of threads allowed out.
Definition: ODManager.h:167
ODManager::UpdateQueues
void UpdateQueues()
Remove references in our array to Tasks that have been completed/Schedule NEW ones.
Definition: ODManager.cpp:566