synchronization (2)
This commit is contained in:
29
main.rkt
29
main.rkt
@@ -13,6 +13,7 @@
|
||||
sl-log-to-file&display
|
||||
sl-set-log-level
|
||||
sl-log-level
|
||||
sl-sync
|
||||
)
|
||||
|
||||
(define (iso-timestamp)
|
||||
@@ -26,8 +27,15 @@
|
||||
(date-second d))))
|
||||
|
||||
(define sync-count 0)
|
||||
(define sync-sem (make-semaphore))
|
||||
(define sync-sems (make-hash))
|
||||
|
||||
(define (sl-sync l topic)
|
||||
(let ((sem (hash-ref sync-sems topic #f)))
|
||||
(when (eq? sem #f)
|
||||
(set! sem (make-semaphore))
|
||||
(hash-set! sync-sems topic sem))
|
||||
(log-message l 'fatal #f "@@SYNC@@" (list (iso-timestamp) topic))
|
||||
(semaphore-wait sem)))
|
||||
|
||||
(define log-callbacks #f)
|
||||
(set! log-callbacks '())
|
||||
@@ -76,11 +84,17 @@
|
||||
)
|
||||
|
||||
(when (string=? msg "@@SYNC@@")
|
||||
(set! sync-count (- sync-count 1))
|
||||
(semaphore-post sync-sem)
|
||||
(set! msg "synchronization received")
|
||||
(let ((sem (hash-ref sync-sems topic #f)))
|
||||
(if (eq? sem #f)
|
||||
(begin
|
||||
(set! msg (format "Cannot synchronize on topic ~a" topic))
|
||||
(set! level 'error))
|
||||
(begin
|
||||
(semaphore-post sem)
|
||||
(set! msg (format "Synchronization received on topic ~a" topic))
|
||||
(set! level 'info)
|
||||
)
|
||||
)))
|
||||
|
||||
(enqueue! log-queue (list topic level dt msg))
|
||||
(unless (null? lc)
|
||||
@@ -160,12 +174,7 @@
|
||||
(define (warnn msg . args) (log 'warning msg args))
|
||||
(define (errn msg . args) (log 'error msg args))
|
||||
(define (fataln msg . args) (log 'fatal msg args))
|
||||
(define (syncn) (begin
|
||||
(log-message l 'fatal #f "@@SYNC@@" (list (iso-timestamp) 'id))
|
||||
(set! sync-count (+ sync-count 1))
|
||||
(semaphore-wait sync-sem)
|
||||
)
|
||||
)
|
||||
(define (syncn) (sl-sync l 'id))
|
||||
(log-to* receiver (λ () log-callbacks))
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user