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

Annotation of /linuxsampler/trunk/src/common/Thread.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1221 - (hide annotations) (download) (as text)
Wed Jun 6 18:50:03 2007 UTC (16 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 3318 byte(s)
* fixed several issues in fundamental "Thread" class: set scheduling
  policy and priority on thread level, set a minimum stack size for
  thread (TODO: a reasonable value yet to be tested), bugfix: non-RT
  threads simply inherited properties of starting thread instead of
  setting their own policy and priority
* updated and fixed test cases (haven't been touched in a while, but
  are now all running successfully through all cases)

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 1212 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 schoenebeck 53 * *
8     * This program is free software; you can redistribute it and/or modify *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #ifndef __THREAD_H__
25     #define __THREAD_H__
26    
27     #include <iostream>
28     #include <stdio.h>
29     #include <stdlib.h>
30     #include <sched.h>
31     #include <sys/mman.h>
32     #include <memory.h>
33     #include <pthread.h>
34     #include <errno.h>
35    
36 schoenebeck 1221 #include "Condition.h"
37    
38 schoenebeck 1212 namespace LinuxSampler {
39    
40 schoenebeck 53 /// Abstract base class for classes that need to run in an own thread.
41     class Thread {
42     public:
43 schoenebeck 392 Thread(bool LockMemory, bool RealTime, int PriorityMax, int PriorityDelta);
44 schoenebeck 53 virtual ~Thread();
45     virtual int StartThread();
46     virtual int StopThread();
47 schoenebeck 57 virtual int SignalStartThread();
48 schoenebeck 53 virtual int SignalStopThread();
49 schoenebeck 1212 virtual bool IsRunning();
50 schoenebeck 53 virtual int SetSchedulingPriority(); //FIXME: should be private
51 schoenebeck 392 virtual int LockMemory(); //FIXME: should be private
52 schoenebeck 53 virtual void EnableDestructor(); //FIXME: should be private
53     virtual int Destructor(); //FIXME: should be private
54     virtual int Main() = 0; ///< This method needs to be implemented by the descendant and is the entry point for the new thread. FIXME: should be protected
55     private:
56 schoenebeck 1221 pthread_attr_t __thread_attr;
57 schoenebeck 53 pthread_t __thread_id;
58     pthread_key_t __thread_destructor_key;
59 schoenebeck 1221 Condition RunningCondition;
60 schoenebeck 53 int PriorityMax;
61     int PriorityDelta;
62     bool isRealTime;
63 schoenebeck 392 bool bLockedMemory;
64 schoenebeck 53 };
65    
66     // Callback functions for the POSIX thread API
67     void* __pthread_launcher(void* thread);
68     void __pthread_destructor(void* thread);
69    
70 schoenebeck 1212 } // namespace LinuxSampler
71    
72 schoenebeck 53 #endif // __THREAD_H__

  ViewVC Help
Powered by ViewVC