From 4bc691b3d921f608efd3dc668688c1a36151fa1f Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 25 Jun 2019 17:34:50 -0400 Subject: [PATCH] WIP --- libs/cyclone/shared-queue.scm | 51 +++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/libs/cyclone/shared-queue.scm b/libs/cyclone/shared-queue.scm index da9d18eb..46ea89a6 100644 --- a/libs/cyclone/shared-queue.scm +++ b/libs/cyclone/shared-queue.scm @@ -19,28 +19,28 @@ ;- queue-empty? (import (scheme base) + (cyclone test) (cyclone concurrent) (srfi 18) (scheme write)) (define *default-table-size* 64) -TODO: how will data structure work? -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 -of the queue -so we need - start, end -capacity is length of the vector -if start == end, vector is empty -if start == end after an add, then vector is full, need to resize - -TODO: should create a corresponding file of tests for this +;TODO: how will data structure work? +;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 +;of the queue +;so we need - start, end +;capacity is length of the vector +;if start == end, vector is empty +;if start == end after an add, then vector is full, need to resize (define-record-type - (%make-queue store size lock) + (%make-queue store start end lock) queue? (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!)) (define (make-queue) @@ -48,6 +48,7 @@ TODO: should create a corresponding file of tests for this (%make-queue (make-vector *default-table-size* #f) 0 + 0 (make-mutex)))) (define (queue . elems) @@ -73,17 +74,17 @@ TODO: should create a corresponding file of tests for this (mutex-unlock! (q:lock q)) ) -(define (%queue-resize! q) - ;; TODO: assumes we already have the lock - ;; TODO: error if size is larger than fixnum?? - (let ((old-store (q:store q)) - (new-store (make-vector (* (vector-length old-store) 2) #f))) - (q:set-size! q 0) - (let loop ((i (vector-length old-store))) - (when (not (zero? i)) - (%queue-add! q (vector-ref - (loop (- i 1))))) -) +;(define (%queue-resize! q) +; ;; TODO: assumes we already have the lock +; ;; TODO: error if size is larger than fixnum?? +; (let ((old-store (q:store q)) +; (new-store (make-vector (* (vector-length old-store) 2) #f))) +; (q:set-size! q 0) +; (let loop ((i (vector-length old-store))) +; (when (not (zero? i)) +; (%queue-add! q (vector-ref +; (loop (- i 1))))) +;) ;- (queue ...) constructor ;- 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-capacity (max size until resize occurs) ;- queue-empty? + +;(test-group "basic") +;(test #t (shared-queue? (make-queue))) +;(test-exit)