CoreLinux++  0.4.32
Thread.hpp
1 #if !defined(__THREAD_HPP)
2 #define __THREAD_HPP
3 
4 /*
5  CoreLinux++
6  Copyright (C) 1999,2000 CoreLinux Consortium
7 
8  The CoreLinux++ Library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12 
13  The CoreLinux++ Library Library is distributed in the hope that it will
14  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public
19  License along with the GNU C Library; see the file COPYING.LIB. If not,
20  write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA 02111-1307, USA.
22 */
23 
24 #if !defined IN_COMMON_HPP
25  #error Thread.hpp is included by Common.hpp only.
26 #endif
27 
28 #if !defined(__SINGLETON_HPP)
29 #include <Singleton.hpp>
30 #endif
31 
32 #if !defined(__MAP_HPP)
33 #include <Map.hpp>
34 #endif
35 
36 #if !defined(__INVALIDTHREADEXCEPTION_HPP)
37 #include <InvalidThreadException.hpp>
38 #endif
39 
40 namespace corelinux
41 {
42  DECLARE_CLASS( ThreadContext );
43 
44  CORELINUX_MAP
45  (
47  ThreadContextPtr,
48  std::less<ThreadIdentifier>,
49  ThreadMap
50  );
51 
52  //
53  // Start of class declaration
54  //
55 
56  DECLARE_CLASS( Thread );
57  DECLARE_TYPE( Singleton<Thread>, ThreadManager );
58 
73  class Thread : public Synchronized
74  {
75  public:
76 
77  //
78  // Constructors and destructor
79  //
80 
82 
83  Thread( void ) throw( Assertion );
84 
86 
87  virtual ~Thread( void );
88 
89  //
90  // Operator overloads
91  //
92 
93  //
94  // Accessors (class)
95  //
96 
103  static Int getKernelError( void );
104 
111  static ThreadIdentifier getThreadIdentifier( void );
112 
119  static ThreadIdentifier getParentThreadIdentifier( void );
120 
127  static ThreadIdentifierCref getThreadManagerIdentifier( void );
128 
137  static ThreadContextCref getThreadContext( ThreadIdentifierCref )
138  throw ( InvalidThreadException ) ;
139 
140 
146  static Count getCreatedThreadCount( void );
147 
153  static Count getActiveThreadCount( void );
154 
160  static Count getBlockedThreadCount( void );
161 
168  static Count getCompletedThreadCount( void );
169 
171 
172  static void dump( void );
173 
174  //
175  // Mutators
176  //
177 
187  static ThreadIdentifier startThread( ThreadContextRef ) ;
188 
199  static Int waitForThread( ThreadIdentifierCref )
200  throw ( InvalidThreadException );
201 
211  static void destroyThreadContext( ThreadIdentifierCref )
213 
223  static Int getThreadPriority( ThreadIdentifierCref )
225 
236  static void setThreadPriority( ThreadIdentifierCref, Int )
238 
239  protected:
240 
241  //
242  // Constructor
243  //
250  Thread( ThreadCref ) throw ( Assertion );
251 
252  //
253  // Operator overloads
254  //
255 
265 
273  bool operator==( ThreadCref ) const throw ( Assertion ) ;
274 
275  //
276  // Thread terminate
277  //
278 
279  static void threadTerminated( Int, VoidPtr, VoidPtr );
280 
281  protected:
282 
284 
286 
287  private:
288 
290 
291  static ThreadMap theThreadMap;
292 
293  static ThreadIdentifier theThreadManagerId;
294  static Count theThreadCount;
295  };
296 
297 }
298 
299 #endif // if !defined(__THREAD_HPP)
300 
301 /*
302  Common rcs information do not modify
303  $Author: dulimart $
304  $Revision: 1.5 $
305  $Date: 2001/03/20 04:06:50 $
306  $Locker: $
307 */
308 
static ThreadIdentifier startThread(ThreadContextRef)
Start a thread as described by the context.
Definition: Thread.cpp:302
virtual ~Thread(void)
Virtual destructor.
Definition: Thread.cpp:101
static ThreadContextCref getThreadContext(ThreadIdentifierCref)
Retrieve a ThreadContext given a identifier.
Definition: Thread.cpp:152
static ThreadIdentifierCref getThreadManagerIdentifier(void)
getThreadManagerIdentifier retrieves the thread that Thread was instantiated from ...
Definition: Thread.cpp:145
static Count getCompletedThreadCount(void)
Retrieve the number of threads that are not starting or running or waiting to run.
Definition: Thread.cpp:215
static Count getCreatedThreadCount(void)
Retrieve the number of created threads.
Definition: Thread.cpp:171
static ThreadManager theThreadManager
The singleton instance of Thread for synchronization.
Definition: Thread.hpp:285
ThreadContext describes the context in which the thread operates.
Definition: ThreadContext.hpp:137
static void dump(void)
Debugging method for the moment.
Definition: Thread.cpp:283
static Int waitForThread(ThreadIdentifierCref)
Blocks the caller until the thread has ended execution, retrieving the return code from the associate...
Definition: Thread.cpp:375
InvalidThreadException describes an exception that is thrown when a operation is attempted on a non-m...
Definition: InvalidThreadException.hpp:43
ThreadRef operator=(ThreadCref)
Assignment operator won&#39;t do, we should never get here anyway but the compiler will generate the miss...
Definition: Thread.cpp:108
Ensure a class only has one instance, and provide a global point of access to it. ...
Definition: Singleton.hpp:38
static Count getBlockedThreadCount(void)
Retrieve the number of threads that are waiting ro tun.
Definition: Thread.cpp:249
static ThreadIdentifier getThreadIdentifier(void)
getThreadIdentifier retrieves the kernel process id for the caller thread
Definition: Thread.cpp:131
static Int getKernelError(void)
getKernelError returns the thread instance errno for the last kernel call the thread made ...
Definition: Thread.cpp:124
Thread(void)
Default constructor.
Definition: Thread.cpp:58
static void setThreadPriority(ThreadIdentifierCref, Int)
Set thread priority for the given indentifier.
Definition: Thread.cpp:438
static ThreadIdentifier getParentThreadIdentifier(void)
getParentThreadIdentifier retrieves the parent thread of the current thread.
Definition: Thread.cpp:138
ScalarIdentifier provides a templated interface for declaring CoreLinux Identifiers for simple scalar...
Definition: ScalarIdentifiers.hpp:37
bool operator==(ThreadCref) const
Equality operator not valid for class utility.
Definition: Thread.cpp:116
static Count getActiveThreadCount(void)
Retrieve the number of threads that are starting or running.
Definition: Thread.cpp:178
Assertion is-a Exception created when an assertion fails.
Definition: Assertion.hpp:423
Synchronized is a mixin which allows class objects to enable monitor functionality.
Definition: Synchronized.hpp:41
static Int getThreadPriority(ThreadIdentifierCref)
Get thread priority for the given indentifier.
Definition: Thread.cpp:429
static void destroyThreadContext(ThreadIdentifierCref)
Destroys the managed context for the given identifier.
Definition: Thread.cpp:387
Thread is a framework for the creation, management, and destruction of caller threads.
Definition: Thread.hpp:73

This is the CoreLinux++ reference manual
Provided by The CoreLinux Consortium