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 

[RESOLVED] Threads and Modules

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



Joined: 29 Aug 2008
Posts: 16

PostPosted: Sun Dec 28, 2008 4:37 am    Post subject: [RESOLVED] Threads and Modules Reply with quote

Hello All !

So, I've got a little problem in my code, here it is (this is not the entire code) :

Code:
int main(int args, char** argv)
{

   .....

   DisplayThread = sceKernelCreateThread("...", Display_Thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL);
   sceKernelStartThread(DisplayThread, 0, 0);
   
   int i;
   
   while(1)
   {
      Ctrl(); //Control
   }

        return 0;
}

void Ctrl()
{
         if (pad.Buttons & SelectKey && !(oldPad.Buttons & SelectKey))
   {
                   ....
                  sceKernelStartModule(usbcam,
                  strlen("ms0:/usbCam.prx")+1,"ms0:/UsbCam.prx", NULL, NULL);

      sceKernelSuspendThread(DisplayThread); //I suspend my display thread to blit my module correctly
        }
         
       if (pad.Buttons & CancelKey && !(oldPad.Buttons & CancelKey))
   {
                   ....
                  sceKernelStopModule(usbcam,strlen("ms0:/usbCam.prx")+1,"ms0:/UsbCam.prx", NULL, NULL);

       sceKernelResumeThread(DisplayThread); // Now I can Resume my Thread
        }

        ... //Other controls ...



The problem is : before I start my module the controls work perfectly. Then I start my module, and when I press Circle, the module is stopped and I resume my display thread. The thread re-appear on the screen normally, but this time the controls don't work :(

I don't know if I'm very clear ^^ In fact, as soon as I stop the module, the controls don't work.

Thanks in advance :p

PS:Sorry for my bad English
_________________
Excuse me for my English, I'm French.


Last edited by BigProMaN on Tue Jan 06, 2009 3:04 am; edited 1 time in total
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Sun Dec 28, 2008 4:59 am    Post subject: Reply with quote

mmm... I can't see a little sceCtrl call...
Are you reading control buffers in the "entire" code?
_________________
Get Xplora!
Back to top
View user's profile Send private message
BigProMaN



Joined: 29 Aug 2008
Posts: 16

PostPosted: Sun Dec 28, 2008 8:04 am    Post subject: Reply with quote

Oh Yes, I forgot this function.
sceCtrlReadBufferPositive(&pad,1) is called in Ctrl();
_________________
Excuse me for my English, I'm French.
Back to top
View user's profile Send private message
cosmito



Joined: 04 Mar 2007
Posts: 314
Location: Portugal

PostPosted: Sun Dec 28, 2008 8:08 am    Post subject: Re: Threads and Modules Reply with quote

BigProMaN wrote:
PS:Sorry for my bad English
_________________
Excuse me for my English, I'm French.

Why everyone nowadays seems to be sorry about their english?! Is it so important really to have a *perfect* english?
His text seems perfectly understandable...
(sorry for the off-topic comment, but sometimes this matter p*ss me off...)
Back to top
View user's profile Send private message Visit poster's website
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sun Dec 28, 2008 11:04 am    Post subject: Re: Threads and Modules Reply with quote

cosmito wrote:
BigProMaN wrote:
PS:Sorry for my bad English
_________________
Excuse me for my English, I'm French.

Why everyone nowadays seems to be sorry about their english?! Is it so important really to have a *perfect* english?
His text seems perfectly understandable...
(sorry for the off-topic comment, but sometimes this matter p*ss me off...)


They're just worried they'll be mistaken for a stupid American... which is a valid concern. I once submitted a review of some fanfiction where I suggested the author try to get someone who spoke/wrote English natively to help him with his writing as I assumed his truly dreadful English was the result of trying to use the truly dreadful language translation sites out. The guy wrote me back a blistering email that was 99% vulgarities because I had apparently insulting his writing skills - turns out, he wasn't a foreigner using bad translation software, he was 100% US citizen... in fact, he claimed to be a college student working on a Masters in English writing! Whoopsie! Considering he wrote below a third grade level with atrocious grammar and spelling, I could only hope he was lying about being an English student at a major university.

So if someone apologies for their English, claiming to be foreign, I just tell them it's fine, that their English is much better than my <whatever language> and leave it at that. :D
Back to top
View user's profile Send private message AIM Address
BigProMaN



Joined: 29 Aug 2008
Posts: 16

PostPosted: Sun Dec 28, 2008 8:53 pm    Post subject: Reply with quote

Excuse me cosmito ... I forgot that my signature was already "Excuse me for my bad English" ^^

Has anybody got the solution ?
_________________
Excuse me for my English, I'm French.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Mon Dec 29, 2008 10:08 am    Post subject: Reply with quote

What kind of waiting are you doing in the Ctrl function? Your while loop simply calls Ctrl over and over, so if Ctrl isn't doing any waiting, nothing but Ctrl is running. The PSP uses coop multitasking, so only one thing runs until you call something that allows others to run. You'd want something like an sceKernelDelayThread(33333); in the loop somewhere so that other threads can run.
Back to top
View user's profile Send private message AIM Address
Smong



Joined: 04 Sep 2007
Posts: 82

PostPosted: Mon Jan 05, 2009 6:41 am    Post subject: Reply with quote

I think sceCtrlReadBufferPositive does allow other threads to run. While sceCtrlPeekBufferPositive does not.
_________________
(+[__]%)
Back to top
View user's profile Send private message
NoEffex



Joined: 27 Nov 2008
Posts: 108

PostPosted: Mon Jan 05, 2009 1:25 pm    Post subject: Reply with quote

Smong wrote:
I think sceCtrlReadBufferPositive does allow other threads to run. While sceCtrlPeekBufferPositive does not.
Nah, I use peekbuffer and it lets the other threads run fine.
_________________
Programming with:
Geany + Latest PSPSDK from svn
Back to top
View user's profile Send private message
Smong



Joined: 04 Sep 2007
Posts: 82

PostPosted: Mon Jan 05, 2009 5:50 pm    Post subject: Reply with quote

In that case I may have to double check it. Is that the only firmware function you are calling from your mainloop? Some other function may be allowing threads to get a chance at running.
_________________
(+[__]%)
Back to top
View user's profile Send private message
BigProMaN



Joined: 29 Aug 2008
Posts: 16

PostPosted: Tue Jan 06, 2009 3:03 am    Post subject: Reply with quote

Finnally the problem is revolved ...
I had to call pspSdkLoadStartModule when I press X, and call sceKernelSelfStopUnloadModule directly in the module loaded to stop/unload it :)
_________________
Excuse me for my English, I'm French.
Back to top
View user's profile Send private message
Smong



Joined: 04 Sep 2007
Posts: 82

PostPosted: Tue Jan 06, 2009 10:26 am    Post subject: Reply with quote

NoEffex wrote:
Smong wrote:
I think sceCtrlReadBufferPositive does allow other threads to run. While sceCtrlPeekBufferPositive does not.
Nah, I use peekbuffer and it lets the other threads run fine.

Smong wrote:
In that case I may have to double check it.

I double checked by calling sceCtrlPeekBufferPositive 1mil times while a 2nd thread was in the ready state and the 2nd thread never got a chance to run. And just to make sure I repeated the test with sceCtrlReadBufferPositive which did let the 2nd thread run. So I will assume you are calling other firmware functions, at least one of which does having a blocking behaviour.
_________________
(+[__]%)
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