]> git.proxmox.com Git - qemu.git/blobdiff - os-win32.c
Use glib memory allocation and free functions
[qemu.git] / os-win32.c
index 566d5e985352467b250396e0236a20e0647af2b0..d3cea42a50e5d6f3e2a3e6555b2579e97279ed57 100644 (file)
@@ -41,7 +41,7 @@ int setenv(const char *name, const char *value, int overwrite)
     int result = 0;
     if (overwrite || !getenv(name)) {
         size_t length = strlen(name) + strlen(value) + 2;
-        char *string = qemu_malloc(length);
+        char *string = g_malloc(length);
         snprintf(string, length, "%s=%s", name, value);
         result = putenv(string);
     }
@@ -62,7 +62,7 @@ static PollingEntry *first_polling_entry;
 int qemu_add_polling_cb(PollingFunc *func, void *opaque)
 {
     PollingEntry **ppe, *pe;
-    pe = qemu_mallocz(sizeof(PollingEntry));
+    pe = g_malloc0(sizeof(PollingEntry));
     pe->func = func;
     pe->opaque = opaque;
     for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next);
@@ -77,7 +77,7 @@ void qemu_del_polling_cb(PollingFunc *func, void *opaque)
         pe = *ppe;
         if (pe->func == func && pe->opaque == opaque) {
             *ppe = pe->next;
-            qemu_free(pe);
+            g_free(pe);
             break;
         }
     }
@@ -140,7 +140,9 @@ void os_host_main_loop_wait(int *timeout)
         int err;
         WaitObjects *w = &wait_objects;
 
+        qemu_mutex_unlock_iothread();
         ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout);
+        qemu_mutex_lock_iothread();
         if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) {
             if (w->func[ret - WAIT_OBJECT_0])
                 w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]);
@@ -180,7 +182,7 @@ void os_setup_early_signal_handling(void)
     /* Note: cpu_interrupt() is currently not SMP safe, so we force
        QEMU to run on a single CPU */
     HANDLE h;
-    DWORD mask, smask;
+    DWORD_PTR mask, smask;
     int i;
 
     SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
@@ -216,7 +218,7 @@ char *os_find_datadir(const char *argv0)
         p--;
     *p = 0;
     if (access(buf, R_OK) == 0) {
-        return qemu_strdup(buf);
+        return g_strdup(buf);
     }
     return NULL;
 }
@@ -256,7 +258,7 @@ int qemu_create_pidfile(const char *filename)
     if (file == INVALID_HANDLE_VALUE) {
         return -1;
     }
-    len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
+    len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid());
     ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
                      &overlap, NULL);
     if (ret == 0) {
@@ -264,3 +266,8 @@ int qemu_create_pidfile(const char *filename)
     }
     return 0;
 }
+
+int qemu_get_thread_id(void)
+{
+    return GetCurrentThreadId();
+}