Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / stream / stream_event_emitter.cc
blobb81dd8f168d3685cf349d42c09c01ffbd0231c8d
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "nacl_io/stream/stream_event_emitter.h"
7 #include <poll.h>
8 #include <stdint.h>
9 #include <stdlib.h>
11 #include "nacl_io/fifo_interface.h"
12 #include "sdk_util/auto_lock.h"
14 namespace nacl_io {
16 StreamEventEmitter::StreamEventEmitter() : stream_(NULL) {
19 void StreamEventEmitter::AttachStream(StreamNode* stream) {
20 AUTO_LOCK(GetLock());
21 stream_ = stream;
24 void StreamEventEmitter::DetachStream() {
25 AUTO_LOCK(GetLock());
27 RaiseEvents_Locked(POLLHUP);
28 stream_ = NULL;
31 void StreamEventEmitter::UpdateStatus_Locked() {
32 uint32_t status = 0;
33 if (!in_fifo()->IsEmpty())
34 status |= POLLIN;
36 if (!out_fifo()->IsFull())
37 status |= POLLOUT;
39 ClearEvents_Locked(~status);
40 RaiseEvents_Locked(status);
43 } // namespace nacl_io