/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2017-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#pragma once
-#include <folly/Baton.h>
#include <folly/Function.h>
#include <folly/IndexedMemPool.h>
#include <folly/Portability.h>
-#include <folly/detail/CacheLocality.h>
+#include <folly/concurrency/CacheLocality.h>
+#include <folly/synchronization/SaturatingSemaphore.h>
#include <atomic>
#include <cassert>
#include <mutex>
+#include <thread>
namespace folly {
///
/// FC is an alternative to coarse-grained locking for making
/// sequential data structures thread-safe while minimizing the
-/// synchroniation overheads and cache coherence traffic associated
+/// synchronization overheads and cache coherence traffic associated
/// with locking.
///
/// Under FC, when a thread finds the lock contended, it can
/// and acquiring the lock are eliminated from the critical path of
/// operating on the data structure.
/// - Opportunities for smart combining, where executing multiple
-/// operations together may take less time than executng the
+/// operations together may take less time than executing the
/// operations separately, e.g., K delete_min operations on a
/// priority queue may be combined to take O(K + log N) time instead
/// of O(K * log N).
/// - A simple interface that requires minimal extra code by the
/// user. To use this interface efficiently the user-provided
-/// functions must be copyable to folly::Functio without dynamic
+/// functions must be copyable to folly::Function without dynamic
/// allocation. If this is impossible or inconvenient, the user is
/// encouraged to use the custom interface described below.
-/// - A custom interface that supports custom combinining and custom
+/// - A custom interface that supports custom combining and custom
/// request structure, either for the sake of smart combining or for
/// efficiently supporting operations that are not be copyable to
-/// folly::Function without synamic allocation.
+/// folly::Function without dynamic allocation.
/// - Both synchronous and asynchronous operations.
/// - Request records with and without thread-caching.
/// - Combining with and without a dedicated combiner thread.
/// Combining request record.
class Rec {
FOLLY_ALIGN_TO_AVOID_FALSE_SHARING
- folly::Baton<Atom, true, false> valid_;
- folly::Baton<Atom, true, false> done_;
- folly::Baton<Atom, true, false> disconnected_;
+ folly::SaturatingSemaphore<false, Atom> valid_;
+ folly::SaturatingSemaphore<false, Atom> done_;
+ folly::SaturatingSemaphore<false, Atom> disconnected_;
size_t index_;
size_t next_;
uint64_t last_;
}
bool isValid() const {
- return valid_.try_wait();
+ return valid_.ready();
}
void setDone() {
}
bool isDone() const {
- return done_.try_wait();
+ return done_.ready();
}
void awaitDone() {
}
bool isDisconnected() const {
- return disconnected_.try_wait();
+ return disconnected_.ready();
}
void setIndex(const size_t index) {
Mutex m_;
FOLLY_ALIGN_TO_AVOID_FALSE_SHARING
- folly::Baton<Atom, false, true> pending_;
+ folly::SaturatingSemaphore<true, Atom> pending_;
Atom<bool> shutdown_{false};
FOLLY_ALIGN_TO_AVOID_FALSE_SHARING
}
bool isPending() const {
- return pending_.try_wait();
+ return pending_.ready();
}
void awaitPending() {
}
};
-} // namespace folly {
+} // namespace folly