folly/folly/synchronization/test/Semaphore.h

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <condition_variable>
#include <cstddef>
#include <mutex>
#include <stdexcept>
#include <type_traits>
#include <utility>

#include <boost/intrusive/list.hpp>

#include <folly/Optional.h>
#include <folly/ScopeGuard.h>
#include <folly/lang/Exception.h>

namespace folly {
namespace test {

//  Semaphore
//
//  A basic portable semaphore, primarily intended for testing scenarios. Likely
//  to be much less performant than better-optimized semaphore implementations.
//
//  In the interest of portability, uses only synchronization mechanisms shipped
//  with all implementations of C++: std::mutex and std::condition_variable.
class Semaphore {};

enum class SemaphoreWakePolicy {};

//  PolicySemaphore
//
//  A basic portable semaphore, primarily intended for testing scenarios. Likely
//  to be much less performant than better-optimized semaphore implementations.
//
//  Like Semaphore above, but with controlled wake order.
//
//  In the interest of portability, uses only synchronization mechanisms shipped
//  with all implementations of C++: std::mutex and std::condition_variable.
template <SemaphoreWakePolicy WakePolicy>
class PolicySemaphore {};

FifoSemaphore;
LifoSemaphore;

} // namespace test
} // namespace folly