Beispiel #1
0
void
IOInterposer::Report(IOInterposeObserver::Observation& aObservation)
{
  MOZ_ASSERT(sMasterList);
  if (!sMasterList) {
    return;
  }

  PerThreadData* ptd = sThreadLocalData.get();
  if (!ptd) {
    // In this case the current thread is not registered with IOInterposer.
    // Alternatively we could take the slow path and just lock everything if
    // we're not registered. That could potentially perform poorly, though.
    return;
  }
  sMasterList->Update(*ptd);

  // Don't try to report if there's nobody listening.
  if (!IOInterposer::IsObservedOperation(aObservation.ObservedOperation())) {
    return;
  }

  ptd->CallObservers(aObservation);
}
Beispiel #2
0
/* static */ void IOInterposer::Report(
  IOInterposeObserver::Observation& aObservation)
{
  // IOInterposer::Init most be called before this method
  MOZ_ASSERT(sObserverLists);
  if (!sObserverLists) {
    return;
  }

  //TODO: We only need read access here, so we should investigate the
  //      performance overhead involved in using some kind of shared lock.
  //      Work towards this end is tracked in bug #913653
  AutoPRLock listLock(sObserverLists->mObserverListsLock);

  // Don't try to report if there's nobody listening
  if (!IOInterposer::IsObservedOperation(aObservation.ObservedOperation())) {
    return;
  }

  // Decide which list of observers to inform
  std::vector<IOInterposeObserver*>* observers = nullptr;
  switch (aObservation.ObservedOperation()) {
    case IOInterposeObserver::OpCreateOrOpen:
      {
        observers = &sObserverLists->mCreateObservers;
      }
      break;
    case IOInterposeObserver::OpRead:
      {
        observers = &sObserverLists->mReadObservers;
      }
      break;
    case IOInterposeObserver::OpWrite:
      {
        observers = &sObserverLists->mWriteObservers;
      }
      break;
    case IOInterposeObserver::OpFSync:
      {
        observers = &sObserverLists->mFSyncObservers;
      }
      break;
    case IOInterposeObserver::OpStat:
      {
        observers = &sObserverLists->mStatObservers;
      }
      break;
    case IOInterposeObserver::OpClose:
      {
        observers = &sObserverLists->mCloseObservers;
      }
      break;
    default:
      {
        // Invalid IO operation, see documentation comment for Report()
        MOZ_ASSERT(false);
        // Just ignore is in non-debug builds.
        return;
      }
  }
  MOZ_ASSERT(observers);

  // Inform observers
  uint32_t nObservers = observers->size();
  for (uint32_t i = 0; i < nObservers; ++i) {
    (*observers)[i]->Observe(aObservation);
  }
}