Skip to content

Commit e92e6b2

Browse files
committed
Buildfix #2 for PS2
1 parent cea3f5a commit e92e6b2

File tree

1 file changed

+31
-36
lines changed
  • libretro/libretro-common/libco

1 file changed

+31
-36
lines changed

libretro/libretro-common/libco/ps2.c

+31-36
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,48 @@
1111
static int32_t active_thread_id = -1;
1212
extern void *_gp;
1313

14-
cothread_t co_active()
14+
cothread_t co_active(void)
1515
{
16-
active_thread_id = GetThreadId();
17-
return &active_thread_id;
16+
active_thread_id = GetThreadId();
17+
return &active_thread_id;
1818
}
1919

2020
cothread_t co_create(unsigned int size, void (*entrypoint)(void))
2121
{
22-
/* Similar scenario as with active_thread_id except there will only be one active_thread_id while there could be many
23-
* new threads each with their own handle, so we create them on the heap instead and delete them manually when they're
24-
* no longer needed in co_delete().
25-
*/
26-
cothread_t handle = malloc(sizeof(cothread_t));
27-
ee_thread_t thread;
28-
29-
// u8 threadStack[size/8] __attribute__ ((aligned(16)));
30-
void *threadStack = (void *)malloc(size);
31-
32-
if ( threadStack== NULL)
33-
{
34-
return(-1);
35-
}
36-
37-
thread.stack_size = size;
38-
thread.gp_reg = &_gp;
39-
thread.func = (void *)entrypoint;
40-
thread.stack = threadStack;
41-
thread.option = 0;
42-
thread.initial_priority = 1;
43-
44-
int32_t new_thread_id = CreateThread(&thread);
45-
46-
StartThread(new_thread_id, NULL);
47-
*(uint32_t *)handle = new_thread_id;
48-
return handle;
22+
/* Similar scenario as with active_thread_id except there will only be one active_thread_id while there could be many
23+
* new threads each with their own handle, so we create them on the heap instead and delete them manually when they're
24+
* no longer needed in co_delete().
25+
*/
26+
ee_thread_t thread;
27+
cothread_t handle = malloc(sizeof(cothread_t));
28+
void *threadStack = (void *)malloc(size);
29+
if (!threadStack)
30+
return NULL;
31+
32+
thread.stack_size = size;
33+
thread.gp_reg = &_gp;
34+
thread.func = (void *)entrypoint;
35+
thread.stack = threadStack;
36+
thread.option = 0;
37+
thread.initial_priority = 1;
38+
39+
int32_t new_thread_id = CreateThread(&thread);
40+
41+
StartThread(new_thread_id, NULL);
42+
*(uint32_t *)handle = new_thread_id;
43+
return handle;
4944
}
5045

5146
void co_delete(cothread_t handle)
5247
{
53-
TerminateThread(*(uint32_t *)handle);
54-
DeleteThread(*(uint32_t *)handle);
55-
free(handle);
48+
TerminateThread(*(uint32_t *)handle);
49+
DeleteThread(*(uint32_t *)handle);
50+
free(handle);
5651
}
5752

5853
void co_switch(cothread_t handle)
5954
{
60-
WakeupThread(*(uint32_t *)handle);
61-
/* Sleep the currently active thread so the new thread can start */
62-
SleepThread();
55+
WakeupThread(*(uint32_t *)handle);
56+
/* Sleep the currently active thread so the new thread can start */
57+
SleepThread();
6358
}

0 commit comments

Comments
 (0)