|
sleep() on RISC OS |
|
ksattic (06:02 27/8/2003) john (09:11 27/8/2003) ksattic (14:46 27/8/2003) john (15:48 27/8/2003) ajps (18:15 27/8/2003) ksattic (00:48 28/8/2003) john (18:15 28/8/2003)
|
|
Simon Wilson |
Message #45900, posted by ksattic at 06:02, 27/8/2003 |
Finally, an avatar!
Posts: 1291
|
I need to do some I/O and then sleep a multitasking app for a short while. I don't want to hang the desktop, so how do I do this?
Let's say I click on a button and I enter a buttonClicked() function. I do some I/O and then I need to sleep for a few ms before doing some more I/O. Do I need to preserve some kind of state and re-enter the buttonClicked() function at a later time? I thought about writing a sleep() function that simply calls Wimp_PollIdle, but this wouldn't work as the Wimp_PollIdle is not guaranteed to return with a NULL reason code - and my app could miss a redraw window request.
Any ideas? |
|
[ Log in to reply ] |
|
John D |
Message #45903, posted by john at 09:11, 27/8/2003, in reply to message #45900 |
Member
Posts: 261
|
Write a little library which has a poll and a pollidle call, as well as a getmessage call and amke it so it remembers the codes from poll and pollidle so that you can get them with getmessage, off the top of my head. Of course you'll have all the ptoblems with user_messages which have to be dealt with immediately and redraw requests which have to be getrectangle-d before the next poll. You could always just write your program to use wimp2, because these problems have been addressed there. Anyway, just a thought, not a definite answer, but I hope it's useful anyway. |
|
[ Log in to reply ] |
|
Simon Wilson |
Message #45910, posted by ksattic at 14:46, 27/8/2003, in reply to message #45903 |
Finally, an avatar!
Posts: 1291
|
Is there a more elegant way to do it? I could probably put the code that needs to sleep() inside a thread, but then I'd need the pthreads library, which I don't think is ready yet. :-( I can't use Wimp2 as my application needs to be 32 bit compatible. |
|
[ Log in to reply ] |
|
John D |
Message #45911, posted by john at 15:48, 27/8/2003, in reply to message #45910 |
Member
Posts: 261
|
You coud just set a flag and do it your way, return to your main loop and if the flag's set you go into your buttonpressed_continued() or whatever unless the're something more pressing come in (message_quit or whatever) That would be the most obvious, even if not so nice for some perspectives. |
|
[ Log in to reply ] |
|
Antony Sidwell |
Message #45918, posted by ajps at 18:15, 27/8/2003, in reply to message #45900 |
Member
Posts: 48
|
There's no hugely elegant way that I know of.
Simplest is to do your first chunk of I/O, then call your main poll routine from inside the buttonClicked function until the time has elapsed, then do your next bit of I/O.
This does require some fiddling about to make sure your poll routine copes correctly with being called from more than one place. You might also have to guard against re-entrancy into your buttonClicked function. It's quit possible though. |
|
[ Log in to reply ] |
|
Simon Wilson |
Message #45927, posted by ksattic at 00:48, 28/8/2003, in reply to message #45918 |
Finally, an avatar!
Posts: 1291
|
What about a yield(int centiseconds) function that calls Wimp_PollIdle with a time of OS_ReadMonotonicTime+centiseconds and a mask that will queue events (0xe3972)?
It seems to work, but I've not tested it extensively. |
|
[ Log in to reply ] |
|
John D |
Message #45946, posted by john at 18:15, 28/8/2003, in reply to message #45927 |
Member
Posts: 261
|
If everything that isn't masked out is handled appropriately then yes, although you might get control back early if the event isn't a null. |
|
[ Log in to reply ] |
|
|