proxygen
fibers.cpp
Go to the documentation of this file.
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/python/fibers.h>
18 #include <folly/fibers/CallOnce.h>
19 #include <folly/python/fiber_manager_api.h>
20 
21 namespace folly {
22 namespace python {
23 
27  // Use call_once because Python performance is really poor,
28  // just to check if a module was already imported
29  folly::call_once(flag, [&]() {
30  // Use main context, because import can load arbitrary number of files,
31  // which is incompatible with fiber stack size restrictions
33  import_folly__fiber_manager();
34  if (PyErr_Occurred() != nullptr) {
35  throw std::logic_error("Fail to import cython fiber_manager");
36  }
37  });
38  });
39  return get_fiber_manager(opts);
40 }
41 
42 } // namespace python
43 } // namespace folly
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
static once_flag flag
Definition: Random.cpp:75
FOLLY_ALWAYS_INLINE void call_once(basic_once_flag< Mutex, Atom > &flag, F &&f, Args &&...args)
Definition: CallOnce.h:56
Single-threaded task execution engine.
invoke_result_t< F > runInMainContext(F &&func)
folly::fibers::FiberManager * getFiberManager(const folly::fibers::FiberManager::Options &opts)
Definition: fibers.cpp:24