@@ -39,7 +39,9 @@
#include "qemu/bitmap.h"
#include "qemu/seqlock.h"
-#ifndef _WIN32
+#ifdef _WIN32
+#include "qemu/winapi.h" /* SuspendThread, ... */
+#else
#include "qemu/compatfd.h"
#endif
@@ -16,12 +16,13 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>
*/
-#include "qemu/thread.h"
+
#include "hw/i386/apic_internal.h"
#include "hw/i386/apic.h"
#include "hw/i386/ioapic.h"
#include "hw/pci/msi.h"
#include "qemu/host-utils.h"
+#include "qemu/thread.h"
#include "trace.h"
#include "hw/i386/pc.h"
#include "hw/i386/apic-msidef.h"
@@ -15,13 +15,9 @@
#include "qemu-common.h"
-#ifdef _WIN32
-#include "qemu/winapi.h"
-#endif
-
struct EventNotifier {
#ifdef _WIN32
- HANDLE event;
+ WinHandle event;
#else
int rfd;
int wfd;
@@ -40,7 +36,7 @@ int event_notifier_set_handler(EventNotifier *, EventNotifierHandler *);
void event_notifier_init_fd(EventNotifier *, int fd);
int event_notifier_get_fd(EventNotifier *);
#else
-HANDLE event_notifier_get_handle(EventNotifier *);
+WinHandle event_notifier_get_handle(EventNotifier *);
#endif
#endif
@@ -152,7 +152,7 @@ typedef void WaitObjectFunc(void *opaque);
* @func: A function to be called when @handle is in a signaled state.
* @opaque: A pointer-size value that is passed to @func.
*/
-int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+int qemu_add_wait_object(WinHandle handle, WaitObjectFunc *func, void *opaque);
/**
* qemu_del_wait_object: Unregister a callback for a Windows handle
@@ -163,7 +163,7 @@ int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
* @func: The function that was passed to qemu_add_wait_object.
* @opaque: A pointer-size value that was passed to qemu_add_wait_object.
*/
-void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+void qemu_del_wait_object(WinHandle handle, WaitObjectFunc *func, void *opaque);
#endif
/* async I/O support */
@@ -1,24 +1,35 @@
#ifndef __QEMU_THREAD_WIN32_H
#define __QEMU_THREAD_WIN32_H 1
-#include "qemu/winapi.h"
+
+/* WinCriticalSection is a substitute for CRITICAL_SECTION and
+ * introduced here to avoid dependencies on windows.h. */
+
+typedef struct {
+ WinHandle DebugInfo;
+ WinLong LockCount;
+ WinLong RecursionCount;
+ WinHandle OwningThread;
+ WinHandle LockSemaphore;
+ WinULong *SpinCount;
+} WinCriticalSection;
struct QemuMutex {
- CRITICAL_SECTION lock;
- LONG owner;
+ WinCriticalSection lock;
+ WinLong owner;
};
struct QemuCond {
- LONG waiters, target;
- HANDLE sema;
- HANDLE continue_event;
+ WinLong waiters, target;
+ WinHandle sema;
+ WinHandle continue_event;
};
struct QemuSemaphore {
- HANDLE sema;
+ WinHandle sema;
};
struct QemuEvent {
- HANDLE event;
+ WinHandle event;
};
typedef struct QemuThreadData QemuThreadData;
@@ -28,6 +39,6 @@ struct QemuThread {
};
/* Only valid for joinable threads. */
-HANDLE qemu_thread_get_handle(QemuThread *thread);
+WinHandle qemu_thread_get_handle(QemuThread *thread);
#endif
@@ -215,7 +215,7 @@ struct CPUState {
struct QemuThread *thread;
#ifdef _WIN32
- HANDLE hThread;
+ WinHandle hThread;
#endif
int thread_id;
uint32_t host_tid;
@@ -54,6 +54,13 @@
# define EWOULDBLOCK WSAEWOULDBLOCK
#endif
+/* Define substitutes for the Win API types HANDLE, LONG, ULONG.
+ * These types are used to avoid dependencies on windows.h. */
+
+typedef void * WinHandle;
+typedef long WinLong;
+typedef unsigned long WinULong;
+
#if defined(_WIN64)
/* On w64, setjmp is implemented by _setjmp which needs a second parameter.
* If this parameter is NULL, longjump does no stack unwinding.
@@ -27,11 +27,6 @@
*/
#include "config-host.h"
-
-/* This needs to be before jpeglib.h line because of conflict with
- INT32 definitions between jmorecfg.h (included by jpeglib.h) and
- Win32 basetsd.h (included by windows.h). */
-#include "qemu/winapi.h" /* TODO: workaround, remove */
#include "qemu-common.h"
#ifdef CONFIG_VNC_PNG
@@ -13,6 +13,7 @@
#include "qemu-common.h"
#include "qemu/event_notifier.h"
#include "qemu/main-loop.h"
+#include "qemu/winapi.h" /* CreateEvent, ... */
int event_notifier_init(EventNotifier *e, int active)
{
@@ -10,11 +10,10 @@
* See the COPYING file in the top-level directory.
*
*/
+
+#include "qemu/winapi.h" /* LocalFree, ... */
#include "qemu-common.h"
#include "qemu/thread.h"
-#include <process.h>
-#include <assert.h>
-#include <limits.h>
static bool name_threads;
@@ -38,18 +37,20 @@ static void error_exit(int err, const char *msg)
void qemu_mutex_init(QemuMutex *mutex)
{
mutex->owner = 0;
- InitializeCriticalSection(&mutex->lock);
+ /* mutex->lock uses a data type which must fit CRITICAL_SECTION. */
+ g_assert(sizeof(mutex->lock) == sizeof(CRITICAL_SECTION));
+ InitializeCriticalSection((CRITICAL_SECTION *)&mutex->lock);
}
void qemu_mutex_destroy(QemuMutex *mutex)
{
assert(mutex->owner == 0);
- DeleteCriticalSection(&mutex->lock);
+ DeleteCriticalSection((CRITICAL_SECTION *)&mutex->lock);
}
void qemu_mutex_lock(QemuMutex *mutex)
{
- EnterCriticalSection(&mutex->lock);
+ EnterCriticalSection((CRITICAL_SECTION *)&mutex->lock);
/* Win32 CRITICAL_SECTIONs are recursive. Assert that we're not
* using them as such.
@@ -62,7 +63,7 @@ int qemu_mutex_trylock(QemuMutex *mutex)
{
int owned;
- owned = TryEnterCriticalSection(&mutex->lock);
+ owned = TryEnterCriticalSection((CRITICAL_SECTION *)&mutex->lock);
if (owned) {
assert(mutex->owner == 0);
mutex->owner = GetCurrentThreadId();
@@ -74,7 +75,7 @@ void qemu_mutex_unlock(QemuMutex *mutex)
{
assert(mutex->owner == GetCurrentThreadId());
mutex->owner = 0;
- LeaveCriticalSection(&mutex->lock);
+ LeaveCriticalSection((CRITICAL_SECTION *)&mutex->lock);
}
void qemu_cond_init(QemuCond *cond)