File: JobList.cpp

package info (click to toggle)
gridengine 6.2u5-1squeeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 57,132 kB
  • ctags: 56,142
  • sloc: ansic: 438,030; java: 66,252; sh: 36,376; jsp: 7,757; xml: 5,850; makefile: 5,514; csh: 4,571; cpp: 2,848; perl: 2,401; tcl: 692; lisp: 669; yacc: 668; ruby: 642; lex: 344
file content (235 lines) | stat: -rwxr-xr-x 7,310 bytes parent folder | download | duplicates (3)
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
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 *
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 *
 *  Sun Microsystems Inc., March, 2001
 *
 *
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *   Copyright: 2001 by Sun Microsystems, Inc.
 *
 *   All Rights Reserved.
 *
 ************************************************************************/
/*___INFO__MARK_END__*/

#include <afxtempl.h>
#include <afxmt.h>
#include <winsock2.h>
#include "Job.h"
#include "JobList.h"

/****** C_JobList::C_JobList() ************************************************
*  NAME
*     C_JobList::C_JobList() -- constructor
*
*  SYNOPSIS
*     C_JobList::C_JobList()
*
*  FUNCTION
*     Initializes C_JobList object.
*
*  NOTES
*******************************************************************************/
C_JobList::C_JobList() : m_JobListMutex(FALSE, "ListMutex", NULL)
{
}

/****** C_JobList::AddJobToList() *********************************************
*  NAME
*     C_JobList::AddJobToList() -- adds new job to the global job list
*
*  SYNOPSIS
*     POSITION C_JobList::AddJobToList(C_Job *pJob)
*
*  FUNCTION
*     Adds the new job to the global job list. If the job (identified by
*     job_id, ja_task_id, pe_task_id) already exists in the job list,
*     function fails.
*
*  INPUTS
*     C_Job *pJob - the new job object that is to be added to the list
*
*  RESULT
*     POSITION - the position of the new job object in the job list. NULL if
*                the job already existed in the job list.
*
*  NOTES
*******************************************************************************/
POSITION C_JobList::AddJobToList(C_Job *pJob)
{
   C_Job    *pExistingJob = NULL;
   POSITION Pos = NULL;

   // lock access to job list
   CSingleLock singleLock(&m_JobListMutex);
   singleLock.Lock();

   pExistingJob = FindJobInList(*pJob);
   if(pExistingJob == NULL) {
      Pos = AddTail(pJob);
   }

   // unlock access to job list
   singleLock.Unlock();

   return Pos;
}

/****** C_JobList::RemoveJobFromList() *****************************************
*  NAME
*     C_JobList::RemoveJobFromList() -- removes job from the job list
*
*  SYNOPSIS
*     C_Job *C_JobList::RemoveJobFromList(C_Job &Job)
*
*  FUNCTION
*     Removes a job object from the job list. 
*
*  INPUTS
*     C_Job &pJob - a temporary job object that contains the job_id, ja_task_id
*                   and pe_task_id of the job object that is to be removed from
*                   the list.
*
*  RESULT
*     C_Job* - pointer to the job object that was removed from the list.
*              NULL if the job object was not found in the list.
*
*  NOTES
*******************************************************************************/
C_Job *C_JobList::RemoveJobFromList(C_Job &Job)
{
   POSITION Pos;
   POSITION PosOld;
   C_Job    *pJob = NULL;

   // lock access to job list
   CSingleLock singleLock(&m_JobListMutex);
   singleLock.Lock();

   // get job from job list
   Pos = GetHeadPosition();
   while(Pos != NULL) {
      PosOld = Pos;
      pJob = GetNext(Pos);
      if(pJob != NULL) {
         if(pJob->m_job_id == Job.m_job_id
            && pJob->m_ja_task_id == Job.m_ja_task_id
            && ((pJob->m_pe_task_id==NULL && Job.m_pe_task_id==NULL)
               || strcmp(pJob->m_pe_task_id, Job.m_pe_task_id)==0)
            && (pJob->m_JobStatus == js_Finished 
               || pJob->m_JobStatus == js_Failed
               || pJob->m_JobStatus == js_Deleted)) {
            RemoveAt(PosOld);
            Pos = NULL;
         } else {
            pJob = NULL;
         }
      }
   }

   // unlock access to job list
   singleLock.Unlock();

   return pJob;
}

/****** C_JobList::FindJobInList() ********************************************
*  NAME
*     C_JobList::FindJobInList() -- searches job in job list
*
*  SYNOPSIS
*     C_Job *C_JobList::FindJobInList(C_Job &Job)
*
*  FUNCTION
*     Searches a job object in the list
*
*  INPUTS
*     C_Job &pJob - a temporary job object that contains the job_id, ja_task_id
*                   and pe_task_id of the job object that is to be searched in 
*                   the list.
*
*  RESULT
*     C_Job* - pointer to a copy of the job object that was found in the list.
*              Delete this copy if you finished using it!
*              NULL if the job object was not found in the list.
*
*  NOTES
*    MT-Note: Lock list before calling this function!
*******************************************************************************/
C_Job *C_JobList::FindJobInList(C_Job &Job)
{
   POSITION Pos;
   C_Job    *pJob = NULL;

   // get job from job list that is not already executed
   Pos = GetHeadPosition();
   while(Pos) {
      pJob = GetNext(Pos);
      if(pJob) {
         if(pJob->m_job_id == Job.m_job_id
            && pJob->m_ja_task_id == Job.m_ja_task_id
            && ((pJob->m_pe_task_id==NULL && Job.m_pe_task_id==NULL)
               || strcmp(pJob->m_pe_task_id, Job.m_pe_task_id)==0)) {
            Pos = NULL;
         } else {
            pJob = NULL;
         }
      }
   }
   return pJob;
}

/****** C_JobList::GetFirstJobInReceivedState() ********************************
*  NAME
*     C_JobList::GetFirstJobInReceivedState() -- searches first job in 
*                                                js_Revceived state
*
*  SYNOPSIS
*     C_Job *C_JobList::GetFirstJobInReceivedState(C_Job &Job)
*
*  FUNCTION
*     Searches the first job in js_Received state in the list
*
*  RESULT
*     C_Job* - pointer to the first job object in js_Received state in the list.
*              NULL if no object in js_Received state was found in the list.
*
*  NOTES
*    MT-Note: Lock list before calling this function!
*******************************************************************************/
C_Job* C_JobList::GetFirstJobInReceivedState()
{
   POSITION Pos;
   C_Job    *pJob = NULL;

   Pos = GetHeadPosition();
   while(Pos) {
      pJob = GetNext(Pos);
      if(pJob) {
         if(pJob->m_JobStatus == js_Received) {
            Pos = NULL;
         } else {
            pJob = NULL;
         }
      }
   }
   return pJob;
}