Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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. | |
| 4 | |
| 5 #ifndef LIBRARIES_NACL_IO_EVENT_EMITTER_PACKET_H_ | |
| 6 #define LIBRARIES_NACL_IO_EVENT_EMITTER_PACKET_H_ | |
| 7 | |
| 8 #include <poll.h> | |
| 9 #include <stdint.h> | |
| 10 #include <stdlib.h> | |
| 11 | |
| 12 #include "nacl_io/event_emitter.h" | |
| 13 #include "nacl_io/fifo_packet.h" | |
| 14 | |
| 15 #include "sdk_util/auto_lock.h" | |
| 16 | |
| 17 namespace nacl_io { | |
| 18 | |
| 19 class EventEmitterPacket; | |
| 20 typedef sdk_util::ScopedRef<EventEmitterPacket> ScopedEmitterPacket; | |
| 21 | |
| 22 class EventEmitterPacket : public EventEmitter { | |
| 23 public: | |
| 24 EventEmitterPacket(size_t rsize, size_t wsize) | |
|
binji
2013/09/12 01:47:56
I'd prefer having a .cc file instead of defining t
noelallen1
2013/09/12 23:19:03
That's in the follow on.
| |
| 25 : rfifo_(NULL), | |
| 26 wfifo_(NULL), | |
| 27 event_status_(0) { | |
| 28 | |
| 29 rsize = std::max<size_t>(1, rsize); | |
| 30 fifo_ = new FIFOPacket(rsize); | |
|
binji
2013/09/12 01:47:56
Why allocate?
If you define these as non-pointer
noelallen1
2013/09/12 23:19:03
I was allowing for more sharing in the parent clas
| |
| 31 | |
| 32 wsize = std::max<size_t>(1, wsize); | |
| 33 fifo_ = new FIFOPacket(wsize); | |
| 34 | |
| 35 UpdateStatusLocked(); | |
| 36 } | |
| 37 | |
| 38 ~EventEmitterPipe() { | |
| 39 delete rfifo_; | |
| 40 delete wfifo_; | |
| 41 } | |
| 42 | |
| 43 virtual uint32_t GetEventStatus() { | |
| 44 return event_status_; | |
| 45 } | |
| 46 | |
| 47 Packet* ReadPacket() { | |
|
binji
2013/09/12 01:47:56
what's the ownership of the returned packet?
noelallen1
2013/09/12 23:19:03
I'll comment.
| |
| 48 AUTO_LOCK(emitter_lock_); | |
| 49 Packet* packet = rfifo_->Read(); | |
| 50 | |
| 51 UpdateStatusLocked(); | |
| 52 return packet; | |
| 53 } | |
| 54 | |
| 55 uint32_t WritePacket(Packet* packet) { | |
|
binji
2013/09/12 01:47:56
ownership of passed packet?
noelallen1
2013/09/12 23:19:03
Done.
| |
| 56 AUTO_LOCK(emitter_lock_); | |
| 57 uint32_t result = rfifo_->Write(packet); | |
| 58 | |
| 59 UpdateStatusLocked(); | |
| 60 return result; | |
| 61 } | |
| 62 | |
| 63 protected: | |
| 64 void UpdateStatusLocked() { | |
| 65 uint32_t old_status = event_status_; | |
| 66 | |
| 67 if (!rfifo_->IsEmpty()) { | |
| 68 event_status_ |= POLLIN; | |
| 69 } else { | |
| 70 event_status_ &= ~POLLIN; | |
| 71 } | |
| 72 | |
| 73 if (!wfifo_->IsFull()) { | |
| 74 event_status_ |= POLLOUT; | |
| 75 } else { | |
| 76 event_status_ &= ~POLLOUT; | |
| 77 } | |
| 78 | |
| 79 uint32_t raise_status = event_status_ & ~old_status; | |
| 80 if (raise_status) | |
| 81 RaiseEvents_Locked(raise_status); | |
| 82 } | |
| 83 | |
| 84 FIFOPacket* rfifo_; | |
| 85 FIFOPacket* wfifo_; | |
| 86 uint32_t event_status_; | |
| 87 }; | |
| 88 | |
| 89 } // namespace nacl_io | |
| 90 | |
| 91 #endif // LIBRARIES_NACL_IO_EVENT_EMITTER_PIPE_H_ | |
|
binji
2013/09/12 01:47:56
PACKET_H_
noelallen1
2013/09/12 23:19:03
Done.
| |
| 92 | |
| OLD | NEW |