DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d1ed7de67f5a)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/waitable_event_watcher.h"

#include "base/compiler_specific.h"
#include "base/object_watcher.h"
#include "base/waitable_event.h"

namespace base {

WaitableEventWatcher::ObjectWatcherHelper::ObjectWatcherHelper(
    WaitableEventWatcher* watcher)
    : watcher_(watcher) {
};

void WaitableEventWatcher::ObjectWatcherHelper::OnObjectSignaled(HANDLE h) {
  watcher_->OnObjectSignaled();
}


WaitableEventWatcher::WaitableEventWatcher()
    : event_(NULL),
      ALLOW_THIS_IN_INITIALIZER_LIST(helper_(this)),
      delegate_(NULL) {
}

WaitableEventWatcher::~WaitableEventWatcher() {
}

bool WaitableEventWatcher::StartWatching(WaitableEvent* event,
                                         Delegate* delegate) {
  delegate_ = delegate;
  event_ = event;

  return watcher_.StartWatching(event->handle(), &helper_);
}

void WaitableEventWatcher::StopWatching() {
  delegate_ = NULL;
  event_ = NULL;
  watcher_.StopWatching();
}

WaitableEvent* WaitableEventWatcher::GetWatchedEvent() {
  return event_;
}

void WaitableEventWatcher::OnObjectSignaled() {
  WaitableEvent* event = event_;
  Delegate* delegate = delegate_;
  event_ = NULL;
  delegate_ = NULL;
  DCHECK(event);

  delegate->OnWaitableEventSignaled(event);
}

}  // namespace base