/usr/include/corelinux/ThreadContext.hpp is in libcorelinux-dev 0.4.32-7.4ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | #if !defined(__THREADCONTEXT_HPP)
#define __THREADCONTEXT_HPP
/*
CoreLinux++
Copyright (C) 1999,2000 CoreLinux Consortium
The CoreLinux++ Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The CoreLinux++ Library Library is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#if !defined(__COMMON_HPP)
#include <Common.hpp>
#endif
#if !defined(__THREADEXCEPTION_HPP)
#include <ThreadException.hpp>
#endif
namespace corelinux
{
/// Thread state enumeration
enum ThreadState
{
/// The thread is waiting to be started
THREAD_WAITING_TO_START = 0,
/// The thread is in the process of starting
THREAD_STARTING,
/// The thread is running
THREAD_RUNNING,
/// Thread completed without exception
THREAD_NORMAL_EXIT,
/// Thread never started with exception
THREAD_START_EXCEPTION,
/// Thread has died with exception
THREAD_EXCEPTION,
/// Thread never started
THREAD_START_FAILED
};
DECLARE_CLASS( ThreadContext );
/**
Callers function entry point
@param ThreadContext object instance pointer
@return int return code
*/
typedef int (*CallerFunctionPtr)(ThreadContextPtr);
/**
Thread frame entry point function handler
@param ThreadContext pointer to managed ThreadContext
@return Int return code from caller thread
*/
typedef Int (*ThreadFrameFunctionPtr)( ThreadContextPtr );
/**
Managed ThreadContext creation function. This is declared so that callers
may change the allocation routine (to map somewhere or instantiate a
derived ThreadContext for example ). The default handler uses the global
new operator.
@param ThreadContext reference to the callers inital ThreadContext
@return ThreadContext pointer to managed ThreadContext
*/
typedef ThreadContextPtr (*ThreadContextCreatePtr)( ThreadContextRef );
/**
Managed ThreadContext deallocate function. This is declared so that
callers may change the deallocation of the managed ThreadContext.
You would normally do this if you have substituted the
ThreadContextCreatePtr as well.
@param ThreadContext pointer to managed ThreadContext.
@return nothing
*/
typedef void (*ThreadContextDestroyPtr)( ThreadContextPtr );
/**
Managed ThreadContext stack creation function. This is declared so that
callers may change the allocation for the threads stack.
The default handler uses the global new operator.
@param ThreadContext pointer to managed ThreadContext
@return Byte pointer to bottom of stack.
*/
typedef BytePtr (*ThreadStackCreatePtr)( ThreadContextPtr );
/**
Managed ThreadContext stack deallocate function. This is declared so
that callers may change the deallocation of the threads stack. You would
normally do this if you have substituted the ThreadStackCreatePtr
as well.
@param Byte pointer as contained by ThreadContext.
@return nothing
*/
typedef void (*ThreadStackDestroyPtr)( BytePtr );
/**
ThreadContext describes the context in which the thread
operates. Included are stack resource, shared address space
flags, factory methods, and state indicators.
*/
class ThreadContext : public Synchronized
{
public:
//
// Constructors and destructor
//
/**
Default constructor only requires a caller entry
point function. Defaults in effect are 8k stack
which is allocated by the system, and all resources
of the caller are shared by the new thread.
@param CallerFunction pointer to the callers thread
routine.
@exception Assertion if pointer is null
*/
ThreadContext( CallerFunctionPtr )
throw ( Assertion );
/**
Constructor which allows the caller to define the
stack. All resources of the caller are shared by
the new thread.
@param CallerFunction pointer to the callers thread
routine.
@param Size Request size for stack in number of
bytes.
@exception Assertion if routine pointer is null or
callers stack size is negative.
*/
ThreadContext( CallerFunctionPtr, Size )
throw ( Assertion );
/**
Copy constructor takes information from the
context argument.
@param ThreadContext reference to existing context
@exception ThreadNotWaitingException if the
argument context is not in a THREAD_WAITING_TO_START
state.
*/
ThreadContext( ThreadContextCref )
// throw ( ThreadNotWaitingException, Assertion );
throw ( Assertion );
/// Virtual destructor
virtual ~ThreadContext( void );
//
// Operator overloads
//
/**
Assignment operator changes the context
@param ThreadContext reference to existing context
@return ThreadContext reference
@exception ThreadNotWaitingException if the
argument context is not in a THREAD_WAITING_TO_START
state.
*/
ThreadContextRef operator=( ThreadContextCref )
throw( Assertion );
/**
Equality operator compares contexts
@param ThreadContext reference to existing context
@return bool true if same
*/
bool operator==( ThreadContextCref ) const;
/**
Equality matches the thread identifiers
@param ThreadIdentifier reference to identifier
@return bool true if same
*/
bool operator==( ThreadIdentifierCref ) const;
/**
Equality operator matches the callers function
@param CallerFunctionPtr a function reference
@return bool true if same.
*/
bool operator==( CallerFunctionPtr ) const;
/**
Coerces ThreadContext to ThreadIdentifier
@return ThreadIdentifier reference
*/
operator ThreadIdentifierCref( void ) const;
//
// Accessors
//
/**
Get the state of the thread as reflected in
its context
@return ThreadState
*/
const ThreadState & getState( void ) const;
/**
Get the size of the stack as defined by
the context constructor
@return Size in bytes
*/
Size getStackSize( void ) const;
/**
Get the share mask for the thread which
determines VM, FILES, FILESYSTEM, SIGNAL
shares.
@return Int
*/
Int getShareMask( void ) const;
/**
Return the code returned by the callers
function. This is only valid if the
thread ended normally
@return Int return code
@see ThreadState
*/
Int getReturnCode( void ) const;
/**
Get the identifier for the thread. This
is only valid once a thread is started
@return ThreadIdentifier the id
*/
ThreadIdentifierCref getIdentifier( void ) const;
/**
Get the thread frame function pointer
@return ThreadFrameFunctionPtr pointer to instance
or default thread frame
*/
virtual ThreadFrameFunctionPtr getFramePointer( void );
/// Get the stack pointer
BytePtr getStack( void );
/// Get the top of stack pointer
BytePtr *getStackTop( void );
//
// Mutators
//
/**
Change the sharing mask for the thread. This is
only effective when set prior to starting the
thread.
@param Int mask of values for thread resource sharing
and signal disposition
*/
void setShareMask( Int );
/**
Allows the caller to substitute the thread frame
entry point.
@param ThreadFrameFunctionPtr points to the new frame
function that is called when starting a thread.
If this argument is NULLPTR the default handler
is set.
*/
void setFrameFunction( ThreadFrameFunctionPtr );
/**
Allows the caller to substitute the routines which create
and destroy the managed ThreadContext object. The
call to create the object comes in at the startThread
prior to stack allocation, the call to destroy the object
comes from startThread exception and error handling, or
when requested by the caller.
@param ThreadContextCreatePtr the function pointer to
set, If this argument is NULLPTR the default
handlers are set for create and destroy.
@param ThreadContextDestroyPtr to the function pointer to set.
If this argument is NULLPTR the default handlers are set
for create and destroy.
*/
void setContextFunctions
(
ThreadContextCreatePtr ,
ThreadContextDestroyPtr
);
/**
Allows the caller to substitute the routines which create
and destroy the managed ThreadContext stack object. The
call to create the stack object comes in at the startThread
prior to threading, the call to destroy the object
comes from startThread exception and error handling, or
when the destruction of the ThreadContext is imanent.
@param ThreadStackCreatePtr pointer to set. If this
argument is NULLPTR the default handlers are set for create
and destroy.
@param ThreadStackDestroyPtr the function pointer to set.
If this argument is NULLPTR the default handlers are set
for create and destroy.
*/
void setStackFunctions
(
ThreadStackCreatePtr ,
ThreadStackDestroyPtr
);
/**
Set the return code for the thread
@param Int return code value
*/
void setReturnCode( Int );
/**
Set the state for the thread
@param ThreadState the threads new state
*/
void setThreadState( ThreadState );
/**
The definitive thread frame entry point. This is the
address that "clone" gets.
@param ThreadContext pointer to a thread context
@return Int return code
*/
static Int cloneFrameFunction( ThreadContextPtr );
//
// Factory invocations
//
/**
Create a instance of ourself, we also invoke
the create stack method so the instance is
ready to be used to run a thread.
@return ThreadContext pointer to object.
@exception ThreadAllocationException either
for Stack or Context
*/
ThreadContextPtr createContext( void )
throw ( ThreadException );
/**
Destroys the context instance. A check is made
to insure it is not a suicide.
@param ThreadContext pointer to context to destroy
@exception Assertion if self referenced
*/
void destroyContext( ThreadContextPtr ) throw ( Assertion );
protected:
//
// Constructors
//
/// Default constructor throws NEVER_GET_HERE
ThreadContext( void ) throw ( Assertion );
//
// Operator overloads
//
/**
Assignment operator for designating thread
identity
@param ThreadIdentifier as retrieved from the
OS
@return ThreadContext reference to self
*/
ThreadContextRef operator=( ThreadIdentifier );
//
// Accessors
//
/**
Return the function pointer of the callers thread
routine.
@return CallerFunctionPtr
*/
CallerFunctionPtr getCallerFunction( void );
private:
//
// Mutators
//
/**
The default thread frame entry point. This is the
address that the immutableFrameFunction gets and calls
either the defaultFrameFunction or user specified
entry point.
@param ThreadContext pointer to a thread context
@return Int return code
*/
static Int defaultFrameFunction( ThreadContextPtr );
//
// Factory methods
//
/**
The default allocation routine for the managers ThreadContext.
The copy constructor is called with the argument reference
@param ThreadContext reference to the context supplied in the
startThread method.
@return The newly allocated managed context
*/
static ThreadContextPtr defaultContextCreate( ThreadContextRef );
/**
The default destroyer of managed ThreadContexts.
@param ThreadContext pointer to managed object.
*/
static void defaultContextDestroy( ThreadContextPtr );
/**
The default allocation routine for the threads stack.
@param ThreadContext pointer to the managed context.
@return Byte pointer to bottom of stack.
*/
static BytePtr defaultStackCreate( ThreadContextPtr );
/**
The default destroyer of managed ThreadContext stacks.
@param ThreadContext pointer to managed object
*/
static void defaultStackDestroy( BytePtr );
private:
/// The default thread frame entry point
static ThreadFrameFunctionPtr theDefaultFrameFunction;
/// The default context create factory method
static ThreadContextCreatePtr theDefaultContextCreator;
/// The default context destroy factory method
static ThreadContextDestroyPtr theDefaultContextDestroyer;
/// The default stack create factory method
static ThreadStackCreatePtr theDefaultStackCreator;
/// The default stack destroy factory method
static ThreadStackDestroyPtr theDefaultStackDestroyer;
/// The assigned thread frame entry point
ThreadFrameFunctionPtr theFrameFunction;
/// The assigned context create factory method
ThreadContextCreatePtr theContextCreator;
/// The assigned context destroy factory method
ThreadContextDestroyPtr theContextDestroyer;
/// The assigned stack create factory method
ThreadStackCreatePtr theStackCreator;
/// The assigned stack destroy factory method
ThreadStackDestroyPtr theStackDestroyer;
/// Non-adjust stack pointer
BytePtr theStack;
/// Stack size in bytes
Size theStackSize;
/// Shared resource flags
Int theShareMask;
/// Unique thread identifier
ThreadIdentifier theThreadIdentifier;
/// Caller thread entry point
CallerFunctionPtr theCallersFunction;
/// State of thread
ThreadState theThreadState;
/// Return code from theCallersFunction
Int theReturnCode;
};
}
#endif // if !defined(__THREADCONTEXT_HPP)
/*
Common rcs information do not modify
$Author: prudhomm $
$Revision: 1.1 $
$Date: 2000/04/23 20:43:13 $
$Locker: $
*/
|