X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=sam.git;a=blobdiff_plain;f=fifo.scm;h=ab5eda05a5e6e22c945ac83d6f0241746e07c966;hp=d2cea2293b23f26bac21cc338397f83e91a9cffb;hb=bf8a20a40dd9e5d963498a0fe43ef5fea52d07c6;hpb=2ddb195dc4dace1129e50e10c6992e2ae95fae83 diff --git a/fifo.scm b/fifo.scm index d2cea22..ab5eda0 100644 --- a/fifo.scm +++ b/fifo.scm @@ -2,12 +2,10 @@ (make-fifo fifo-push fifo-pop - fifo-empty? fifo->list) (import scheme - (chicken base) - srfi-18) + (chicken base)) (define (make-fifo) (define (cell val prev next) @@ -21,12 +19,9 @@ (set-car! (cddr cell) next-cell)) (let ((head '()) - (tail '()) - (pop-mutex (make-mutex))) - (mutex-lock! pop-mutex #f #f) + (tail '())) (lambda (cmd . args) (case cmd - ((empty?) (null? head)) ((push) (if (not (null? head)) (let ((old-head head)) @@ -35,37 +30,26 @@ (begin ;; Initialize list (set! head (cell (car args) '() '())) - (set! tail head) - (mutex-unlock! pop-mutex)))) + (set! tail head)))) ((pop) - (mutex-lock! pop-mutex #f #f) - (if (null? head) - (error "FIFO empty.") - (let ((old-tail tail)) - (set! tail (cell-prev old-tail)) - (if (null? tail) - (set! head '()) - (begin - (set-cell-next! tail '()) - (mutex-unlock! pop-mutex #f #f))) - (cell-val old-tail))))) - ((->list) (if (not (= (length args) 0)) - (error "Wrong number of arguments to ->list.") - (let loop ((this-cell head)) - (if (null? this-cell) - '() - (cons (cell-val this-cell) - (loop (cell-next this-cell)))))))))) + (let ((old-tail tail)) + (set! tail (cell-prev old-tail)) + (if (null? tail) + (set! head '()) + (set-cell-next! tail '())) + (cell-val old-tail))) + ((->list) + (let loop ((this-cell head)) + (if (null? this-cell) + '() + (cons (cell-val this-cell) + (loop (cell-next this-cell)))))))))) - (define (fifo-push fifo x) (fifo 'push x)) (define (fifo-pop fifo) (fifo 'pop)) - (define (fifo-empty? fifo) - (fifo 'empty?)) - (define (fifo->list fifo) (fifo '->list)))