xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdCl
XrdClJobManager.hh
Go to the documentation of this file.
1
//------------------------------------------------------------------------------
2
// Copyright (c) 2013 by European Organization for Nuclear Research (CERN)
3
// Author: Lukasz Janyst <ljanyst@cern.ch>
4
//------------------------------------------------------------------------------
5
// XRootD is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU Lesser General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// XRootD is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17
//------------------------------------------------------------------------------
18
19
#ifndef __XRD_CL_JOB_MANAGER_HH__
20
#define __XRD_CL_JOB_MANAGER_HH__
21
22
#include <stdint.h>
23
#include <vector>
24
#include <pthread.h>
25
#include "
XrdCl/XrdClSyncQueue.hh
"
26
27
namespace
XrdCl
28
{
29
//----------------------------------------------------------------------------
31
//----------------------------------------------------------------------------
32
class
Job
33
{
34
public
:
35
//------------------------------------------------------------------------
37
//------------------------------------------------------------------------
38
virtual
~Job
() {};
39
40
//------------------------------------------------------------------------
42
//------------------------------------------------------------------------
43
virtual
void
Run
(
void
*arg ) = 0;
44
};
45
46
//----------------------------------------------------------------------------
48
//----------------------------------------------------------------------------
49
class
JobManager
50
{
51
public
:
52
//------------------------------------------------------------------------
54
//------------------------------------------------------------------------
55
JobManager
( uint32_t workers )
56
{
57
pRunning
=
false
;
58
pWorkers
.resize( workers );
59
}
60
61
//------------------------------------------------------------------------
63
//------------------------------------------------------------------------
64
~JobManager
()
65
{
66
}
67
68
//------------------------------------------------------------------------
70
//------------------------------------------------------------------------
71
bool
Initialize
();
72
73
//------------------------------------------------------------------------
75
//------------------------------------------------------------------------
76
bool
Finalize
();
77
78
//------------------------------------------------------------------------
80
//------------------------------------------------------------------------
81
bool
Start
();
82
83
//------------------------------------------------------------------------
85
//------------------------------------------------------------------------
86
bool
Stop
();
87
88
//------------------------------------------------------------------------
90
//------------------------------------------------------------------------
91
void
QueueJob
(
Job
*job,
void
*arg = 0 )
92
{
93
pJobs
.Put(
JobHelper
( job, arg ) );
94
}
95
96
//------------------------------------------------------------------------
98
//------------------------------------------------------------------------
99
void
RunJobs
();
100
101
private
:
102
//------------------------------------------------------------------------
104
//------------------------------------------------------------------------
105
void
StopWorkers
( uint32_t n );
106
107
struct
JobHelper
108
{
109
JobHelper
(
Job
*j = 0,
void
*a = 0 ):
job
(j),
arg
(a) {}
110
Job
*
job
;
111
void
*
arg
;
112
};
113
114
std::vector<pthread_t>
pWorkers
;
115
SyncQueue<JobHelper>
pJobs
;
116
XrdSysMutex
pMutex
;
117
bool
pRunning
;
118
};
119
}
120
121
#endif // __XRD_CL_ANY_OBJECT_HH__
Generated by
1.8.3.1