|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 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 "cachelib/navy/common/NavyThread.h" |
| 18 | + |
| 19 | +namespace facebook::cachelib::navy { |
| 20 | + |
| 21 | +static thread_local NavyThread* currentNavyThread_ = nullptr; |
| 22 | + |
| 23 | +NavyThread* getCurrentNavyThread() { return currentNavyThread_; } |
| 24 | + |
| 25 | +NavyThread::NavyThread(folly::StringPiece name, Options options) { |
| 26 | + th_ = std::make_unique<folly::ScopedEventBaseThread>(name.str()); |
| 27 | + |
| 28 | + folly::fibers::FiberManager::Options opts; |
| 29 | + opts.stackSize = |
| 30 | + options.stackSize ? options.stackSize : Options::kDefaultStackSize; |
| 31 | + auto& eb = *th_->getEventBase(); |
| 32 | + fm_ = &folly::fibers::getFiberManager(eb, opts); |
| 33 | + |
| 34 | + eb.runInEventBaseThreadAndWait([this]() { currentNavyThread_ = this; }); |
| 35 | +} |
| 36 | + |
| 37 | +NavyThread::~NavyThread() { th_.reset(); } |
| 38 | + |
| 39 | +} // namespace facebook::cachelib::navy |
0 commit comments