From d1fd250867ccd56dcaae0da0387d616e310d59ca Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Mon, 16 Dec 2024 22:17:51 +0100 Subject: simulation: synchronized logger --- TODO.md | 1 - simulation.scm | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index 344a6ff..6a7305e 100644 --- a/TODO.md +++ b/TODO.md @@ -10,4 +10,3 @@ retransmissions) - Fix interference calculation -> IMPORTANT - Signal strength, location and rssi (complex, just an extra) -- Make logger concurrency-friendly -> IMPORTANT diff --git a/simulation.scm b/simulation.scm index 09cc16d..01bc347 100644 --- a/simulation.scm +++ b/simulation.scm @@ -25,9 +25,21 @@ (begin exp ...) (loop))) +;; Synchronized logger +(define *output-channel* (make-channel)) +(define (logger) + (forever + (let ((msg (get-message *output-channel*))) + (display msg)))) + (define (ll f . data) (let ((now (gettimeofday))) - (format #t "~a~a - ~?~%" (car now) (cdr now) f data))) + (spawn-fiber + (lambda () + (put-message + *output-channel* + (format #f "~a~a - ~?~%" (car now) (cdr now) f data)))))) + ;; type can be: ;; 'start @@ -197,6 +209,9 @@ (define (run-simulation) + ;; We need a synchronized logger running in a fiber + (spawn-fiber logger) + (let* ((radio-chn (make-channel)) (end-devices (make-hash-table)) (gateways (make-hash-table))) -- cgit v1.2.3