wm: glendy

Download patch

ref: 1cfe3d11519e64bcc6b6d73252d5854f134b33be
parent: d60b119559e63594d7cfcaf10f2db3ab068f19c9
author: mkf <mkf@cloud9p.org>
date: Wed Jun 5 16:38:32 EDT 2024

don't lock in wrong place

--- a/srv5.c
+++ b/srv5.c
@@ -599,9 +599,11 @@
 {
 	Client *head;
 
+	pthread_mutex_lock(&game_lock);
 	if(clients.l == nil)
 		clients.l = llnew();
 
+
 	head = clients.l->data;
 	if(head == nil || c->side == head->side)
 	{
@@ -609,6 +611,7 @@
 			c->side = nrand(1) ? PTrapper : PGlenda;
 		
 		qadd(&clients, c);
+		pthread_mutex_unlock(&game_lock);
 		fprint(c->fd, "WAIT\n");
 	}
 	else
@@ -617,6 +620,7 @@
 			c->side = (head->side == PGlenda) ? PTrapper : PGlenda;
 		
 		qnext(&clients);
+		pthread_mutex_unlock(&game_lock);
 		if(c->side == PTrapper)
 			play(c, head);
 		else
@@ -665,11 +669,7 @@
 	cl = newclient(s, fd);
 	
 	if(cl != nil)
-	{
-		pthread_mutex_lock(&game_lock);
 		makematch(cl);
-		pthread_mutex_unlock(&game_lock);
-	}
 	die:
 		free(s);
 }