You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2006/12/21 03:22:13 UTC
svn commit: r489249 - in /incubator/qpid/branches/event-queue-2006-12-20/cpp:
lib/common/sys/posix/EventChannel.cpp lib/common/sys/posix/EventChannel.h
tests/EventChannelTest.cpp
Author: aconway
Date: Wed Dec 20 18:22:12 2006
New Revision: 489249
URL: http://svn.apache.org/viewvc?view=rev&rev=489249
Log:
Simplify EventChannel.cpp: remove unnecessary DispatchEvent feature.
Modified:
incubator/qpid/branches/event-queue-2006-12-20/cpp/lib/common/sys/posix/EventChannel.cpp
incubator/qpid/branches/event-queue-2006-12-20/cpp/lib/common/sys/posix/EventChannel.h
incubator/qpid/branches/event-queue-2006-12-20/cpp/tests/EventChannelTest.cpp
Modified: incubator/qpid/branches/event-queue-2006-12-20/cpp/lib/common/sys/posix/EventChannel.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/event-queue-2006-12-20/cpp/lib/common/sys/posix/EventChannel.cpp?view=diff&rev=489249&r1=489248&r2=489249
==============================================================================
--- incubator/qpid/branches/event-queue-2006-12-20/cpp/lib/common/sys/posix/EventChannel.cpp (original)
+++ incubator/qpid/branches/event-queue-2006-12-20/cpp/lib/common/sys/posix/EventChannel.cpp Wed Dec 20 18:22:12 2006
@@ -151,8 +151,7 @@
/**
- * Holds the epoll fd, Descriptor map and dispatch queue.
- * Most of the epoll work is done by the Descriptors.
+ * Holds a map of Descriptors, which do most of the work.
*/
class EventChannel::Impl {
public:
@@ -168,8 +167,6 @@
/** Wait for an event, return 0 on timeout */
Event* wait(Time timeout);
- Queue& getDispatchQueue() { return *dispatchQueue; }
-
void shutdown();
private:
@@ -179,9 +176,8 @@
Monitor monitor;
int epollFd;
DescriptorMap descriptors;
- int pipe[2];
+ int shutdownPipe[2];
AtomicCount nWaiters;
- Queue* dispatchQueue;
bool isShutdown;
};
@@ -336,7 +332,7 @@
EventChannel::Impl::Impl(int epollSize):
- epollFd(-1), dispatchQueue(0), isShutdown(false)
+ epollFd(-1), isShutdown(false)
{
// Create the epoll file descriptor.
epollFd = epoll_create(epollSize);
@@ -345,17 +341,16 @@
// Create a pipe and write a single byte. The byte is never
// read so the pipes read fd is always ready for read.
// We activate the FD when there are messages in the queue.
- QPID_POSIX_CHECK(::pipe(pipe));
+ QPID_POSIX_CHECK(::pipe(shutdownPipe));
static char zero = '\0';
- QPID_POSIX_CHECK(::write(pipe[1], &zero, 1));
- dispatchQueue = &getDescriptor(pipe[0]).getQueue(IN);
+ QPID_POSIX_CHECK(::write(shutdownPipe[1], &zero, 1));
}
EventChannel::Impl::~Impl() {
shutdown();
::close(epollFd);
- ::close(pipe[0]);
- ::close(pipe[1]);
+ ::close(shutdownPipe[0]);
+ ::close(shutdownPipe[1]);
}
@@ -369,18 +364,11 @@
// TODO aconway 2006-12-20: If I just close the epollFd will
// that wake all threads? If so with what? Would be simpler than:
- // Create a pipe and write a single byte. The byte is never
- // read so the pipes read fd is always ready for read.
- // Since we use level-triggered epoll this will wake up all
- // wait() threads.
- //
- QPID_POSIX_CHECK(::pipe(pipe));
- static char zero = '\0';
- QPID_POSIX_CHECK(::write(pipe[1], &zero, 1));
CleanStruct<epoll_event> ee;
ee.data.ptr = 0;
ee.events = EPOLLIN;
- QPID_POSIX_CHECK(epoll_ctl(epollFd, EPOLL_CTL_ADD, pipe[0], &ee));
+ QPID_POSIX_CHECK(
+ epoll_ctl(epollFd, EPOLL_CTL_ADD, shutdownPipe[0], &ee));
}
// Wait for nWaiters to get out.
while (nWaiters > 0) {
@@ -455,8 +443,6 @@
if (ed == 0) // We're being shut-down.
throw ShutdownException();
assert(ed != 0);
- // TODO aconway 2006-12-20: DEBUG
- cout << endl << epoll(ee.events) << endl;
event = ed->wake(ee.events);
}
return event;
@@ -590,11 +576,5 @@
ed.shutdownUnsafe(); // Called with lock held.
}
}
-
-void DispatchEvent::prepare(EventChannel::Impl& impl) {
- impl.getDispatchQueue().push(this);
-}
-
-void DispatchEvent::complete(EventChannel::Descriptor&) {}
}}
Modified: incubator/qpid/branches/event-queue-2006-12-20/cpp/lib/common/sys/posix/EventChannel.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/event-queue-2006-12-20/cpp/lib/common/sys/posix/EventChannel.h?view=diff&rev=489249&r1=489248&r2=489249
==============================================================================
--- incubator/qpid/branches/event-queue-2006-12-20/cpp/lib/common/sys/posix/EventChannel.h (original)
+++ incubator/qpid/branches/event-queue-2006-12-20/cpp/lib/common/sys/posix/EventChannel.h Wed Dec 20 18:22:12 2006
@@ -125,20 +125,7 @@
friend class EventChannel::Queue;
};
-/**
- * An event that does not wait for anything, it is processed
- * immediately by one of the channel threads.
- */
-class DispatchEvent : public Event {
- public:
- DispatchEvent(Callback cb=0) : Event(cb) {}
-
- protected:
- void prepare(EventChannel::Impl&);
- void complete(EventChannel::Descriptor&);
-};
-
-// Utility base class.
+/** Base class for events related to a file descriptor */
class FDEvent : public Event {
public:
int getDescriptor() const { return descriptor; }
@@ -149,7 +136,7 @@
int descriptor;
};
-// Utility base class
+/** Base class for read or write events. */
class IOEvent : public FDEvent {
public:
size_t getSize() const { return size; }
Modified: incubator/qpid/branches/event-queue-2006-12-20/cpp/tests/EventChannelTest.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/event-queue-2006-12-20/cpp/tests/EventChannelTest.cpp?view=diff&rev=489249&r1=489248&r2=489249
==============================================================================
--- incubator/qpid/branches/event-queue-2006-12-20/cpp/tests/EventChannelTest.cpp (original)
+++ incubator/qpid/branches/event-queue-2006-12-20/cpp/tests/EventChannelTest.cpp Wed Dec 20 18:22:12 2006
@@ -47,7 +47,6 @@
class EventChannelTest : public CppUnit::TestCase
{
CPPUNIT_TEST_SUITE(EventChannelTest);
- CPPUNIT_TEST(testDispatch);
CPPUNIT_TEST(testRead);
CPPUNIT_TEST(testPartialRead);
CPPUNIT_TEST(testFailedRead);
@@ -86,18 +85,6 @@
return &event == next;
}
- void testDispatch()
- {
- RunMe runMe;
- CPPUNIT_ASSERT(!runMe.ran);
- // Instances of Event just pass thru the channel immediately.
- DispatchEvent e(runMe.functor());
- ec->post(e);
- CPPUNIT_ASSERT(isNextEventOk(e));
- e.dispatch();
- CPPUNIT_ASSERT(runMe.ran);
- }
-
void testRead() {
ReadEvent re(pipe[0], readBuf, size);
ec->post(re);