summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)))