]> granicus.if.org Git - libevent/commitdiff
Fix a few locking issues on windows.
authorunknown <Nick Mathewson@.(none)>
Mon, 21 Dec 2009 21:36:40 +0000 (16:36 -0500)
committerunknown <Nick Mathewson@.(none)>
Mon, 21 Dec 2009 21:36:40 +0000 (16:36 -0500)
evdns.c
evthread.c
test/regress_iocp.c

diff --git a/evdns.c b/evdns.c
index 43a5255bae98a94883dc38742f7151d05c77b63f..1eb8f9c4fec60f2fa085fcf80d760da219a2385e 100644 (file)
--- a/evdns.c
+++ b/evdns.c
@@ -3609,8 +3609,10 @@ evdns_base_config_windows_nameservers(struct evdns_base *base)
        if (base == NULL)
                return -1;
        EVDNS_LOCK(base);
-       if (load_nameservers_with_getnetworkparams(base) == 0)
+       if (load_nameservers_with_getnetworkparams(base) == 0) {
+               EVDNS_UNLOCK(base);
                return 0;
+       }
        r = load_nameservers_from_registry(base);
        EVDNS_UNLOCK(base);
        return r;
index 66d7a3dd04cb8c8aa5a7a0e316bf894b78b806e9..f12eed7bddc699927260c16cc22f28ce269dc223 100644 (file)
@@ -170,6 +170,8 @@ debug_lock_alloc(unsigned locktype)
                        mm_free(result);
                        return NULL;
                }
+       } else {
+               result->lock = NULL;
        }
        result->locktype = locktype;
        result->count = 0;
index 64cfc7e1c6b4b1627fc0f651a52f619331d736b7..b84e08d06598385185b55c45081745dae6705064 100644 (file)
@@ -66,13 +66,13 @@ dummy_cb(struct event_overlapped *o, uintptr_t key, ev_ssize_t n, int ok)
        struct dummy_overlapped *d_o =
            EVUTIL_UPCAST(o, struct dummy_overlapped, eo);
 
-       EVLOCK_LOCK(d_o->lock, EVTHREAD_WRITE);
+       EVLOCK_LOCK(d_o->lock, 0);
        if (d_o->call_count < MAX_CALLS) {
                d_o->keys[d_o->call_count] = key;
                d_o->sizes[d_o->call_count] = n;
        }
        d_o->call_count++;
-       EVLOCK_UNLOCK(d_o->lock, EVTHREAD_WRITE);
+       EVLOCK_UNLOCK(d_o->lock, 0);
 }
 
 static int
@@ -80,14 +80,14 @@ pair_is_in(struct dummy_overlapped *o, uintptr_t key, ev_ssize_t n)
 {
        int i;
        int result = 0;
-       EVLOCK_LOCK(o->lock, EVTHREAD_WRITE);
+       EVLOCK_LOCK(o->lock, 0);
        for (i=0; i < o->call_count; ++i) {
                if (o->keys[i] == key && o->sizes[i] == n) {
                        result = 1;
                        break;
                }
        }
-       EVLOCK_UNLOCK(o->lock, EVTHREAD_WRITE);
+       EVLOCK_UNLOCK(o->lock, 0);
        return result;
 }
 
@@ -97,9 +97,6 @@ test_iocp_port(void *ptr)
        struct event_iocp_port *port = NULL;
        struct dummy_overlapped o1, o2;
 
-#ifdef WIN32
-       evthread_use_windows_threads();
-#endif
        memset(&o1, 0, sizeof(o1));
        memset(&o2, 0, sizeof(o2));
 
@@ -186,10 +183,6 @@ test_iocp_evbuffer(void *ptr)
        event_overlapped_init(&rol, read_complete);
        event_overlapped_init(&wol, write_complete);
 
-#ifdef WIN32
-       evthread_use_windows_threads();
-#endif
-
        for (i = 0; i < sizeof(junk); ++i)
                junk[i] = (char)(i);
 
@@ -238,11 +231,6 @@ test_iocp_bufferevent_async(void *ptr)
        size_t n;
        struct timeval one_sec = {1,0};
 
-
-#ifdef WIN32
-       evthread_use_windows_threads();
-#endif
-
        event_base_start_iocp(data->base);
        port = event_base_get_iocp(data->base);
        tt_assert(port);
@@ -274,10 +262,12 @@ end:
 
 
 struct testcase_t iocp_testcases[] = {
-       { "port", test_iocp_port, TT_FORK, NULL, NULL },
-       { "evbuffer", test_iocp_evbuffer, TT_FORK|TT_NEED_SOCKETPAIR,
+       { "port", test_iocp_port, TT_FORK|TT_NEED_THREADS, NULL, NULL },
+       { "evbuffer", test_iocp_evbuffer,
+         TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_THREADS,
          &basic_setup, NULL },
        { "bufferevent_async", test_iocp_bufferevent_async,
-         TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE, &basic_setup, NULL },
+         TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_THREADS|TT_NEED_BASE,
+         &basic_setup, NULL },
        END_OF_TESTCASES
 };