Apache Mesos
latch.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License
12 
13 #ifndef __PROCESS_LATCH_HPP__
14 #define __PROCESS_LATCH_HPP__
15 
16 #include <atomic>
17 
18 #include <process/pid.hpp>
19 
20 #include <stout/duration.hpp>
21 
22 namespace process {
23 
24 class Latch
25 {
26 public:
27  Latch();
28  virtual ~Latch();
29 
30  bool operator==(const Latch& that) const { return pid == that.pid; }
31  bool operator<(const Latch& that) const { return pid < that.pid; }
32 
33  // Returns true if the latch was triggered, false if the latch had
34  // already been triggered.
35  bool trigger();
36 
37  // Returns true if the latch was triggered within the specified
38  // duration, otherwise false.
39  bool await(const Duration& duration = Seconds(-1));
40 
41 private:
42  // Not copyable, not assignable.
43  Latch(const Latch& that);
44  Latch& operator=(const Latch& that);
45 
46  std::atomic_bool triggered;
47  UPID pid;
48 };
49 
50 } // namespace process {
51 
52 #endif // __PROCESS_LATCH_HPP__
virtual ~Latch()
bool operator==(const Latch &that) const
Definition: latch.hpp:30
Definition: duration.hpp:32
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
Definition: duration.hpp:207
bool operator<(const Latch &that) const
Definition: latch.hpp:31
Definition: executor.hpp:47
bool await(const Duration &duration=Seconds(-1))
Definition: latch.hpp:24