xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdCl
XrdClTaskManager.hh
Go to the documentation of this file.
1
//------------------------------------------------------------------------------
2
// Copyright (c) 2011-2012 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_TASK_MANAGER_HH__
20
#define __XRD_CL_TASK_MANAGER_HH__
21
22
#include <ctime>
23
#include <set>
24
#include <list>
25
#include <string>
26
#include <stdint.h>
27
#include <pthread.h>
28
#include "
XrdSys/XrdSysPthread.hh
"
29
30
namespace
XrdCl
31
{
32
//----------------------------------------------------------------------------
34
//----------------------------------------------------------------------------
35
class
Task
36
{
37
public
:
38
virtual
~Task
() {};
39
40
//------------------------------------------------------------------------
46
//------------------------------------------------------------------------
47
virtual
time_t
Run
( time_t now ) = 0;
48
49
//------------------------------------------------------------------------
51
//------------------------------------------------------------------------
52
const
std::string &
GetName
()
const
53
{
54
return
pName
;
55
}
56
57
//------------------------------------------------------------------------
59
//------------------------------------------------------------------------
60
void
SetName
(
const
std::string &name )
61
{
62
pName
= name;
63
}
64
65
private
:
66
std::string
pName
;
67
};
68
69
//----------------------------------------------------------------------------
74
//----------------------------------------------------------------------------
75
class
TaskManager
76
{
77
public
:
78
//------------------------------------------------------------------------
80
//------------------------------------------------------------------------
81
TaskManager
();
82
83
//------------------------------------------------------------------------
85
//------------------------------------------------------------------------
86
~TaskManager
();
87
88
//------------------------------------------------------------------------
90
//------------------------------------------------------------------------
91
bool
Start
();
92
93
//------------------------------------------------------------------------
97
//------------------------------------------------------------------------
98
bool
Stop
();
99
100
//------------------------------------------------------------------------
106
//------------------------------------------------------------------------
107
void
RegisterTask
(
Task
*task, time_t time );
108
109
//------------------------------------------------------------------------
113
//------------------------------------------------------------------------
114
void
UnregisterTask
(
Task
*task );
115
116
//------------------------------------------------------------------------
118
//------------------------------------------------------------------------
119
void
RunTasks
();
120
121
private
:
122
123
//------------------------------------------------------------------------
124
// Task set helpers
125
//------------------------------------------------------------------------
126
struct
TaskHelper
127
{
128
TaskHelper
(
Task
*tsk, time_t tme ): task(tsk),
execTime
(tme) {}
129
Task
*
task
;
130
time_t
execTime
;
131
};
132
133
struct
TaskHelperCmp
134
{
135
bool
operator ()
(
const
TaskHelper
&th1,
const
TaskHelper
&th2 )
const
136
{
137
return
th1.
execTime
< th2.
execTime
;
138
}
139
};
140
141
typedef
std::multiset<TaskHelper, TaskHelperCmp>
TaskSet
;
142
typedef
std::list<Task*>
TaskList
;
143
144
//------------------------------------------------------------------------
145
// Private variables
146
//------------------------------------------------------------------------
147
uint16_t
pResolution
;
148
TaskSet
pTasks
;
149
TaskList
pToBeUnregistered
;
150
pthread_t
pRunnerThread
;
151
bool
pRunning
;
152
XrdSysMutex
pMutex
;
153
XrdSysMutex
pOpMutex
;
154
};
155
}
156
157
#endif // __XRD_CL_TASK_MANAGER_HH__
Generated by
1.8.3.1