Changeset 34960 in project


Ignore:
Timestamp:
12/25/17 21:16:10 (12 months ago)
Author:
kon
Message:

oh my , wrapping - a seasonal pun ?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/thread-utils/trunk/atomic-value.scm

    r34959 r34960  
    88;;
    99;; - something like mutex-conditions for state-change watchers?
     10;;
     11;; - clojure validators and watches
    1012
    1113;;;
     
    2830  default-atom-value
    2931  ;
    30   make-atom atom
     32  make-atom atom atom-wrap
    3133  atom? check-atom error-atom
    3234  atom-value
     
    4244(use
    4345  srfi-18
     46  (only data-structures identity)
    4447  (only miscmacros define-parameter)
    4548  (only moremacros ->boolean)
     
    9497
    9598(define-inline (<atom>-value atm)
    96   (mutex-specific atm) )
     99  (let ((func (mutex-specific atm)))
     100    (func) ) )
    97101
    98102;=> (or #f <atom>)
    99103(define-inline (<atom>-value-set! atm val)
    100   (mutex-specific-set! atm val)
     104  (let ((func (mutex-specific atm)))
     105    (mutex-specific-set! atm (func val)) )
    101106  ;need true return
    102107  atm )
     
    165170
    166171;
    167 (define: (atom (val *)) --> <atom>
    168   ;just in case doesn't inline make-atom
    169   (make-<atom> val) )
     172(define: (atom (oval *)) --> <atom>
     173  (<atom>-value-set! (atom-wrap identity) oval) )
     174
     175;NOTE the {{mut}} need only return a value for the atom ,
     176;side-effects are extra - so validators and watches are possible
     177;via a suitable {{mut}}
     178; - (atom-mutator atom <func/1>)
     179; - (atom-validator atom <func/1>)
     180; - (atom-watcher atom <func/1>)
     181;
     182(define: (atom-wrap (mut procedure)) --> <atom>
     183  (check-procedure 'atom-wrap mut)
     184  (make-<atom>
     185    (let ((val (void)))
     186      ;
     187      (define proc
     188        (case-lambda
     189          (() val)
     190          ((ival)
     191            (set! val (mut ival))
     192            proc ) ) )
     193      ;
     194      proc ) ) )
    170195
    171196;
Note: See TracChangeset for help on using the changeset viewer.