/[svn]/linuxsampler/trunk/src/common/WorkerThread.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/common/WorkerThread.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2426 by persson, Sun May 3 12:15:40 2009 UTC revision 2427 by persson, Sat Mar 2 07:03:04 2013 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2   *                                                                         *   *                                                                         *
3   *   Copyright (C) 2007 Christian Schoenebeck, Grigor Iliev                *   *   Copyright (C) 2007 - 2013 Christian Schoenebeck, Grigor Iliev         *
4   *                                                                         *   *                                                                         *
5   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 27  namespace LinuxSampler { Line 27  namespace LinuxSampler {
27      WorkerThread::WorkerThread() : Thread(true, false, 0, -4) { }      WorkerThread::WorkerThread() : Thread(true, false, 0, -4) { }
28    
29      void WorkerThread::Execute(Runnable* pJob) {      void WorkerThread::Execute(Runnable* pJob) {
30          mutex.Lock();          {
31          queue.push_back(pJob);              LockGuard lock(mutex);
32          mutex.Unlock();              queue.push_back(pJob);
33            }
34          StartThread(); // ensure thread is running          StartThread(); // ensure thread is running
35          conditionJobsLeft.Set(true); // wake up thread          conditionJobsLeft.Set(true); // wake up thread
36      }      }
# Line 39  namespace LinuxSampler { Line 39  namespace LinuxSampler {
39      int WorkerThread::Main() {      int WorkerThread::Main() {
40          while (true) {          while (true) {
41    
42          #if CONFIG_PTHREAD_TESTCANCEL              #if CONFIG_PTHREAD_TESTCANCEL
43                          TestCancel();              TestCancel();
44          #endif              #endif
45              while (!queue.empty()) {              while (true) {
46                  Runnable* pJob;                  Runnable* pJob;
47    
48                  // grab a new job from the queue                  // grab a new job from the queue
49                  mutex.Lock();                  {
50                  pJob = queue.front();                      LockGuard lock(mutex);
51                  mutex.Unlock();                      if (queue.empty()) break;
52    
53                        pJob = queue.front();
54                        queue.pop_front();
55                    }
56    
57                  try {                  try {
58                      pJob->Run();                      pJob->Run();
# Line 59  namespace LinuxSampler { Line 63  namespace LinuxSampler {
63                      std::cerr << std::endl << std::flush;                      std::cerr << std::endl << std::flush;
64                  }                  }
65    
                 // remove processed job from the queue  
                 mutex.Lock();  
                 queue.pop_front();  
                 mutex.Unlock();  
   
66                  delete pJob;                  delete pJob;
67              }              }
68    

Legend:
Removed from v.2426  
changed lines
  Added in v.2427

  ViewVC Help
Powered by ViewVC