ref: 590d2b438b3ece75659ed51e4353e35519144cf5
parent: 1d710193b2b6d199929d61a3aa1547a8f8770cd8
author: mkf <mkf@cloud9p.org>
date: Thu Jun 6 08:11:13 EDT 2024
srv5: lots of fixes, (check for nulls, etc)
--- a/srv5.c
+++ b/srv5.c
@@ -472,8 +472,8 @@
c1->thread = (pthread_t*)emalloc(sizeof(pthread_t));
c2->thread = (pthread_t*)emalloc(sizeof(pthread_t));
- llappend(threads, c1->thread);
- llappend(threads, c2->thread);
+// llappend(threads, c1->thread);
+// llappend(threads, c2->thread);
pthread_mutex_unlock(&game_lock);
@@ -592,13 +592,18 @@
{
Client *head;
+ dprint("makematch(%p)\n", c);
pthread_mutex_lock(&game_lock);
- if(clients.l == nil)
- clients.l = llnew();
+ if(clients.head == nil)
+ {
+ clients.head = llnew();
+ clients.tail = clients.head;
- head = (Client*)clients.l->data;
- if(head == nil || c->side == head->side)
+ }
+ head = (Client*)clients.head->data;
+ if(clients.len == 0 || c->side == head->side)
{
+ /* head->side can never be PRandom anyway */
if(c->side == PRandom)
c->side = nrand(1) ? PTrapper : PGlenda;
@@ -705,7 +710,9 @@
srand(time(nil));
games = llnew();
- clients.l = llnew();
+ clients.len = 0;
+ clients.head = llnew();
+ clients.tail = clients.head;
threads = llnew();
srv(listenfd);