- Package:
- mingw-w64-i686-dev
- Source:
- mingw-w64
- Submitter:
- Bill Allombert
- Date:
- 2014-06-17 11:21:08 UTC
- Severity:
- wishlist
Package: mingw-w64-i686-dev Version: 3.1.0-1 Severity: wishlist Hello Stephen, It would be nice if mingw would provide alarm. Maybe it kinda does actually: /usr/i686-w64-mingw32/include/io.h:unsigned int alarm(unsigned int seconds); /usr/i686-w64-mingw32/include/signal.h:#define SIGALRM 14 /* alarm clock */ but it does not seem to work (at least under wine) and alarm is supposed to be in unistd.h. There is a lot of confusion on the web wheter mingw support alarm, whether it is implemented as a noop, why it is in io.h, etc. Some clarification would be very welcome. Cheers,
Hi Bill,
It is implemented as a noop; in mingw-w64-crt/misc/alarm.c in the mingw-w64
source code:
unsigned int alarm(unsigned int __UNUSED_PARAM(seconds))
{
return 0;
}
I'll forward your request upstream!
Regards,
Stephen
Hello Stephen, thanks again for your answer. Is there a clear documentation of the mingw API ? (at least the difference between mingw and POSIX) Then I would not need to bother you. Thanks, though I understand win32 signal model might not make it easy. Cheers,
The API is "documented" on https://sourceforge.net/apps/trac/mingw-w64/wiki/Mingw-w64%20API%20documentation but very little of the API is described. Yes, I imagine it would have to be emulated using SetTimer but even then producing a signal from the timer function might be difficult... Regards, Stephen
Well I came with the code below.
This works, but of course it should do raise(SIGALRM), but
mingw does not support catching SIGALRM.
static HANDLE hTimerQueue = NULL;
static void CALLBACK
win32_cb_alarm(void *lpParam, BOOLEAN TimerOrWaitFired)
{
raise(SIGINT);
}
void
win32_alarm(unsigned int s)
{
if (hTimerQueue)
{
HANDLE oldhTimerQueue = hTimerQueue;
hTimerQueue = NULL;
DeleteTimerQueue(oldhTimerQueue);
}
if (s)
{
void *arg = NULL;
HANDLE hTimer = NULL;
hTimerQueue = CreateTimerQueue();
CreateTimerQueueTimer( &hTimer, hTimerQueue,
(WAITORTIMERCALLBACK)win32_cb_alarm, &arg , s*1000, 0, 0);
}
}
Cheers,