Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Shayne Fletcher
Glasgow Haskell Compiler
Commits
afe67cb5
Commit
afe67cb5
authored
Mar 20, 2006
by
Simon Marlow
Browse files
stopTicker(): wait for the timer thread to exit
parent
1f5e3b24
Changes
1
Hide whitespace changes
Inline
Side-by-side
ghc/rts/win32/Ticker.c
View file @
afe67cb5
...
...
@@ -8,6 +8,7 @@
#include <windows.h>
#include <stdio.h>
#include <process.h>
#include "OSThreads.h"
/*
* Provide a timer service for the RTS, periodically
...
...
@@ -20,6 +21,7 @@
* signals.)
*/
static
HANDLE
hStopEvent
=
INVALID_HANDLE_VALUE
;
static
HANDLE
tickThread
=
INVALID_HANDLE_VALUE
;
static
TickProc
tickProc
=
NULL
;
...
...
@@ -38,11 +40,13 @@ unsigned
WINAPI
TimerProc
(
PVOID
param
)
{
return
0
;
int
ms
=
(
int
)
param
;
DWORD
waitRes
;
/* interpret a < 0 timeout period as 'instantaneous' */
if
(
ms
<
0
)
ms
=
0
;
/* interpret a < 0 timeout period as 'instantaneous' */
if
(
ms
<
0
)
ms
=
0
;
while
(
1
)
{
waitRes
=
WaitForSingleObject
(
hStopEvent
,
ms
);
...
...
@@ -86,19 +90,37 @@ startTicker(nat ms, TickProc handle_tick)
return
0
;
}
tickProc
=
handle_tick
;
return
(
0
!=
_beginthreadex
(
NULL
,
tickThread
=
(
HANDLE
)(
long
)
_beginthreadex
(
NULL
,
0
,
TimerProc
,
(
LPVOID
)
ms
,
0
,
&
threadId
)
);
&
threadId
);
return
(
tickThread
!=
0
);
}
int
stopTicker
(
void
)
{
if
(
hStopEvent
!=
INVALID_HANDLE_VALUE
)
{
SetEvent
(
hStopEvent
);
}
return
0
;
// We must wait for the ticker thread to terminate, since if we
// are in a DLL that is about to be unloaded, the ticker thread
// cannot be allowed to return to a missing DLL.
if
(
hStopEvent
!=
INVALID_HANDLE_VALUE
&&
tickThread
!=
INVALID_HANDLE_VALUE
)
{
DWORD
exitCode
;
SetEvent
(
hStopEvent
);
while
(
1
)
{
WaitForSingleObject
(
tickThread
,
20
);
if
(
!
GetExitCodeThread
(
tickThread
,
&
exitCode
))
{
return
1
;
}
if
(
exitCode
!=
STILL_ACTIVE
)
{
tickThread
=
INVALID_HANDLE_VALUE
;
return
0
;
}
TerminateThread
(
tickThread
,
0
);
}
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment