From 856ab034d5c7b73e0fd86c4e1a3e9d8af92f3d00 Mon Sep 17 00:00:00 2001 From: Thomas Hintz Date: Tue, 28 Apr 2020 17:27:48 -0700 Subject: [PATCH] Ensure amb+ is protected with mutex. --- src/server/farm.scm | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/server/farm.scm b/src/server/farm.scm index ec623c2..103632e 100644 --- a/src/server/farm.scm +++ b/src/server/farm.scm @@ -96,6 +96,14 @@ (lambda () (set! (,(first (second x)) obj) res)) (lambda () (mutex-unlock! mutex)))))))) +(define-syntax with-app + (syntax-rules () + ((_ (app) body ...) + (dynamic-wind + (lambda () (mutex-lock! (app-mutex app))) + (lambda () body ...) + (lambda () (mutex-unlock! (app-mutex app))))))) + (define-record player (setter cash) (setter display-cash) @@ -2303,6 +2311,7 @@ (player-stats p))))) (define (get-actions player space) + (with-app (*app*) (let ((res '())) (let loop ((a (prolog+meta @@ -2408,7 +2417,7 @@ `((,(list-ref *months* space) ?action tom ?value))))) (if a (begin (set! res (cons a res)) (loop (amb+))) - res)))) + res))))) (define (normalize-crop crop) (cond ((or (eq? crop 'wheat) (eq? crop 'corn)) @@ -2625,24 +2634,8 @@ ;; TODO ;; make sure two players can't have the same name -;; "your turn to roll" showing up on mobile when on action screen ;; bug on display for uncle berts farm ;; Error: (mailbox-send!) bad argument type - not a mailbox: "redhead91 ;; farmers luck can cause display cash to be out of sync - -;; Uncaught TypeError: Cannot read property 'toFixed' of undefined -;; at St (app.0f8d4f4543faaee5dff1.js:1377) -;; at app.0f8d4f4543faaee5dff1.js:1457 -;; at Object.y [as dispatch] (vendors.bef6ac3591b4d9cb3c76.js:8936) -;; at app.0f8d4f4543faaee5dff1.js:1226 -;; at eu (vendors.bef6ac3591b4d9cb3c76.js:12601) -;; at WebSocket.pt (app.0f8d4f4543faaee5dff1.js:1127) - -;; Uncaught TypeError: Cannot read property 'krispy kreme' of undefined -;; at app.0f8d4f4543faaee5dff1.js:1461 -;; at Object.y [as dispatch] (vendors.bef6ac3591b4d9cb3c76.js:8936) -;; at app.0f8d4f4543faaee5dff1.js:1226 -;; at eu (vendors.bef6ac3591b4d9cb3c76.js:12601) -;; at WebSocket.pt (app.0f8d4f4543faaee5dff1.js:1127)