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
|
// IBM_PROLOG_BEGIN_TAG
// This is an automatically generated prolog.
//
// $Source: src/usr/initservice/taskargs/taskargs.C $
//
// IBM CONFIDENTIAL
//
// COPYRIGHT International Business Machines Corp. 2011
//
// p1
//
// Object Code Only (OCO) source materials
// Licensed Internal Code Source Materials
// IBM HostBoot Licensed Internal Code
//
// The source code for this program is not published or other-
// wise divested of its trade secrets, irrespective of what has
// been deposited with the U.S. Copyright Office.
//
// Origin: 30
//
// IBM_PROLOG_END
/**
* @file taskargs.C
*
* common file to hold arguments passed onto tasks.
* will also hold macros, etc to manage arguments
*
* @note Notes on barrier:
* barrier_init() will initialize the barrier to the number of threads to
* wait on.
* "barrier_wait() function shall synchronize participating threads at
* the barrier referenced by barrier.
* The calling thread shall block until the required number of threads
* have called pthread_barrier_wait specifying the barrier."
*
* So in this case, the barrier is initialized to 2 (through barrier_init()
* in the constructor).
* When InitSvc launches the child, it calls barrier wait() (through
* waitChildSync() ) which adds 1 task to the "waitlist", blocks, and
* returns to InitSvc. InitSvc then calls waitParentSync() which adds
* its' task to the "waitlist". When the second task is added, both task
* are unblocked.
*
* The barrier is destroyed when TaskArgs goes out of scope by calling
* barrier_destroy() in the destructor.
*
*/
#include <initservice/taskargs.H>
namespace INITSERVICE
{
extern trace_desc_t *g_trac_initsvc;
void TaskArgs::waitParentSync( )
{
barrier_wait( &iv_sync_barrier);
}
void TaskArgs::waitChildSync( )
{
barrier_wait( &iv_sync_barrier);
}
void TaskArgs::postReturnCode( const uint64_t i_returncode )
{
iv_taskreturncode = i_returncode;
return;
}
uint64_t TaskArgs::getReturnCode( ) const
{
return iv_taskreturncode;
}
void TaskArgs::setCommand( const uint64_t i_command )
{
iv_taskcommand = i_command;
return;
}
uint64_t TaskArgs::getCommand( ) const
{
return iv_taskcommand;
}
void TaskArgs::postErrorLog( errlHndl_t i_errl )
{
iv_errl = i_errl;
}
errlHndl_t TaskArgs::getErrorLog( )
{
errlHndl_t l_errl = iv_errl;
// null out iv_errl after returning it to someone.
iv_errl = NULL;
return l_errl;
}
void TaskArgs::clear()
{
iv_taskreturncode = TASKARGS_UNDEFINED64; // init iv_returncode to undefined
iv_taskcommand = TASKARGS_UNDEFINED64; // init iv_command to undefined
// this should not happen, should have been handled by the caller(s)
// commit the errorlog here just to get rid of it
if ( iv_errl )
{
TRACFCOMP( g_trac_initsvc,
ERR_MRK "ERROR: errorlog %p was left in TaskArgs",
iv_errl );
errlCommit(iv_errl);
}
}
TaskArgs::TaskArgs()
: iv_errl( NULL ), // init errorlog handle to NULL
iv_taskreturncode(TASKARGS_UNDEFINED64), // init iv_returncode to undefined
iv_taskcommand(TASKARGS_UNDEFINED64) // init iv_command to undefined
{
// set barrier to wait for 2 tasks before releasing,
// see notes above.
barrier_init( &iv_sync_barrier, 2 );
}
TaskArgs::~TaskArgs()
{
clear();
barrier_destroy( &iv_sync_barrier );
// add an assert here to check if there is still an errorlog pending?
}
}; // namespace
|