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

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

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

revision 63 by schoenebeck, Tue May 4 18:52:24 2004 UTC revision 392 by schoenebeck, Sat Feb 19 02:40:24 2005 UTC
# Line 22  Line 22 
22    
23  #include "Thread.h"  #include "Thread.h"
24    
25  Thread::Thread(bool RealTime, int PriorityMax, int PriorityDelta) {  Thread::Thread(bool LockMemory, bool RealTime, int PriorityMax, int PriorityDelta) {
26        this->bLockedMemory     = LockMemory;
27      this->isRealTime        = RealTime;      this->isRealTime        = RealTime;
28      this->Running           = false;      this->Running           = false;
29      this->PriorityDelta     = PriorityDelta;      this->PriorityDelta     = PriorityDelta;
# Line 98  int Thread::StopThread() { Line 99  int Thread::StopThread() {
99      if (Running) {      if (Running) {
100          SignalStopThread();          SignalStopThread();
101          pthread_cond_wait(&__thread_exit_condition, &__thread_state_mutex);          pthread_cond_wait(&__thread_exit_condition, &__thread_state_mutex);
102            pthread_detach(__thread_id);
103      }      }
104      pthread_mutex_unlock(&__thread_state_mutex);      pthread_mutex_unlock(&__thread_state_mutex);
105      return 0;      return 0;
# Line 123  int Thread::SignalStopThread() { Line 125  int Thread::SignalStopThread() {
125   *  current priority).   *  current priority).
126   */   */
127  int Thread::SetSchedulingPriority() {  int Thread::SetSchedulingPriority() {
128    #if !defined(__APPLE__)
129      struct sched_param schp;      struct sched_param schp;
130    
131      if (!isRealTime) return 0;      if (!isRealTime) return 0;
132    
     if (mlockall(MCL_CURRENT | MCL_FUTURE) < 0) {  
         perror("WARNING, can't mlockall() memory!");  
     }  
   
133      /*      /*
134       * set the process to realtime privs       * set the process to realtime privs
135       */       */
# Line 143  int Thread::SetSchedulingPriority() { Line 142  int Thread::SetSchedulingPriority() {
142      }      }
143    
144      if (sched_setscheduler(0, SCHED_FIFO, &schp) != 0) {      if (sched_setscheduler(0, SCHED_FIFO, &schp) != 0) {
145          perror("sched_setscheduler");          perror("Thread: WARNING, can't assign realtime scheduling to thread!");
146          return -1;          return -1;
147      }      }
148    #endif
149        return 0;
150    }
151    
152    /**
153     * Locks the memory so it will not be swapped out by the operating system.
154     */
155    int Thread::LockMemory() {
156        if (!bLockedMemory) return 0;
157        if (mlockall(MCL_CURRENT | MCL_FUTURE) < 0) {
158            perror("Thread: WARNING, can't mlockall() memory!");
159            return -1;
160        }
161      return 0;      return 0;
162  }  }
163    
# Line 182  void* __pthread_launcher(void* thread) { Line 193  void* __pthread_launcher(void* thread) {
193      Thread* t;      Thread* t;
194      t = (Thread*) thread;      t = (Thread*) thread;
195      t->SetSchedulingPriority();      t->SetSchedulingPriority();
196        t->LockMemory();
197      t->EnableDestructor();      t->EnableDestructor();
198      t->Main();      t->Main();
199  }  }

Legend:
Removed from v.63  
changed lines
  Added in v.392

  ViewVC Help
Powered by ViewVC