| View previous topic :: View next topic |
| Author |
Message |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Fri Nov 23, 2007 1:59 am Post subject: Thread calling function from class problem |
|
|
Hi folks,
I am trying to create a simple loadingscreen function. I do it with the sceKernelCreateThread function which create the loading sequence rendering code while the main thread remains loading up models/pictures/variable/files etc....
anyway... that was the idea :) As in the past I have some problem regarding function pointers and the like.
The second parameter of the function sceKernelCreateThread is pointer to a function. I try to do it like this:
| Code: |
LoadingScreen::LoadingScreen() {
// the loadingscreen is loaded
thid_ = sceKernelCreateThread("LoadingThread", this->RunLoadingScreen(), 0x18, 0x10000, 0, NULL);
}
void LoadingScreen::KillLoadingScreen() {
// shut down the loading screen again.
sceKernelDeleteThread(thid_);
}
void LoadingScreen::RunLoadingScreen() {
while(1) {
// render loading screen
}
} |
Now calling this function returns an error with compiling.
| Code: |
oadingScreen.cpp: In constructor 'LoadingScreen::LoadingScreen()':
LoadingScreen.cpp:6: error: invalid use of void expression
|
I remember from before that there is a way of using pointers to functions from classes but I do not know anymore how exactly and I could not find it with google :(
Hope you guys can shed some light on it !
greets Ghoti _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Fri Nov 23, 2007 2:21 am Post subject: Re: Thread calling function from class problem |
|
|
| Ghoti wrote: |
| Code: |
thid_ = sceKernelCreateThread("LoadingThread", this->RunLoadingScreen(), 0x18, 0x10000, 0, NULL);
|
|
What this line does is call this->RunLoadingScreen() and try to submit its return value (which is void) as the second parameter to sceKernelCreateThread.
What you want to do is this:
| Code: |
thid_ = sceKernelCreateThread("LoadingThread", RunLoadingScreen, 0x18, 0x10000, 0, NULL);
|
_________________ <Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki
Alexander Berl |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Fri Nov 23, 2007 2:36 am Post subject: |
|
|
Hi thanks!
you are right but I also had to change the function to a static and like this:
| Code: | int LoadingScreen::RunLoadingScreen(SceSize args, void *argp) {
|
but what I do not understand is why, why does it need the args and argp? why does it have to be an int as return value ? I really want to understand it before I will use it for whatever.
greets ghoti
EDIT::EDIT
Is there a non kernel function for creating and using thread by the way ? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Cpasjuste
Joined: 29 May 2005 Posts: 214
|
Posted: Fri Nov 23, 2007 2:42 am Post subject: |
|
|
| You can create and start threads in user mode the same way! |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Fri Nov 23, 2007 2:45 am Post subject: |
|
|
| Ghoti wrote: |
but what I do not understand is why, why does it need the args and argp? why does it have to be an int as return value ?
|
Because that's the definition of a thread entry function, same as the main program entry function main( ... ).
| Quote: |
Is there a non kernel function for creating and using thread by the way ? |
sceKernelCreateThread is actually a user function. Just because it starts with sceKernel doesn't mean the function only works in kernel mode.
See the header files in pspsdk\src\user _________________ <Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki
Alexander Berl |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Fri Nov 23, 2007 2:51 am Post subject: |
|
|
| Raphael wrote: | | Ghoti wrote: |
but what I do not understand is why, why does it need the args and argp? why does it have to be an int as return value ?
|
Because that's the definition of a thread entry function, same as the main program entry function main( ... ).
| Quote: |
Is there a non kernel function for creating and using thread by the way ? |
sceKernelCreateThread is actually a user function. Just because it starts with sceKernel doesn't mean the function only works in kernel mode.
See the header files in pspsdk\src\user |
Yes your right about the main function :) forgot about that, for the PSP I always just pass void to the main function.
I yes I should have found that in the header files, I just assumed without checking if there is kernel in the name it is a kernel function :s will not do that anymore :D _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Fri Nov 23, 2007 3:58 am Post subject: |
|
|
The reason it needs to be static is due to C++ calling conventions. There are some tricks you can do to fudge it but normally best to do something akin to:
| Code: | class MyClass
{
public:
static int ThreadEntry(int args, void *argp) {
MyClass *this = *((MyClass **) argp;
this->RunLoadingScreen();
return 0;
}
}
MyClass* p = new MyClass;
uid = sceKernelCreateThread("MyClassThread", MyClass::ThreadEntry, ...);
sceKernelStartThread(uid, sizeof(p), &p);
|
|
|
| Back to top |
|
 |
pspZorba
Joined: 22 Sep 2007 Posts: 156 Location: NY
|
Posted: Fri Dec 14, 2007 8:27 am Post subject: |
|
|
Does it mean that the real signature of a thread entry is :
int threadEntry( int argc, void *argv[] )
rather than
int threadEntry( int argc, void *argv ) _________________ --pspZorba--
NO to K1.5 ! |
|
| Back to top |
|
 |
pspZorba
Joined: 22 Sep 2007 Posts: 156 Location: NY
|
Posted: Fri Dec 14, 2007 8:33 am Post subject: |
|
|
froget about the question.
I understood my mistake _________________ --pspZorba--
NO to K1.5 ! |
|
| Back to top |
|
 |
|