Add test for WAIT_ABANDONED handling for win32 mutexes. Code works as
expected.
@@ -425,6 +425,45 @@ static void test_thread_unnestedmutex(abts_case *tc, void *data)
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
}
+#ifdef WIN32
+static void *APR_THREAD_FUNC
+thread_win32_abandoned_mutex_function(apr_thread_t *thd, void *data)
+{
+ apr_thread_mutex_t *mutex = data;
+ apr_status_t rv;
+
+ rv = apr_thread_mutex_lock(mutex);
+
+ /* exit from thread without unlocking mutex. */
+ apr_thread_exit(thd, rv);
+}
+
+static void test_win32_abandoned_mutex(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_thread_t *thread;
+ apr_thread_mutex_t *mutex;
+
+ /* Create timed mutex: APR will create Win32 mutex object in this case. */
+ rv = apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_TIMED, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_thread_create(&thread, NULL, thread_win32_abandoned_mutex_function,
+ mutex, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ apr_thread_join(&rv, thread);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_thread_mutex_trylock(mutex);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ rv = apr_thread_mutex_unlock (mutex);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+}
+
+#endif
+
#endif /* !APR_HAS_THREADS */
#if !APR_HAS_THREADS
@@ -450,6 +489,9 @@ abts_suite *testlock(abts_suite *suite)
abts_run_test(suite, test_cond, NULL);
abts_run_test(suite, test_timeoutcond, NULL);
abts_run_test(suite, test_timeoutmutex, NULL);
+#ifdef WIN32
+ abts_run_test(suite, test_win32_abandoned_mutex, NULL);
+#endif
#endif
return suite;
