You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. namespace rtc {
  15. class Location;
  16. }
  17. namespace webrtc {
  18. class Module;
  19. // TODO(tommi): ProcessThread probably doesn't need to be a virtual
  20. // interface. There exists one override besides ProcessThreadImpl,
  21. // MockProcessThread, but when looking at how it is used, it seems
  22. // a nullptr might suffice (or simply an actual ProcessThread instance).
  23. class ProcessThread {
  24. public:
  25. virtual ~ProcessThread();
  26. static std::unique_ptr<ProcessThread> Create(const char* thread_name);
  27. // Starts the worker thread. Must be called from the construction thread.
  28. virtual void Start() = 0;
  29. // Stops the worker thread. Must be called from the construction thread.
  30. virtual void Stop() = 0;
  31. // Wakes the thread up to give a module a chance to do processing right
  32. // away. This causes the worker thread to wake up and requery the specified
  33. // module for when it should be called back. (Typically the module should
  34. // return 0 from TimeUntilNextProcess on the worker thread at that point).
  35. // Can be called on any thread.
  36. virtual void WakeUp(Module* module) = 0;
  37. // Queues a task object to run on the worker thread. Ownership of the
  38. // task object is transferred to the ProcessThread and the object will
  39. // either be deleted after running on the worker thread, or on the
  40. // construction thread of the ProcessThread instance, if the task did not
  41. // get a chance to run (e.g. posting the task while shutting down or when
  42. // the thread never runs).
  43. virtual void PostTask(std::unique_ptr<QueuedTask> task) = 0;
  44. // Adds a module that will start to receive callbacks on the worker thread.
  45. // Can be called from any thread.
  46. virtual void RegisterModule(Module* module, const rtc::Location& from) = 0;
  47. // Removes a previously registered module.
  48. // Can be called from any thread.
  49. virtual void DeRegisterModule(Module* module) = 0;
  50. };
  51. } // namespace webrtc
  52. #endif // MODULES_UTILITY_INCLUDE_PROCESS_THREAD_H_