aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-09-08 09:32:26 +0000
committerrodri <rgl@antares-labs.eu>2023-09-08 09:32:26 +0000
commitebbadfc6e6a5041bc4dd15d8c8db327b13997b41 (patch)
tree383388b156161cde7d3f4d528d70cad8e7384de3
parente29fc9d0f23c62085114cb479032e07b0fb29abb (diff)
downloadbattleship-ebbadfc6e6a5041bc4dd15d8c8db327b13997b41.tar.gz
battleship-ebbadfc6e6a5041bc4dd15d8c8db327b13997b41.tar.bz2
battleship-ebbadfc6e6a5041bc4dd15d8c8db327b13997b41.zip
got rid of unused locking popplayer. use an fd for the threadgrp.
-rw-r--r--btsd.c25
1 files changed, 4 insertions, 21 deletions
diff --git a/btsd.c b/btsd.c
index 861add4..ccc55b8 100644
--- a/btsd.c
+++ b/btsd.c
@@ -27,30 +27,13 @@ pushplayer(Player *p)
fprint(2, "pushed fd %d sfd %d state %d\n", p->fd, p->sfd, p->state);
}
+/* XXX non-locking */
Player *
popplayer(void)
{
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);
@@ -135,7 +118,7 @@ battleproc(void *arg)
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 @@ matchmaker(void *)
}
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;