| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "nacl_io/stream/stream_event_emitter.h" | 5 #include "nacl_io/stream/stream_event_emitter.h" |
| 6 | 6 |
| 7 #include <poll.h> | 7 #include <poll.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 | 10 |
| 11 #include "nacl_io/fifo_interface.h" | 11 #include "nacl_io/fifo_interface.h" |
| 12 #include "sdk_util/auto_lock.h" | 12 #include "sdk_util/auto_lock.h" |
| 13 | 13 |
| 14 namespace nacl_io { | 14 namespace nacl_io { |
| 15 | 15 |
| 16 StreamEventEmitter::StreamEventEmitter() : stream_(NULL) {} | 16 StreamEventEmitter::StreamEventEmitter() : stream_(NULL) { |
| 17 } |
| 17 | 18 |
| 18 void StreamEventEmitter::AttachStream(StreamNode* stream) { | 19 void StreamEventEmitter::AttachStream(StreamNode* stream) { |
| 19 AUTO_LOCK(GetLock()); | 20 AUTO_LOCK(GetLock()); |
| 20 stream_ = stream; | 21 stream_ = stream; |
| 21 } | 22 } |
| 22 | 23 |
| 23 void StreamEventEmitter::DetachStream() { | 24 void StreamEventEmitter::DetachStream() { |
| 24 AUTO_LOCK(GetLock()); | 25 AUTO_LOCK(GetLock()); |
| 25 | 26 |
| 26 RaiseEvents_Locked(POLLHUP); | 27 RaiseEvents_Locked(POLLHUP); |
| 27 stream_ = NULL; | 28 stream_ = NULL; |
| 28 } | 29 } |
| 29 | 30 |
| 30 void StreamEventEmitter::UpdateStatus_Locked() { | 31 void StreamEventEmitter::UpdateStatus_Locked() { |
| 31 uint32_t status = 0; | 32 uint32_t status = 0; |
| 32 if (!in_fifo()->IsEmpty()) | 33 if (!in_fifo()->IsEmpty()) |
| 33 status |= POLLIN; | 34 status |= POLLIN; |
| 34 | 35 |
| 35 if (!out_fifo()->IsFull()) | 36 if (!out_fifo()->IsFull()) |
| 36 status |= POLLOUT; | 37 status |= POLLOUT; |
| 37 | 38 |
| 38 ClearEvents_Locked(~status); | 39 ClearEvents_Locked(~status); |
| 39 RaiseEvents_Locked(status); | 40 RaiseEvents_Locked(status); |
| 40 } | 41 } |
| 41 | 42 |
| 42 } // namespace nacl_io | 43 } // namespace nacl_io |
| OLD | NEW |