Action Engine
Loading...
Searching...
No Matches
concurrency.h
Go to the documentation of this file.
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
24
25#ifndef ACTIONENGINE_CONCURRENCY_CONCURRENCY_H_
26#define ACTIONENGINE_CONCURRENCY_CONCURRENCY_H_
27
28#include <absl/base/attributes.h>
29#include <absl/base/nullability.h>
30#include <absl/base/thread_annotations.h>
31#include <absl/time/time.h>
32
33#include "thread/concurrency.h"
34
35// IWYU pragma: begin_exports
36#if GOOGLE3
37#include "actionengine/google3_concurrency_headers.h"
38#else
39#include "thread/concurrency.h"
40#endif // GOOGLE3
41// IWYU pragma: end_exports
42
60
62namespace act::concurrency {
63
64#if GOOGLE3
65using CondVar = absl::CondVar;
66using Mutex = absl::Mutex;
67using MutexLock = absl::MutexLock;
68
69inline void SleepFor(absl::Duration duration) {
70 absl::SleepFor(duration);
71}
72#else
73using CondVar = impl::CondVar;
74using Mutex = impl::Mutex;
75using MutexLock = impl::MutexLock;
76
77void SleepFor(absl::Duration duration);
78#endif // GOOGLE3
79
92class ABSL_SCOPED_LOCKABLE TwoMutexLock {
93 public:
94 explicit TwoMutexLock(Mutex* absl_nonnull mu1, Mutex* absl_nonnull mu2)
95 ABSL_EXCLUSIVE_LOCK_FUNCTION(mu1, mu2);
96
97 // This class is not copyable or movable.
98 TwoMutexLock(const TwoMutexLock&) = delete; // NOLINT(runtime/mutex)
99 TwoMutexLock& operator=(const TwoMutexLock&) = delete;
100
101 ~TwoMutexLock() ABSL_UNLOCK_FUNCTION();
102
103 private:
104 Mutex* absl_nonnull const mu1_;
105 Mutex* absl_nonnull const mu2_;
106};
107} // namespace act::concurrency
108
109namespace act {
110
111using concurrency::CondVar;
112using concurrency::Mutex;
113using concurrency::MutexLock;
114
122inline void SleepFor(absl::Duration duration) {
123 concurrency::SleepFor(duration);
124}
125
126} // namespace act
127
128#endif // ACTIONENGINE_CONCURRENCY_CONCURRENCY_H_
void SleepFor(absl::Duration duration)
Sleeps for the given duration, allowing other fibers to proceed on the rest of the thread's quantum,...
Definition concurrency.h:122