Exemplo n.º 1
0
LazyIdleThread::Release()
{
  nsrefcnt count = NS_AtomicDecrementRefcnt(mRefCnt);
  NS_LOG_RELEASE(this, count, "LazyIdleThread");

  if (!count) {
    // Stabilize refcount.
    mRefCnt = 1;

    nsCOMPtr<nsIRunnable> runnable =
      NS_NewNonOwningRunnableMethod(this, &LazyIdleThread::SelfDestruct);
    NS_WARN_IF_FALSE(runnable, "Couldn't make runnable!");

    if (NS_FAILED(NS_DispatchToCurrentThread(runnable))) {
      MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
      // The only way this could fail is if we're in shutdown, and in that case
      // threads should have been joined already. Deleting here isn't dangerous
      // anymore because we won't spin the event loop waiting to join the
      // thread.
      SelfDestruct();
    }
  }

  return count;
}
void
GonkVideoDecoderManager::VideoResourceListener::codecCanceled()
{
  if (mManager) {
    nsCOMPtr<nsIRunnable> r =
      NS_NewNonOwningRunnableMethod(mManager, &GonkVideoDecoderManager::codecCanceled);
    mManager->mReaderTaskQueue->Dispatch(r.forget());
  }
}
Exemplo n.º 3
0
void
CrossProcessCompositorParent::DeferredDestroy()
{
  CrossProcessCompositorParent* self;
  mSelfRef.forget(&self);

  nsCOMPtr<nsIRunnable> runnable =
    NS_NewNonOwningRunnableMethod(self, &CrossProcessCompositorParent::Release);
  MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable)));
}
GMPErr
GMPRemoveTest::Decode()
{
  mGMPThread->Dispatch(
    NS_NewNonOwningRunnableMethod(this, &GMPRemoveTest::gmp_Decode),
    NS_DISPATCH_NORMAL);

  mTestMonitor.AwaitFinished();
  return mDecodeResult;
}
void
GMPRemoveTest::CloseVideoDecoder()
{
  mGMPThread->Dispatch(
    NS_NewNonOwningRunnableMethod(mDecoder, &GMPVideoDecoderProxy::Close),
    NS_DISPATCH_SYNC);

  mDecoder = nullptr;
  mHost = nullptr;
}
Exemplo n.º 6
0
  void
  Destroy()
  {
    if (IsOnOwningThread()) {
      delete this;
      return;
    }

    nsCOMPtr<nsIRunnable> destroyRunnable =
      NS_NewNonOwningRunnableMethod(this, &StreamWrapper::Destroy);

    MOZ_ALWAYS_TRUE(NS_SUCCEEDED(mOwningThread->Dispatch(destroyRunnable,
                                                         NS_DISPATCH_NORMAL)));
  }
Exemplo n.º 7
0
void
ChannelMediaResource::CacheClientNotifyDataReceived()
{
  NS_ASSERTION(NS_IsMainThread(), "Don't call on non-main thread");
  // NOTE: this can be called with the media cache lock held, so don't
  // block or do anything which might try to acquire a lock!

  if (mDataReceivedEvent.IsPending())
    return;

  mDataReceivedEvent =
    NS_NewNonOwningRunnableMethod(this, &ChannelMediaResource::DoNotifyDataReceived);
  NS_DispatchToMainThread(mDataReceivedEvent.get(), NS_DISPATCH_NORMAL);
}
Exemplo n.º 8
0
void
DOMStorageDBThread::NotifyFlushCompletion()
{
#ifdef DOM_STORAGE_TESTS
  if (!NS_IsMainThread()) {
    nsRefPtr<nsRunnableMethod<DOMStorageDBThread, void, false> > event =
      NS_NewNonOwningRunnableMethod(this, &DOMStorageDBThread::NotifyFlushCompletion);
    NS_DispatchToMainThread(event);
    return;
  }

  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
  if (obs) {
    obs->NotifyObservers(nullptr, "domstorage-test-flushed", nullptr);
  }
#endif
}
bool
DBusThread::StartEventLoop()
{
  // socketpair opens two sockets for the process to communicate on.
  // This is how android's implementation of the dbus event loop
  // communicates with itself in relation to IPC signals. These
  // sockets are contained sequentially in the same struct in the
  // android code, but we break them out into class members here.
  // Therefore we read into a local array and then copy.

  int sockets[2];
  if (socketpair(AF_LOCAL, SOCK_STREAM, 0, (int*)(&sockets)) < 0) {
    TearDownData();
    return false;
  }
  mControlFdR.rwget() = sockets[0];
  mControlFdW.rwget() = sockets[1];
  pollfd p;
  p.fd = mControlFdR.get();
  p.events = POLLIN;
  mPollData.AppendElement(p);

  // Due to the fact that mPollData and mWatchData have to match, we
  // push a null to the front of mWatchData since it has the control
  // fd in the first slot of mPollData.

  mWatchData.AppendElement((DBusWatch*)NULL);
  if (!SetUpEventLoop()) {
    TearDownData();
    return false;
  }
  if (NS_FAILED(NS_NewNamedThread("DBus Poll",
                                  getter_AddRefs(mThread),
                                  NS_NewNonOwningRunnableMethod(this,
                                                                &DBusThread::EventLoop)))) {
    NS_WARNING("Cannot create DBus Thread!");
    return false;    
  }
#ifdef DEBUG
  LOG("DBus Thread Starting\n");
#endif
  return true;
}
Exemplo n.º 10
0
bool
NuwaParent::RecvNotifyReady()
{
#ifdef MOZ_NUWA_PROCESS
  if (!mContentParent || !mContentParent->IsNuwaProcess()) {
    NS_ERROR("Received NotifyReady() message from a non-Nuwa process.");
    return false;
  }

  // Creating a NonOwningRunnableMethod here is safe because refcount changes of
  // mContentParent have to go the the main thread. The mContentParent will
  // be alive when the runnable runs.
  nsCOMPtr<nsIRunnable> runnable =
    NS_NewNonOwningRunnableMethod(mContentParent.get(),
                                  &ContentParent::OnNuwaReady);
  MOZ_ASSERT(runnable);
  MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable)));

  return true;
#else
  NS_ERROR("NuwaParent::RecvNotifyReady() not implemented!");
  return false;
#endif
}