1/*
2 * Copyright 2018-present Facebook, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <folly/experimental/AtomicReadMostlyMainPtr.h>
18
19#include <folly/executors/InlineExecutor.h>
20
21namespace folly {
22namespace detail {
23
24namespace {
25struct FailingExecutor : folly::Executor {
26 // We shouldn't be invoking any callbacks.
27 void add(Func func) override {
28 LOG(DFATAL)
29 << "Added an RCU callback to the AtomicReadMostlyMainPtr executor.";
30 InlineExecutor::instance().add(std::move(func));
31 }
32};
33} // namespace
34
35// *All* modifications of *all* AtomicReadMostlyMainPtrs use the same mutex and
36// domain. The first of these just shrinks the size of the individual objects a
37// little, but the second is necessary for correctness; all rcu_domains need
38// their own tag (as an rcu_domain API constraint), but we want to support
39// arbitrarily many AtomicReadMostlyMainPtrs.
40Indestructible<std::mutex> atomicReadMostlyMu;
41Indestructible<folly::rcu_domain<detail::AtomicReadMostlyTag>>
42 atomicReadMostlyDomain(new FailingExecutor);
43
44} // namespace detail
45} // namespace folly
46