+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
-#include <pthread.h>
-#include <check.h>
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
+#ifdef EFL_HAVE_POSIX_THREADS
+# include <pthread.h>
#endif
+#include <check.h>
+
#include <Eina.h>
#include "eet_suite.h"
}
END_TEST
+#ifdef EFL_HAVE_THREADS
+
static Eina_Bool open_worker_stop;
+
+# ifdef EFL_HAVE_POSIX_THREADS
+
static void*
open_close_worker(void* path)
{
pthread_exit(NULL);
}
+# else
+
+static unsigned int __stdcall
+open_close_worker(void *path)
+{
+ while (!open_worker_stop)
+ {
+ Eet_File *ef = eet_open((char const *)path, EET_FILE_MODE_READ);
+ if (ef == NULL)
+ {
+ _endthreadex(-1);
+ }
+ else
+ {
+ Eet_Error err_code = eet_close(ef);
+ if (err_code != EET_ERROR_NONE)
+ _endthreadex(-2);
+ }
+ }
+
+ _endthreadex(0);
+}
+
+# endif
+
START_TEST(eet_cache_concurrency)
{
char *file = strdup("/tmp/eet_suite_testXXXXXX");
Eet_File *ef;
void *thread_ret;
unsigned int n;
+# ifdef EFL_HAVE_POSIX_THREADS
+ pthread_t thread;
+# else
+ uintptr_t thread;
+ unsigned int thread_id;
+ DWORD ret;
+# endif
eet_init();
/* start a thread that repeatedly opens and closes a file */
open_worker_stop = 0;
- pthread_t thread;
+# ifdef EFL_HAVE_POSIX_THREADS
pthread_create(&thread, NULL, open_close_worker, file);
-
+# else
+ thread = _beginthreadex(NULL, 0, open_close_worker, file, 0, &thread_id);
+# endif
/* clear the cache repeatedly in this thread */
for (n = 0; n < 50000; ++n)
{
/* join the other thread, and fail if it returned an error message */
open_worker_stop = 1;
+# ifdef EFL_HAVE_POSIX_THREADS
fail_if(pthread_join(thread, &thread_ret) != 0);
fail_unless(thread_ret == NULL, (char const*)thread_ret);
+# else
+ ret = WaitForSingleObject((HANDLE)thread, INFINITE);
+ fail_if(ret != WAIT_OBJECT_0);
+ fail_if(GetExitCoeThread((HANDLE)thread, &ret) == FALSE);
+ fail_if(ret != 0)
+# endif
fail_if(unlink(file) != 0);
eet_shutdown();
}
END_TEST
+#endif /* EFL_HAVE_THREADS */
+
typedef struct _Eet_Connection_Data Eet_Connection_Data;
struct _Eet_Connection_Data
{
suite_add_tcase(s, tc);
#endif
+#ifdef EFL_HAVE_THREADS
tc = tcase_create("Eet Cache");
tcase_add_test(tc, eet_cache_concurrency);
suite_add_tcase(s, tc);
+#endif
tc = tcase_create("Eet Connection");
tcase_add_test(tc, eet_connection_check);