Removed arguments array for friends/tasks
This commit is contained in:
parent
1be9024704
commit
29e130ace0
|
@ -78,38 +78,39 @@ system_inspect(Uxn *u)
|
||||||
/* Friends */
|
/* Friends */
|
||||||
|
|
||||||
Uint8 *global_ram;
|
Uint8 *global_ram;
|
||||||
Uint16 friends_tasks[0x80];
|
Uint16 friends_tasks[MAX_FRIENDS];
|
||||||
pthread_t friends[0x80];
|
pthread_t friends[MAX_FRIENDS];
|
||||||
int friends_count = 0;
|
int friends_count = 0;
|
||||||
int friends_args[0x80];
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
friend_task(void *x)
|
friend_task(void *vector)
|
||||||
{
|
{
|
||||||
Uxn friend;
|
Uxn friend;
|
||||||
uxn_boot(&friend, global_ram);
|
uxn_boot(&friend, global_ram);
|
||||||
uxn_eval(&friend, friends_tasks[*((int *)x)]);
|
uxn_eval(&friend, *((Uint16 *)vector));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
spawn_friend(Uint16 task)
|
|
||||||
{
|
|
||||||
if(friends_count >= 0x80)
|
|
||||||
return system_error("friends", "Too many threads");
|
|
||||||
friends_args[friends_count] = friends_count;
|
|
||||||
friends_tasks[friends_count] = task;
|
|
||||||
pthread_create(&friends[friends_count], NULL, friend_task, (void *)&friends_args[friends_count]);
|
|
||||||
return friends_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
wait_friends(void)
|
wait_friends(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < friends_count; ++i)
|
for(i = 0; i < friends_count; ++i)
|
||||||
pthread_join(friends[i], NULL);
|
pthread_join(friends[i], NULL);
|
||||||
friends_count = 0;
|
return friends_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
spawn_friend(Uint8 *ram, Uint16 task)
|
||||||
|
{
|
||||||
|
if(!task)
|
||||||
|
return wait_friends();
|
||||||
|
if(friends_count >= MAX_FRIENDS)
|
||||||
|
return system_error("friends", "Too many threads");
|
||||||
|
global_ram = ram;
|
||||||
|
friends_tasks[friends_count] = task;
|
||||||
|
pthread_create(&friends[friends_count], NULL, friend_task, (void *)&friends_tasks[friends_count]);
|
||||||
|
return friends_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* IO */
|
/* IO */
|
||||||
|
@ -117,18 +118,12 @@ wait_friends(void)
|
||||||
void
|
void
|
||||||
system_deo(Uxn *u, Uint8 *d, Uint8 port)
|
system_deo(Uxn *u, Uint8 *d, Uint8 port)
|
||||||
{
|
{
|
||||||
Uint16 v;
|
|
||||||
switch(port) {
|
switch(port) {
|
||||||
case 0x3:
|
case 0x3:
|
||||||
system_cmd(u->ram, PEEK2(d + 2));
|
system_cmd(u->ram, PEEK2(d + 2));
|
||||||
break;
|
break;
|
||||||
case 0x5:
|
case 0x5:
|
||||||
v = PEEK2(d + 4);
|
spawn_friend(u->ram, PEEK2(d + 4));
|
||||||
global_ram = u->ram;
|
|
||||||
if(v)
|
|
||||||
spawn_friend(v);
|
|
||||||
else
|
|
||||||
wait_friends();
|
|
||||||
break;
|
break;
|
||||||
case 0xe:
|
case 0xe:
|
||||||
system_inspect(u);
|
system_inspect(u);
|
||||||
|
|
|
@ -10,6 +10,7 @@ WITH REGARD TO THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define RAM_PAGES 0x10
|
#define RAM_PAGES 0x10
|
||||||
|
#define MAX_FRIENDS 0x10
|
||||||
|
|
||||||
#define CONSOLE_STD 0x1
|
#define CONSOLE_STD 0x1
|
||||||
#define CONSOLE_ARG 0x2
|
#define CONSOLE_ARG 0x2
|
||||||
|
|
Loading…
Reference in New Issue