summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-12-16 22:17:51 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-12-16 22:18:07 +0100
commitd1fd250867ccd56dcaae0da0387d616e310d59ca (patch)
tree4213663d0daa0efcbf36d885f44c327edb99848d
parentd6ce26104985c313a2795487769e7109657dcb79 (diff)
simulation: synchronized logger
-rw-r--r--TODO.md1
-rw-r--r--simulation.scm17
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)))