process_thread.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_
  11. #define MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_
  12. #include <memory>
  13. #include "api/task_queue/queued_task.h"
  14. #include "api/task_queue/task_queue_base.h"
  15. namespace rtc {
  16. class Location;
  17. }
  18. namespace webrtc {
  19. class Module;
  20. // TODO(tommi): ProcessThread probably doesn't need to be a virtual
  21. // interface. There exists one override besides ProcessThreadImpl,
  22. // MockProcessThread, but when looking at how it is used, it seems
  23. // a nullptr might suffice (or simply an actual ProcessThread instance).
  24. class ProcessThread : public TaskQueueBase {
  25. public:
  26. ~ProcessThread() override;
  27. static std::unique_ptr<ProcessThread> Create(const char* thread_name);
  28. // Starts the worker thread. Must be called from the construction thread.
  29. virtual void Start() = 0;
  30. // Stops the worker thread. Must be called from the construction thread.
  31. virtual void Stop() = 0;
  32. // Wakes the thread up to give a module a chance to do processing right
  33. // away. This causes the worker thread to wake up and requery the specified
  34. // module for when it should be called back. (Typically the module should
  35. // return 0 from TimeUntilNextProcess on the worker thread at that point).
  36. // Can be called on any thread.
  37. virtual void WakeUp(Module* module) = 0;
  38. // Adds a module that will start to receive callbacks on the worker thread.
  39. // Can be called from any thread.
  40. virtual void RegisterModule(Module* module, const rtc::Location& from) = 0;
  41. // Removes a previously registered module.
  42. // Can be called from any thread.
  43. virtual void DeRegisterModule(Module* module) = 0;
  44. };
  45. } // namespace webrtc
  46. #endif // MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_