On 03/03/2011 07:21 AM, Daniel P. Berrange wrote:
The event loop implementation is used by more than just the
daemon, so move it into the shared area.
* daemon/event.c, src/util/event_poll.c: Renamed
* daemon/event.h, src/util/event_poll.h: Renamed
* tools/Makefile.am, tools/console.c, tools/virsh.c: Update
to use new virEventPoll APIs
* daemon/mdns.c, daemon/mdns.c, daemon/Makefile.am: Update
to use new virEventPoll APIs
---
daemon/Makefile.am | 1 -
daemon/event.c | 706 ----------------------------------------------
daemon/event.h | 134 ---------
daemon/libvirtd.c | 18 +-
daemon/mdns.c | 6 +-
src/Makefile.am | 1 +
src/libvirt_private.syms | 13 +
src/util/event_poll.c | 705 +++++++++++++++++++++++++++++++++++++++++++++
src/util/event_poll.h | 132 +++++++++
tools/Makefile.am | 1 -
tools/console.c | 6 +-
tools/virsh.c | 16 +-
12 files changed, 874 insertions(+), 865 deletions(-)
delete mode 100644 daemon/event.c
delete mode 100644 daemon/event.h
create mode 100644 src/util/event_poll.c
create mode 100644 src/util/event_poll.h
git config diff.rename true
That cuts your 66k message down to 25k, making it easier to review.
ACK if you squash this in (did you forget to run 'make check'?):
diff --git i/tests/Makefile.am w/tests/Makefile.am
index 5922b64..5896442 100644
--- i/tests/Makefile.am
+++ w/tests/Makefile.am
@@ -375,7 +375,7 @@ virbuftest_LDADD = $(LDADDS)
if WITH_LIBVIRTD
eventtest_SOURCES = \
- eventtest.c testutils.h testutils.c ../daemon/event.c
+ eventtest.c testutils.h testutils.c
eventtest_LDADD = -lrt $(LDADDS)
endif
diff --git i/tests/eventtest.c w/tests/eventtest.c
index 93317be..4c4a823 100644
--- i/tests/eventtest.c
+++ w/tests/eventtest.c
@@ -31,7 +31,7 @@
#include "threads.h"
#include "logging.h"
#include "util.h"
-#include "../daemon/event.h"
+#include "event_poll.h"
#define NUM_FDS 31
#define NUM_TIME 31
@@ -89,7 +89,7 @@ testPipeReader(int watch, int fd, int events, void *data)
info->error = EV_ERROR_NONE;
if (info->delete != -1)
- virEventRemoveHandleImpl(info->delete);
+ virEventPollRemoveHandle(info->delete);
}
@@ -108,7 +108,7 @@ testTimer(int timer, void *data)
info->error = EV_ERROR_NONE;
if (info->delete != -1)
- virEventRemoveTimeoutImpl(info->delete);
+ virEventPollRemoveTimeout(info->delete);
}
static pthread_mutex_t eventThreadMutex = PTHREAD_MUTEX_INITIALIZER;
@@ -127,7 +127,7 @@ static void *eventThreadLoop(void *data
ATTRIBUTE_UNUSED) {
eventThreadRunOnce = 0;
pthread_mutex_unlock(&eventThreadMutex);
- virEventRunOnce();
+ virEventPollRunOnce();
pthread_mutex_lock(&eventThreadMutex);
eventThreadJobDone = 1;
@@ -288,12 +288,12 @@ mymain(int argc, char **argv)
return EXIT_FAILURE;
}
- virEventInit();
+ virEventPollInit();
for (i = 0 ; i < NUM_FDS ; i++) {
handles[i].delete = -1;
handles[i].watch =
- virEventAddHandleImpl(handles[i].pipeFD[0],
+ virEventPollAddHandle(handles[i].pipeFD[0],
VIR_EVENT_HANDLE_READABLE,
testPipeReader,
&handles[i], NULL);
@@ -303,7 +303,7 @@ mymain(int argc, char **argv)
timers[i].delete = -1;
timers[i].timeout = -1;
timers[i].timer =
- virEventAddTimeoutImpl(timers[i].timeout,
+ virEventPollAddTimeout(timers[i].timeout,
testTimer,
&timers[i], NULL);
}
@@ -324,7 +324,7 @@ mymain(int argc, char **argv)
/* Now lets delete one before starting poll(), and
* try triggering another handle */
- virEventRemoveHandleImpl(handles[0].watch);
+ virEventPollRemoveHandle(handles[0].watch);
startJob();
if (safewrite(handles[1].pipeFD[1], &one, 1) != 1)
return EXIT_FAILURE;
@@ -338,13 +338,13 @@ mymain(int argc, char **argv)
/* NB: this case is subject to a bit of a race condition.
* We yield & sleep, and pray that the other thread gets
- * scheduled before we run EventRemoveHandleImpl */
+ * scheduled before we run EventPollRemoveHandle */
startJob();
pthread_mutex_unlock(&eventThreadMutex);
sched_yield();
usleep(100 * 1000);
pthread_mutex_lock(&eventThreadMutex);
- virEventRemoveHandleImpl(handles[1].watch);
+ virEventPollRemoveHandle(handles[1].watch);
if (finishJob("Interrupted during poll", -1, -1) != EXIT_SUCCESS)
return EXIT_FAILURE;
@@ -380,22 +380,22 @@ mymain(int argc, char **argv)
/* Run a timer on its own */
- virEventUpdateTimeoutImpl(timers[1].timer, 100);
+ virEventPollUpdateTimeout(timers[1].timer, 100);
startJob();
if (finishJob("Firing a timer", -1, 1) != EXIT_SUCCESS)
return EXIT_FAILURE;
- virEventUpdateTimeoutImpl(timers[1].timer, -1);
+ virEventPollUpdateTimeout(timers[1].timer, -1);
resetAll();
/* Now lets delete one before starting poll(), and
* try triggering another timer */
- virEventUpdateTimeoutImpl(timers[1].timer, 100);
- virEventRemoveTimeoutImpl(timers[0].timer);
+ virEventPollUpdateTimeout(timers[1].timer, 100);
+ virEventPollRemoveTimeout(timers[0].timer);
startJob();
if (finishJob("Deleted before poll", -1, 1) != EXIT_SUCCESS)
return EXIT_FAILURE;
- virEventUpdateTimeoutImpl(timers[1].timer, -1);
+ virEventPollUpdateTimeout(timers[1].timer, -1);
resetAll();
@@ -404,13 +404,13 @@ mymain(int argc, char **argv)
/* NB: this case is subject to a bit of a race condition.
* We yield & sleep, and pray that the other thread gets
- * scheduled before we run EventRemoveTimeoutImpl */
+ * scheduled before we run EventPollRemoveTimeout */
startJob();
pthread_mutex_unlock(&eventThreadMutex);
sched_yield();
usleep(100 * 1000);
pthread_mutex_lock(&eventThreadMutex);
- virEventRemoveTimeoutImpl(timers[1].timer);
+ virEventPollRemoveTimeout(timers[1].timer);
if (finishJob("Interrupted during poll", -1, -1) != EXIT_SUCCESS)
return EXIT_FAILURE;
@@ -423,27 +423,27 @@ mymain(int argc, char **argv)
* before poll() exits for the first safewrite(). We don't
* see a hard failure in other cases, so nothing to worry
* about */
- virEventUpdateTimeoutImpl(timers[2].timer, 100);
- virEventUpdateTimeoutImpl(timers[3].timer, 100);
+ virEventPollUpdateTimeout(timers[2].timer, 100);
+ virEventPollUpdateTimeout(timers[3].timer, 100);
startJob();
timers[2].delete = timers[3].timer;
if (finishJob("Deleted during dispatch", -1, 2) != EXIT_SUCCESS)
return EXIT_FAILURE;
- virEventUpdateTimeoutImpl(timers[2].timer, -1);
+ virEventPollUpdateTimeout(timers[2].timer, -1);
resetAll();
/* Extreme fun, lets delete ourselves during dispatch */
- virEventUpdateTimeoutImpl(timers[2].timer, 100);
+ virEventPollUpdateTimeout(timers[2].timer, 100);
startJob();
timers[2].delete = timers[2].timer;
if (finishJob("Deleted during dispatch", -1, 2) != EXIT_SUCCESS)
return EXIT_FAILURE;
for (i = 0 ; i < NUM_FDS - 1 ; i++)
- virEventRemoveHandleImpl(handles[i].watch);
+ virEventPollRemoveHandle(handles[i].watch);
for (i = 0 ; i < NUM_TIME - 1 ; i++)
- virEventRemoveTimeoutImpl(timers[i].timer);
+ virEventPollRemoveTimeout(timers[i].timer);
resetAll();
@@ -464,11 +464,11 @@ mymain(int argc, char **argv)
handles[0].pipeFD[0] = handles[1].pipeFD[0];
handles[0].pipeFD[1] = handles[1].pipeFD[1];
- handles[0].watch = virEventAddHandleImpl(handles[0].pipeFD[0],
+ handles[0].watch = virEventPollAddHandle(handles[0].pipeFD[0],
0,
testPipeReader,
&handles[0], NULL);
- handles[1].watch = virEventAddHandleImpl(handles[1].pipeFD[0],
+ handles[1].watch = virEventPollAddHandle(handles[1].pipeFD[0],
VIR_EVENT_HANDLE_READABLE,
testPipeReader,
&handles[1], NULL);
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org