ref: ebbadfc6e6a5041bc4dd15d8c8db327b13997b41
parent: e29fc9d0f23c62085114cb479032e07b0fb29abb
author: rodri <rgl@antares-labs.eu>
date: Fri Sep 8 05:32:26 EDT 2023
got rid of unused locking popplayer. use an fd for the threadgrp.
--- a/btsd.c
+++ b/btsd.c
@@ -27,6 +27,7 @@
fprint(2, "pushed fd %d sfd %d state %d\n", p->fd, p->sfd, p->state);
}
+/* XXX non-locking */
Player *
popplayer(void)
{
@@ -33,33 +34,15 @@
Player *p;
p = nil;
- qlock(&playerq);
if(playerq.nplayers > 0){
p = playerq.players[0];
memmove(&playerq.players[0], &playerq.players[1], --playerq.nplayers * sizeof p);
}
- qunlock(&playerq);
if(debug)
fprint(2, "poppin fd %d sfd %d state %d\n", p->fd, p->sfd, p->state);
return p;
}
-/* non-locking version */
-Player *
-nlpopplayer(void)
-{
- Player *p;
-
- p = nil;
- if(playerq.nplayers > 0){
- p = playerq.players[0];
- memmove(&playerq.players[0], &playerq.players[1], --playerq.nplayers * sizeof p);
- }
- if(debug)
- fprint(2, "poppin fd %d sfd %d state %d\n", p->fd, p->sfd, p->state);
- return p;
-}
-
void
freeplayer(Player *p)
{
@@ -135,7 +118,7 @@
a[1].c = cp[1].c; a[1].v = &s; a[1].op = CHANRCV;
a[2].op = CHANEND;
- threadsetgrp(truerand());
+ threadsetgrp(cp[0].fd);
threadcreate(netrecvthread, &cp[0], mainstacksize);
threadcreate(netrecvthread, &cp[1], mainstacksize);
@@ -286,8 +269,8 @@
}
m = emalloc(sizeof *m);
- m->pl[0] = nlpopplayer();
- m->pl[1] = nlpopplayer();
+ m->pl[0] = popplayer();
+ m->pl[1] = popplayer();
qunlock(&playerq);
m->pl[0]->state = Waiting0;
m->pl[1]->state = Waiting0;