WorkerHolder.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "WorkerHolder.h"
  6. #include "WorkerPrivate.h"
  7. BEGIN_WORKERS_NAMESPACE
  8. WorkerHolder::WorkerHolder()
  9. : mWorkerPrivate(nullptr)
  10. {
  11. }
  12. WorkerHolder::~WorkerHolder()
  13. {
  14. NS_ASSERT_OWNINGTHREAD(WorkerHolder);
  15. ReleaseWorkerInternal();
  16. MOZ_ASSERT(mWorkerPrivate == nullptr);
  17. }
  18. bool
  19. WorkerHolder::HoldWorker(WorkerPrivate* aWorkerPrivate, Status aFailStatus)
  20. {
  21. NS_ASSERT_OWNINGTHREAD(WorkerHolder);
  22. MOZ_ASSERT(aWorkerPrivate);
  23. aWorkerPrivate->AssertIsOnWorkerThread();
  24. if (!aWorkerPrivate->AddHolder(this, aFailStatus)) {
  25. return false;
  26. }
  27. mWorkerPrivate = aWorkerPrivate;
  28. return true;
  29. }
  30. void
  31. WorkerHolder::ReleaseWorker()
  32. {
  33. NS_ASSERT_OWNINGTHREAD(WorkerHolder);
  34. MOZ_ASSERT(mWorkerPrivate);
  35. ReleaseWorkerInternal();
  36. }
  37. void
  38. WorkerHolder::ReleaseWorkerInternal()
  39. {
  40. NS_ASSERT_OWNINGTHREAD(WorkerHolder);
  41. if (mWorkerPrivate) {
  42. mWorkerPrivate->AssertIsOnWorkerThread();
  43. mWorkerPrivate->RemoveHolder(this);
  44. mWorkerPrivate = nullptr;
  45. }
  46. }
  47. END_WORKERS_NAMESPACE