diff options
| author | Christopher Allan Webber <cwebber@dustycloud.org> | 2017-08-10 14:06:51 -0500 |
|---|---|---|
| committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2017-08-10 14:13:12 -0500 |
| commit | 0fa1fd6adf9980229a46956503a6bf36e8154a78 (patch) | |
| tree | 3df2575d4fa95e2395160bd7fed4db198a3f82dc /fibers/deque.scm | |
| parent | Update copyright headers, adding Chris Webber where appropriate. (diff) | |
| download | guile-fibers-0fa1fd6adf9980229a46956503a6bf36e8154a78.tar.gz | |
Garbage collect synchronized items from channels put/get queues.
* fibers/conditions.scm (make-counter, %steps-till-gc, counter-decrement!)
(counter-reset!): Moved to new module, counter.scm.
* fibers/counter.scm: New file. Rename `%steps-till-gc' to
`%countdown-steps'.
* Makefile.am: Add counter.scm.
* fibers/channels.scm (<channel>, make-channel): Add new slots
`getq-gc-counter' and `putq-gc-counter'.
(put-operation, get-operation): Garbage collect synchronized items
from queues.
* fibers/deque.scm (dequeue-filter, dequeue-filter!): New procedures.
Diffstat (limited to 'fibers/deque.scm')
| -rw-r--r-- | fibers/deque.scm | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/fibers/deque.scm b/fibers/deque.scm index 6a41583..d427729 100644 --- a/fibers/deque.scm +++ b/fibers/deque.scm @@ -1,6 +1,7 @@ ;; Double-ended queue ;;;; Copyright (C) 2016 Andy Wingo <wingo@pobox.com> +;;;; Copyright (C) 2017 Christopher Allan Webber <cwebber@dustycloud.org> ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -27,10 +28,12 @@ dequeue dequeue-all dequeue-match + dequeue-filter undequeue dequeue! dequeue-all! - enqueue!)) + enqueue! + dequeue-filter!)) ;; A functional double-ended queue ("deque") has a head and a tail, ;; which are both lists. The head is in FIFO order and the tail is in @@ -82,6 +85,12 @@ ((head . tail) (make-deque (cons item head) tail)))) +(define (dequeue-filter dq pred) + (match dq + ((head . tail) + (cons (filter pred head) + (filter pred tail))))) + (define-inlinable (update! box f) (let spin ((x (atomic-box-ref box))) (call-with-values (lambda () (f x)) @@ -110,3 +119,8 @@ (update! dqbox (lambda (dq) (values (enqueue dq item) #f)))) + +(define (dequeue-filter! dqbox pred) + (update! dqbox (lambda (dq) + (values (dequeue-filter dq pred) + #f)))) |
