#endif
}
+void
+event_base_stop_iocp(struct event_base *base)
+{
+#ifdef WIN32
+ int rv;
+
+ if (!base->iocp)
+ return;
+ rv = event_iocp_shutdown(base->iocp, -1);
+ EVUTIL_ASSERT(rv >= 0);
+ base->iocp = NULL;
+#endif
+}
+
void
event_base_free(struct event_base *base)
{
/* XXX(niels) - check for internal events first */
EVUTIL_ASSERT(base);
+#ifdef WIN32
+ event_base_stop_iocp(base);
+#endif
+
/* threading fds if we have them */
if (base->th_notify_fd[0] != -1) {
event_del(&base->th_notify);
EnterCriticalSection(&port->lock);
if (port->shutdown) {
if (--port->n_live_threads == 0)
- ReleaseSemaphore(port->shutdownSemaphore, 1, NULL);
+ ReleaseSemaphore(port->shutdownSemaphore, 1,
+ NULL);
LeaveCriticalSection(&port->lock);
return;
}
int
event_iocp_shutdown(struct event_iocp_port *port, long waitMsec)
{
+ DWORD ms = INFINITE;
int n;
+
EnterCriticalSection(&port->lock);
port->shutdown = 1;
LeaveCriticalSection(&port->lock);
event_iocp_notify_all(port);
- WaitForSingleObject(port->shutdownSemaphore, waitMsec);
+ if (waitMsec >= 0)
+ ms = waitMsec;
+
+ WaitForSingleObject(port->shutdownSemaphore, ms);
EnterCriticalSection(&port->lock);
n = port->n_live_threads;
LeaveCriticalSection(&port->lock);
ev_uintptr_t key);
/** Tell all threads serving an iocp to stop. Wait for up to waitMsec for all
- the threads to finish whatever they're doing. If all the threads are
- done, free the port and return 0. Otherwise, return -1. If you get a -1
- return value, it is safe to call this function again.
+ the threads to finish whatever they're doing. If waitMsec is -1, wait
+ as long as required. If all the threads are done, free the port and return
+ 0. Otherwise, return -1. If you get a -1 return value, it is safe to call
+ this function again.
*/
int event_iocp_shutdown(struct event_iocp_port *port, long waitMsec);
/* FIXME document. */
int event_base_start_iocp(struct event_base *base);
+void event_base_stop_iocp(struct event_base *base);
/* FIXME document. */
struct bufferevent *bufferevent_async_new(struct event_base *base,
buf[n]='\0';
tt_str_op(buf, ==, "Hello world");
- tt_want(!event_iocp_shutdown(port, 2000));
end:
/* FIXME: free stuff. */;
}