Calling a function periodically

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
tkondal
Posts: 8
Joined: Thu May 25, 2006 4:00 am

Calling a function periodically

Post by tkondal »

Hi,

I need a function to be called every x milliseconds. I have used the following functions on Windows : SetTimer() and KillTimer().

I looked into the PSPSDK documentation and the only two functions that I found (that I think could do the job) are the following: sceKernelSetAlarm() and sceKernelCancelAlarm().

However, I am not sure how to use these. The documentation does not provide too much information on these. I want to know if these are the appropriate functions to do a periodic call.

I was wondering if anyone has already used these and could point me in the right direction on what parameters to pass (small example).

Thanks.
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

uhm..... why not do a thread with low priority which has something like:

Code: Select all

while(!quit){
sceKernelDelayThread(milliseconds);
my_function();
}
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

I dont know what part of the documentation you say is lacking but in my eyes it makes perfect sense.

i.e. do

Code: Select all

SceUInt alarm_handler(void *common)
{
    // Do something, wont run in a thread so will have to set a semaphore or event flag
}

void set_alarm(void)
{
   SceUID uid;

   // Set an alarm for 1 second in the future
   uid = sceKernelSetAlarm(1000000, alarm_handler, NULL);
}
Post Reply