mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 04:25:06 +02:00
WIP
This commit is contained in:
parent
d7ab5ce39e
commit
4bc691b3d9
1 changed files with 28 additions and 23 deletions
|
@ -19,28 +19,28 @@
|
||||||
;- queue-empty?
|
;- queue-empty?
|
||||||
|
|
||||||
(import (scheme base)
|
(import (scheme base)
|
||||||
|
(cyclone test)
|
||||||
(cyclone concurrent)
|
(cyclone concurrent)
|
||||||
(srfi 18)
|
(srfi 18)
|
||||||
(scheme write))
|
(scheme write))
|
||||||
|
|
||||||
(define *default-table-size* 64)
|
(define *default-table-size* 64)
|
||||||
|
|
||||||
TODO: how will data structure work?
|
;TODO: how will data structure work?
|
||||||
probably want a circular queue, add at end and remove from start
|
;probably want a circular queue, add at end and remove from start
|
||||||
need to keep track of those positions, they may wrap around the end
|
;need to keep track of those positions, they may wrap around the end
|
||||||
of the queue
|
;of the queue
|
||||||
so we need - start, end
|
;so we need - start, end
|
||||||
capacity is length of the vector
|
;capacity is length of the vector
|
||||||
if start == end, vector is empty
|
;if start == end, vector is empty
|
||||||
if start == end after an add, then vector is full, need to resize
|
;if start == end after an add, then vector is full, need to resize
|
||||||
|
|
||||||
TODO: should create a corresponding file of tests for this
|
|
||||||
|
|
||||||
(define-record-type <queue>
|
(define-record-type <queue>
|
||||||
(%make-queue store size lock)
|
(%make-queue store start end lock)
|
||||||
queue?
|
queue?
|
||||||
(store q:store q:set-store!)
|
(store q:store q:set-store!)
|
||||||
(size q:size q:set-size!)
|
(start q:start q:set-start!)
|
||||||
|
(end q:end q:set-end!)
|
||||||
(lock q:lock q:set-lock!))
|
(lock q:lock q:set-lock!))
|
||||||
|
|
||||||
(define (make-queue)
|
(define (make-queue)
|
||||||
|
@ -48,6 +48,7 @@ TODO: should create a corresponding file of tests for this
|
||||||
(%make-queue
|
(%make-queue
|
||||||
(make-vector *default-table-size* #f)
|
(make-vector *default-table-size* #f)
|
||||||
0
|
0
|
||||||
|
0
|
||||||
(make-mutex))))
|
(make-mutex))))
|
||||||
|
|
||||||
(define (queue . elems)
|
(define (queue . elems)
|
||||||
|
@ -73,17 +74,17 @@ TODO: should create a corresponding file of tests for this
|
||||||
(mutex-unlock! (q:lock q))
|
(mutex-unlock! (q:lock q))
|
||||||
)
|
)
|
||||||
|
|
||||||
(define (%queue-resize! q)
|
;(define (%queue-resize! q)
|
||||||
;; TODO: assumes we already have the lock
|
; ;; TODO: assumes we already have the lock
|
||||||
;; TODO: error if size is larger than fixnum??
|
; ;; TODO: error if size is larger than fixnum??
|
||||||
(let ((old-store (q:store q))
|
; (let ((old-store (q:store q))
|
||||||
(new-store (make-vector (* (vector-length old-store) 2) #f)))
|
; (new-store (make-vector (* (vector-length old-store) 2) #f)))
|
||||||
(q:set-size! q 0)
|
; (q:set-size! q 0)
|
||||||
(let loop ((i (vector-length old-store)))
|
; (let loop ((i (vector-length old-store)))
|
||||||
(when (not (zero? i))
|
; (when (not (zero? i))
|
||||||
(%queue-add! q (vector-ref
|
; (%queue-add! q (vector-ref
|
||||||
(loop (- i 1)))))
|
; (loop (- i 1)))))
|
||||||
)
|
;)
|
||||||
|
|
||||||
;- (queue ...) constructor
|
;- (queue ...) constructor
|
||||||
;- queue-add! - add item to the queue
|
;- queue-add! - add item to the queue
|
||||||
|
@ -95,3 +96,7 @@ TODO: should create a corresponding file of tests for this
|
||||||
;- queue-size (current length)
|
;- queue-size (current length)
|
||||||
;- queue-capacity (max size until resize occurs)
|
;- queue-capacity (max size until resize occurs)
|
||||||
;- queue-empty?
|
;- queue-empty?
|
||||||
|
|
||||||
|
;(test-group "basic")
|
||||||
|
;(test #t (shared-queue? (make-queue)))
|
||||||
|
;(test-exit)
|
||||||
|
|
Loading…
Add table
Reference in a new issue