forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Callback - Multi threading - Help Please

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
r3v3rb



Joined: 02 Jul 2005
Posts: 6

PostPosted: Thu Jul 14, 2005 7:19 pm    Post subject: Callback - Multi threading - Help Please Reply with quote

I am trying to setup the controller to change some mod (music files) that i have playing over a little demo i am creating, but if the code runs in the main thread then the whole thing stops whilst the new track is called in to play.

So i have tried setting this process up as a seperate thread, the only issue i seem to be having is that after a short period it stops working and no button presses get parsed, at the very start of the program the callback works reasonably well, still pauses slighty but not as ugly. Below is the call back code i have produced any help would be greatly appreciated::

Code:

void controllertest(void *arg){

ctrl_data_t pad;

sceCtrlReadBufferPositive(&pad, 1);
   
      if(pad.buttons & CTRL_RIGHT){
         ModPlay_Stop();
         ModPlay_Init(0,music2);
         ModPlay_Play();
      }
      if(pad.buttons==CTRL_LEFT){
         ModPlay_Stop();
         ModPlay_Init(0,music3);
         ModPlay_Play();
      }
      if(pad.buttons==CTRL_UP){
         ModPlay_Stop();
         ModPlay_Init(0,music4);
         ModPlay_Play();
      }
      if(pad.buttons==CTRL_DOWN){
         ModPlay_Stop();
         ModPlay_Init(0,music5);
         ModPlay_Play();
      }
      else
      {
      pgPrint(0,0,0xffff,"Now Playing :: ",0,255);
      }
}

int setupcontroller(void){

int thrd = 0;

thrd = sceKernelCreateThread("audio_thread", controllertest, 0x11, 0xFA0, 0, 0);

if(thrd>=0)
sceKernelStartThread(thrd,0,0);
return thrd;
}


I am not sure of the arguments 0x11 and 0xFA could they be conflicting with the same args in the home button callback as the program fails to quit properly as well when this call back has been implemented.

regards,

r3v3rb
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Fri Jul 15, 2005 2:07 am    Post subject: Reply with quote

Set 0x11 to sommit like 0x12 and it should work, or at the very least call sceDisplayWaitVblankStart to put your test thread into a wait state, otherwise the callback thread cannot preempt the currently running thread and thus never gets called.
Back to top
View user's profile Send private message
r3v3rb



Joined: 02 Jul 2005
Posts: 6

PostPosted: Fri Jul 15, 2005 3:18 am    Post subject: Reply with quote

thank you tyranid, tried to catch you on efnet the other day for this but missed you. I have done the 0x12 already and its still plays about so now its time for the sceDisplayWaitVBlankStart, I'm guessing that this needs to go with the main program part and not in the thread ? or is it round the other way ?
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Fri Jul 15, 2005 3:46 am    Post subject: Reply with quote

Hmmlooking at your code again you you don't actually loop in that thread so it must be dropping out of it again. What does the rest of your code do? i.e. the put after you call setup controller ?
Back to top
View user's profile Send private message
r3v3rb



Joined: 02 Jul 2005
Posts: 6

PostPosted: Fri Jul 15, 2005 5:35 am    Post subject: Reply with quote

the bit before and after the setupcontroller function loops round forever. It's wierd though even by altering to 0x12 it screws the home button callback. PSP goes to 'Please Wait' and then just sits there, the music continues to play but then nothing happens. I have to physically turn off he psp...
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Fri Jul 15, 2005 5:43 am    Post subject: Reply with quote

Well it will do :) Setting 0x12 only works for the thread you created, once it drops out of the thread at the end of the function is it cleaned up anyway so it doesn't make a difference. Either in your main thread (the thing which created the thread as is running in an infinite loop) call either sceKernelSleepThread() or sceKernelExitDeleteThread(0) to stop it or sceDisplayWaitVblankStart if you are still doing stuff in the loop.

Although if you main thread is of a low enough prioroty the callback should just work but it is best to try, though without the code it is hard to tell what is wrong.
Back to top
View user's profile Send private message
r3v3rb



Joined: 02 Jul 2005
Posts: 6

PostPosted: Fri Jul 15, 2005 5:50 am    Post subject: Reply with quote

Well, i took out the thread setup from the code and put it back to a straight function call from within the main program loop. Lo and behold, the audio changes, the home button works properly but I get a horrendous pause whilst it inits the music files. So i can either leave like this which is crap or something is wrong with this

Code:
void setupcontroller(void){

int thrd = 0;

thrd = sceKernelCreateThread("audio_thread", controllertest, 0x12, 0xFA0, 0, 0);

if(thrd>=0)
sceKernelStartThread(thrd,0,0);
return thrd;

}


or the way I am implementing the thread is wrong. sceDisplayWaitVBlankStart gave errors when compiling...

Or I need a way to load data into memory during the loop and not have it init until all data is ready to be dealt with... any ideas ?
Back to top
View user's profile Send private message
r3v3rb



Joined: 02 Jul 2005
Posts: 6

PostPosted: Fri Jul 15, 2005 7:01 am    Post subject: Reply with quote

success, setting the thread to loop and removing the call from the main loop has the program running without too many hitches, just the modplay_init pauses to try and suss now.

Many thanks TyRaNID !! :D
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group