CPN
Computational Process Networks
PthreadAttr.h
Go to the documentation of this file.
1 //=============================================================================
2 // PthreadAttr class
3 //-----------------------------------------------------------------------------
4 // POSIX Pthread class library
5 // Copyright (C) 1997-1999 The University of Texas
6 //
7 // This library is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU Library General Public License as published
9 // by the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // The GNU Public License is available in the file LICENSE, or you
18 // can write to the Free Software Foundation, Inc., 59 Temple Place -
19 // Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
20 // World Wide Web at http://www.fsf.org.
21 //=============================================================================
22 
23 #ifndef PthreadAttr_h
24 #define PthreadAttr_h
25 #pragma once
26 
27 #ifdef EXTERNAL_TEMPLATES
28 # pragma interface
29 #endif
30 
31 #include <cpn/common.h>
33 #ifdef _POSIX_THREADS
34 
37 #include <assert.h>
38 
39 
41  public:
42  PthreadAttr(int systemScope=0);
43  ~PthreadAttr(void);
44 
45  PthreadAttr(const PthreadAttr&); // simple referenceCount version
46 
47  operator pthread_attr_t* (void) { return &attr; }
48  operator const pthread_attr_t* (void) const { return &attr; }
49 
50  // Thread Detach State
51  void CreateDetached(void) { DetachState(PTHREAD_CREATE_DETACHED); }
52  void CreateJoinable(void) { DetachState(PTHREAD_CREATE_JOINABLE); }
53  int Detached(void) { return DetachState() == PTHREAD_CREATE_DETACHED; }
54  int Joinable(void) { return DetachState() == PTHREAD_CREATE_JOINABLE; }
55 
56  #if defined _XOPEN_REALTIME_THREADS
57  #if defined __USE_XOPEN2K
58  // Thread Stack Address and Size
59  void* Stack(void* stackaddr, size_t stacksize);
60  void* Stack(size_t& stackSize);
61  #endif
62  #elif defined _POSIX_THREAD_ATTR_STACKADDR
63  // Thread Stack Address
64  void* StackAddress(void* stackaddr);
65  void* StackAddress(void);
66  #endif
67 
68  #ifdef _POSIX_THREAD_ATTR_STACKSIZE
69  // Thread Stack Size
70  size_t StackSize(size_t stacksize);
71  size_t StackSize(void);
72  #endif
73 
74  #ifdef _POSIX_THREAD_ATTR_PRIORITY_SCHEDULING
75  // Thread Scheduling Inheritance
76  void InheritScheduling(void) { ScheduleInherit(PTHREAD_INHERIT_SCHED); }
77  void ExplicitScheduling(void) { ScheduleInherit(PTHREAD_EXPLICIT_SCHED); }
78  int ScheduleInherited(void) { return ScheduleInherit() == PTHREAD_INHERIT_SCHED; }
79  int ScheduleExplicit(void) { return ScheduleInherit() == PTHREAD_EXPLICIT_SCHED; }
80 
81  // Thread Scheduling Policy
82  // SCHED_FIFO: A thread runs until it blocks (then end of priority line).
83  // SCHED_RR: Time-sliced threads (with fixed priorities).
84  // SCHED_OTHER: Implementation dependent (generally Unix-like)
85  int SchedulePolicy(int policy);
86  int SchedulePolicy(void);
87 
88  // (using PthreadScheduleParam class)
89  void GetScheduleParam(PthreadScheduleParam& sp);
90  void SetScheduleParam(PthreadScheduleParam& sp);
91  #endif
92 
93  // Thread Scheduling Scope
94  void SystemScope(void) { ScheduleScope(PTHREAD_SCOPE_SYSTEM); }
95  void ProcessScope(void) { ScheduleScope(PTHREAD_SCOPE_PROCESS); }
96  int InSystemScope(void) { return ScheduleScope() == PTHREAD_SCOPE_SYSTEM; }
97  int InProcessScope(void) { return ScheduleScope() == PTHREAD_SCOPE_PROCESS; }
98 
99  private:
100  pthread_attr_t attr;
102 
103  // PTHREAD_CREATE_DETACHED, PTHREAD_CREATE_JOINABLE
104  int DetachState(int detState);
105  int DetachState(void);
106 
107  #ifdef _POSIX_THREAD_ATTR_PRIORITY_SCHEDULING
108  // PTHREAD_INHERIT_SCHED, PTHREAD_EXPLICIT_SCHED
109  int ScheduleInherit(int inherit);
110  int ScheduleInherit(void);
111  #endif
112 
113  // PTHREAD_SCOPE_SYSTEM, PTHREAD_SCOPE_PROCESS
114  int ScheduleScope(int scope);
115  int ScheduleScope(void);
116 };
117 
118 
119 #endif
120 #endif
int InProcessScope(void)
Definition: PthreadAttr.h:97
pthread_attr_t attr
Definition: PthreadAttr.h:100
~PthreadAttr(void)
Definition: PthreadAttr.cc:42
void CreateDetached(void)
Definition: PthreadAttr.h:51
int Detached(void)
Definition: PthreadAttr.h:53
void CreateJoinable(void)
Definition: PthreadAttr.h:52
PthreadAttr(int systemScope=0)
Definition: PthreadAttr.cc:32
void SystemScope(void)
Definition: PthreadAttr.h:94
int InSystemScope(void)
Definition: PthreadAttr.h:96
void ProcessScope(void)
Definition: PthreadAttr.h:95
int DetachState(void)
Definition: PthreadAttr.cc:67
int Joinable(void)
Definition: PthreadAttr.h:54
int ScheduleScope(void)
Definition: PthreadAttr.cc:217
int referenceCount
Definition: PthreadAttr.h:101