GlobalThreadPoolList.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 <string>
  19. #include <vector>
  20. #include <folly/Indestructible.h>
  21. #include <folly/Synchronized.h>
  22. #include <folly/ThreadLocal.h>
  23. namespace folly {
  24. /**
  25. * A hook for tracking which threads belong to which thread pools.
  26. * This is used only by a gdb extension to aid in debugging. You won't be able
  27. * to see any useful information from within C++ code.
  28. *
  29. * An instance of ThreadPoolListHook should be created in the thread pool class
  30. * that you want to keep track of. Then, to register a thread you call
  31. * registerThread() on your instance of ThreadPoolListHook from that thread.
  32. *
  33. * When a thread exits it will be removed from the list
  34. * When the thread pool is destroyed, it will be removed from the list
  35. */
  36. class ThreadPoolListHook {
  37. public:
  38. /**
  39. * Name is used to identify the thread pool when listing threads.
  40. */
  41. explicit ThreadPoolListHook(std::string name);
  42. ~ThreadPoolListHook();
  43. /**
  44. * Call this from any new thread that the thread pool creates.
  45. */
  46. void registerThread();
  47. ThreadPoolListHook(const ThreadPoolListHook& other) = delete;
  48. ThreadPoolListHook& operator=(const ThreadPoolListHook&) = delete;
  49. private:
  50. ThreadPoolListHook();
  51. };
  52. } // namespace folly