]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/cpp/src/thrift/concurrency/TimerManager.h
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 #ifndef _THRIFT_CONCURRENCY_TIMERMANAGER_H_
21 #define _THRIFT_CONCURRENCY_TIMERMANAGER_H_ 1
23 #include <thrift/concurrency/Monitor.h>
24 #include <thrift/concurrency/ThreadFactory.h>
31 namespace concurrency
{
36 * This class dispatches timer tasks when they fall due.
44 typedef std::weak_ptr
<Task
> Timer
;
48 virtual ~TimerManager();
50 virtual std::shared_ptr
<const ThreadFactory
> threadFactory() const;
52 virtual void threadFactory(std::shared_ptr
<const ThreadFactory
> value
);
55 * Starts the timer manager service
57 * @throws IllegalArgumentException Missing thread factory attribute
62 * Stops the timer manager service
66 virtual size_t taskCount() const;
69 * Adds a task to be executed at some time in the future by a worker thread.
71 * @param task The task to execute
72 * @param timeout Time in milliseconds to delay before executing task
73 * @return Handle of the timer, which can be used to remove the timer.
75 virtual Timer
add(std::shared_ptr
<Runnable
> task
, const std::chrono::milliseconds
&timeout
);
76 Timer
add(std::shared_ptr
<Runnable
> task
, uint64_t timeout
) { return add(task
,std::chrono::milliseconds(timeout
)); }
79 * Adds a task to be executed at some time in the future by a worker thread.
81 * @param task The task to execute
82 * @param abstime Absolute time in the future to execute task.
83 * @return Handle of the timer, which can be used to remove the timer.
85 virtual Timer
add(std::shared_ptr
<Runnable
> task
, const std::chrono::time_point
<std::chrono::steady_clock
>& abstime
);
88 * Removes a pending task
90 * @param task The task to remove. All timers which execute this task will
92 * @throws NoSuchTaskException Specified task doesn't exist. It was either
93 * processed already or this call was made for a
94 * task that was never added to this timer
96 * @throws UncancellableTaskException Specified task is already being
97 * executed or has completed execution.
99 virtual void remove(std::shared_ptr
<Runnable
> task
);
102 * Removes a single pending task
104 * @param timer The timer to remove. The timer is returned when calling the
106 * @throws NoSuchTaskException Specified task doesn't exist. It was either
107 * processed already or this call was made for a
108 * task that was never added to this timer
110 * @throws UncancellableTaskException Specified task is already being
111 * executed or has completed execution.
113 virtual void remove(Timer timer
);
115 enum STATE
{ UNINITIALIZED
, STARTING
, STARTED
, STOPPING
, STOPPED
};
117 virtual STATE
state() const;
120 std::shared_ptr
<const ThreadFactory
> threadFactory_
;
122 std::multimap
<std::chrono::time_point
<std::chrono::steady_clock
>, std::shared_ptr
<Task
> > taskMap_
;
127 friend class Dispatcher
;
128 std::shared_ptr
<Dispatcher
> dispatcher_
;
129 std::shared_ptr
<Thread
> dispatcherThread_
;
130 using task_iterator
= decltype(taskMap_
)::iterator
;
131 typedef std::pair
<task_iterator
, task_iterator
> task_range
;
135 } // apache::thrift::concurrency
137 #endif // #ifndef _THRIFT_CONCURRENCY_TIMERMANAGER_H_