Changeset 39716 in project for release/5/mailbox/trunk/mailbox.scm


Ignore:
Timestamp:
03/15/21 05:15:31 (3 months ago)
Author:
Kon Lovett
Message:

queue depth limit (wip)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/5/mailbox/trunk/mailbox.scm

    r39702 r39716  
    3838  ;Mailbox API
    3939  make-mailbox
     40  make-limited-mailbox
    4041  mailbox?
    4142  mailbox-name
    4243  mailbox-empty?
    4344  mailbox-count
     45  mailbox-limit
    4446  mailbox-waiting?
    4547  mailbox-waiters
     
    6163(import scheme
    6264  (chicken base)
     65  (chicken fixnum)
    6366  (chicken syntax)
    6467  (chicken condition)
     
    7376    thread-signal! thread-sleep!
    7477    thread-suspend! thread-resume!))
     78
     79;;; Typoes
     80
     81(define-type srfi-18-time   (struct time))
     82(define-type mailbox        (struct mailbox))
     83(define-type mailbox-cursor (struct mailbox-cursor))
     84(define-type time-number    (or fixnum float))
     85(define-type timeout        (or time-number srfi-18-time))
     86(define-type unique-object  (vector-of symbol))
     87
     88(: mailbox-timeout-condition?         (* -> boolean : condition))
     89(: make-mailbox                       (#!optional * -> mailbox))
     90(: make-limited-mailbox               (#!optional (or boolean fixnum) * -> mailbox))
     91(: mailbox?                           (* -> boolean : mailbox))
     92(: mailbox-name                       (mailbox --> *))
     93(: mailbox-empty?                     (mailbox -> boolean))
     94(: mailbox-count                      (mailbox -> fixnum))
     95(: mailbox-limit                      (mailbox -> fixnum))
     96(: mailbox-waiting?                   (mailbox -> boolean))
     97(: mailbox-waiters                    (mailbox -> list))
     98(: mailbox-send!                      (mailbox * -> void))
     99(: mailbox-wait!                      (mailbox #!optional timeout -> void))
     100(: mailbox-receive!                   (mailbox #!optional timeout * -> *))
     101(: mailbox-push-back!                 (mailbox * -> void))
     102(: mailbox-push-back-list!            (mailbox list -> void))
     103(: make-mailbox-cursor                (mailbox -> mailbox-cursor))
     104(: mailbox-cursor?                    (* -> boolean : mailbox-cursor))
     105(: mailbox-cursor-mailbox             (mailbox-cursor --> mailbox))
     106(: mailbox-cursor-rewound?            (mailbox-cursor -> boolean))
     107(: mailbox-cursor-unwound?            (mailbox-cursor -> boolean))
     108(: mailbox-cursor-rewind              (mailbox-cursor -> void))
     109(: mailbox-cursor-next                (mailbox-cursor #!optional timeout * -> *))
     110(: mailbox-cursor-extract-and-rewind! (mailbox-cursor -> void))
    75111
    76112;;; Support
     
    218254(include-relative "inline-queue")
    219255
    220 ;;; Typoes
    221 
    222 (define-type srfi-18-time   (struct time))
    223 (define-type mailbox        (struct mailbox))
    224 (define-type mailbox-cursor (struct mailbox-cursor))
    225 (define-type time-number    (or fixnum float))
    226 (define-type timeout        (or time-number srfi-18-time))
    227 (define-type unique-object  (vector-of symbol))
    228 
    229 (: mailbox-timeout-condition?         (* -> boolean : condition))
    230 (: make-mailbox                       (#!optional * -> mailbox))
    231 (: mailbox?                           (* -> boolean : mailbox))
    232 (: mailbox-name                       (mailbox --> *))
    233 (: mailbox-empty?                     (mailbox -> boolean))
    234 (: mailbox-count                      (mailbox -> fixnum))
    235 (: mailbox-waiting?                   (mailbox -> boolean))
    236 (: mailbox-waiters                    (mailbox -> list))
    237 (: mailbox-send!                      (mailbox * -> void))
    238 (: mailbox-wait!                      (mailbox #!optional timeout -> void))
    239 (: mailbox-receive!                   (mailbox #!optional timeout * -> *))
    240 (: mailbox-push-back!                 (mailbox * -> void))
    241 (: mailbox-push-back-list!            (mailbox list -> void))
    242 (: make-mailbox-cursor                (mailbox -> mailbox-cursor))
    243 (: mailbox-cursor?                    (* -> boolean : mailbox-cursor))
    244 (: mailbox-cursor-mailbox             (mailbox-cursor --> mailbox))
    245 (: mailbox-cursor-rewound?            (mailbox-cursor -> boolean))
    246 (: mailbox-cursor-unwound?            (mailbox-cursor -> boolean))
    247 (: mailbox-cursor-rewind              (mailbox-cursor -> void))
    248 (: mailbox-cursor-next                (mailbox-cursor #!optional timeout * -> *))
    249 (: mailbox-cursor-extract-and-rewind! (mailbox-cursor -> void))
    250 
    251256;;; Mailbox
    252257
     
    260265  (wt %mailbox-waiters %mailbox-waiters-set!) )
    261266
    262 (define-inline (%make-mailbox nm)
    263   (%raw-make-mailbox nm (%make-empty-queue) '()) )
     267(define-inline (%make-mailbox nm lm)
     268  (%raw-make-mailbox nm (%make-empty-queue lm) '()) )
    264269
    265270(define (error-mailbox loc obj #!optional argnam)
     
    281286(define-inline (%mailbox-queue-count mb)
    282287  (%queue-count (%mailbox-queue mb)) )
     288
     289(define-inline (%mailbox-queue-limit mb)
     290  (%queue-limit (%mailbox-queue mb)) )
    283291
    284292(define-inline (%mailbox-queue-add! mb x)
     
    475483(define-syntax on-mailbox-available
    476484  (syntax-rules ()
    477     ((_ ?loc ?mb ?timout ?timout-value ?expr0 ...)
     485    ((on-mailbox-available ?loc ?mb ?timout ?timout-value ?expr0 ...)
    478486      (let ((_mb ?mb) (_to ?timout) (_tv ?timout-value))
    479487        (let waiting ()
     
    506514;; Mailbox Constructor
    507515
     516(define (make-limited-mailbox #!optional lm (nm (gensym 'mailbox)))
     517  (%make-mailbox nm
     518    (cond
     519      ((not lm)     QUEUE-UNBUFFERED)
     520      ((fixnum? lm) lm)
     521      (else         QUEUE-UNLIMITED))) )
     522
    508523(define (make-mailbox #!optional (nm (gensym 'mailbox)))
    509   (%make-mailbox nm) )
     524  (make-limited-mailbox #t nm) )
    510525
    511526(define (mailbox? obj)
     
    522537(define (mailbox-count mb)
    523538  (%mailbox-queue-count (%check-mailbox 'mailbox-count mb)) )
     539
     540(define (mailbox-limit mb)
     541  (%mailbox-queue-limit (%check-mailbox 'mailbox-count mb)) )
    524542
    525543(define (mailbox-waiting? mb)
     
    564582  (with-output-to-port out
    565583    (lambda ()
    566       (printf "#<mailbox ~A queued: ~A waiters: ~A>"
     584      (printf "#<mailbox ~A queued: ~A waiters: ~A limit: ~A>"
    567585        (%mailbox-name mb)
    568586        (%mailbox-queue-count mb)
    569         (%mailbox-waiters-count mb)) ) ) )
     587        (%mailbox-waiters-count mb)
     588        (%mailbox-queue-limit mb)) ) ) )
    570589
    571590;;; Mailbox Cursor
Note: See TracChangeset for help on using the changeset viewer.