summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorzuxy <zuxy@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-11-11 08:14:57 +0000
committerzuxy <zuxy@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-11-11 08:14:57 +0000
commit87db049a8320893f7b8b499e27a9d1b9150addb3 (patch)
tree6c566310f103ebee62e727319cac5afa9475f61c /gui
parent97e52ed6fdc62094707ba08901324fcf30a27b06 (diff)
downloadmpv-87db049a8320893f7b8b499e27a9d1b9150addb3.tar.bz2
mpv-87db049a8320893f7b8b499e27a9d1b9150addb3.tar.xz
Better handling of win32 GUI thread:
1. Use _beginthreadex to create the GUI thread to avoid possible memory leak when linked to MS CRT. 2. Terminate the GUI thread in an cleaner way using PostThreadMessage() rather than the unrecommended TerminateThread(). git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@25020 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'gui')
-rw-r--r--gui/win32/interface.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/gui/win32/interface.c b/gui/win32/interface.c
index 3583b4c73f..d877206620 100644
--- a/gui/win32/interface.c
+++ b/gui/win32/interface.c
@@ -59,6 +59,8 @@ static gui_t *mygui = NULL;
static int update_subwindow(void);
static RECT old_rect;
static DWORD style;
+static HANDLE hThread;
+static unsigned threadId;
ao_functions_t *audio_out = NULL;
vo_functions_t *video_out = NULL;
mixer_t *mixer = NULL;
@@ -459,7 +461,7 @@ void mplFullScreen( void )
if(sub_window) ShowWindow(mygui->subwindow, SW_SHOW);
}
-static DWORD WINAPI GuiThread(void)
+static unsigned __stdcall GuiThread(void* param)
{
MSG msg;
@@ -473,9 +475,8 @@ static DWORD WINAPI GuiThread(void)
gtkAutoSync = autosync;
}
- while(mygui)
+ while(GetMessage(&msg, NULL, 0, 0))
{
- GetMessage(&msg, NULL, 0, 0);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
@@ -486,12 +487,11 @@ static DWORD WINAPI GuiThread(void)
void guiInit(void)
{
- DWORD threadId;
memset(&guiIntfStruct, 0, sizeof(guiIntfStruct));
/* Create The gui thread */
if (!mygui)
{
- CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) GuiThread, NULL, 0, &threadId);
+ hThread = _beginthreadex(NULL, 0, GuiThread, NULL, 0, &threadId);
mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Creating GUI Thread 0x%04x\n", threadId);
}
@@ -506,9 +506,11 @@ void guiDone(void)
{
fprintf(stderr, "[GUI] Closed by main mplayer window\n");
fflush(stderr);
+ PostThreadMessage(threadId, WM_QUIT, 0, 0);
+ WaitForSingleObject(hThread, INFINITE);
+ CloseHandle(hThread);
mygui->uninit(mygui);
free(mygui);
- TerminateThread(GuiThread, 0);
mygui = NULL;
}
/* Remove tray icon */