Changeset 8:dba41f33ddce in xplcommon for src/xplcommon
- Timestamp:
- 12/29/12 08:01:50 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/xplcommon
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/xplcommon/WaitableEvent.h
r7 r8 44 44 * An event on which one can wait with a waiter. 45 45 */ 46 class WaitableEvent : public Waitable 46 class WaitableEvent : public Waitable, public Failable 47 47 { 48 48 public: 49 49 /** 50 50 * Construct the event. 51 * 52 * @param waiter the waiter to be used for waiting. If given, the 53 * check() function will always return immediately. If not given, 54 * the check() function may block and returns only when the event 55 * is fired. 51 56 */ 52 57 WaitableEvent(Waiter* waiter = 0); -
src/xplcommon/posix/WaitableEvent.cc
r6 r8 48 48 49 49 WaitableEvent::WaitableEvent(Waiter* waiter) : 50 Waitable(waiter, eventfd(0, EFD_NONBLOCK), POLLIN) 50 Waitable(waiter, eventfd(0, (waiter==0) ? 0 : EFD_NONBLOCK), POLLIN), 51 fired(false) 51 52 { 52 53 assert(fd>=0); … … 67 68 if (write(fd, &one, sizeof(one))<0) { 68 69 if (errno!=EAGAIN) { 69 perror("xplcommon::posix::WaitableEvent::fire: write"); 70 assert(0); 70 setErrorCode(errno); 71 71 } 72 72 } … … 77 77 bool WaitableEvent::check() 78 78 { 79 if ( fired) {79 if (doCheck()) { 80 80 fired = false; 81 81 return true; … … 97 97 { 98 98 if ((events&POLLIN)==POLLIN) { 99 uint64_t value = 0; 100 if (read(fd, &value, sizeof(value))<0) { 101 if (errno!=EAGAIN) { 102 perror("xplcommon::posix::WaitableEvent::handleEvents: read"); 103 assert(0); 104 } 105 } else { 106 fired = value>0; 99 doCheck(); 100 } 101 } 102 103 //------------------------------------------------------------------------------ 104 105 bool WaitableEvent::doCheck(bool fromHandleEvents) 106 { 107 if (failed()) return false; 108 if (!fromHandleEvents && fired) return true; 109 110 uint64_t value = 0; 111 if (read(fd, &value, sizeof(value))<0) { 112 if (errno!=EAGAIN) { 113 setErrorCode(errno); 107 114 } 115 } else { 116 fired = fired || value>0; 108 117 } 118 119 return fired; 109 120 } 110 121 -
src/xplcommon/posix/WaitableEvent.h
r6 r8 34 34 #include "Waitable.h" 35 35 36 #include "../Failable.h" 37 36 38 //------------------------------------------------------------------------------ 37 39 … … 43 45 * An event on which one can wait with a waiter. 44 46 */ 45 class WaitableEvent : public Waitable 47 class WaitableEvent : public Waitable, public Failable 46 48 { 47 49 private: … … 83 85 */ 84 86 virtual void handleEvents(short events); 87 88 private: 89 /** 90 * Perform the real check. If we already know that we are fired, 91 * just return true. Otherwise try to read from the event fd. 92 */ 93 bool doCheck(bool fromHandleEvents = false); 85 94 }; 86 95
Note:
See TracChangeset
for help on using the changeset viewer.