GlobalExecutor.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2017-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. #pragma once
  17. #include <memory>
  18. #include <folly/Executor.h>
  19. #include <folly/executors/IOExecutor.h>
  20. namespace folly {
  21. /**
  22. * Retrieve the global Executor. If there is none, a default InlineExecutor
  23. * will be constructed and returned. This is named CPUExecutor to distinguish
  24. * it from IOExecutor below and to hint that it's intended for CPU-bound tasks.
  25. *
  26. * Can return nullptr on shutdown.
  27. */
  28. std::shared_ptr<folly::Executor> getCPUExecutor();
  29. /**
  30. * Set an Executor to be the global Executor which will be returned by
  31. * subsequent calls to getCPUExecutor().
  32. */
  33. void setCPUExecutor(std::weak_ptr<folly::Executor> executor);
  34. /**
  35. * Retrieve the global IOExecutor. If there is none, a default
  36. * IOThreadPoolExecutor will be constructed and returned.
  37. *
  38. * IOExecutors differ from Executors in that they drive and provide access to
  39. * one or more EventBases.
  40. *
  41. * Can return nullptr on shutdown.
  42. */
  43. std::shared_ptr<IOExecutor> getIOExecutor();
  44. /**
  45. * Set an IOExecutor to be the global IOExecutor which will be returned by
  46. * subsequent calls to getIOExecutor().
  47. */
  48. void setIOExecutor(std::weak_ptr<IOExecutor> executor);
  49. /**
  50. * Retrieve an event base from the global IOExecutor
  51. *
  52. * NOTE: This is not shutdown-safe, the returned pointer may be
  53. * invalid during shutdown.
  54. */
  55. folly::EventBase* getEventBase();
  56. } // namespace folly