Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/system/Basis/Implementation/NJ/internal-signals.sml
ViewVC logotype

Diff of /sml/trunk/src/system/Basis/Implementation/NJ/internal-signals.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1600, Mon Aug 9 21:23:58 2004 UTC revision 1601, Tue Aug 10 14:40:53 2004 UTC
# Line 146  Line 146 
146        = MASKALL        = MASKALL
147        | MASK of signal list        | MASK of signal list
148    
   (* increment the masking level of the given signal by one, and return true.  
    *)  
     fun incMask (SIG(sigId, _)) = let  
           val {act, mask, signal} = getInfo sigId  
           in  
             setInfo(sigId, {act=act, mask=mask+1, signal=signal});  
             true  
           end  
   (* decrement the masking level of the given signal by one; return true,  
    * if the signal is still masked.  
    *)  
     fun decMask (SIG(sigId, _)) = let  
           val {act, mask, signal} = getInfo sigId  
           in  
             (mask <> 0) andalso (  
               setInfo(sigId, {act=act, mask=mask-1, signal=signal});  
               (mask <> 1))  
           end  
   
149      local      local
150      (* Run-time system API:      (* Run-time system API:
151       *   NONE   -- empty mask       *   NONE   -- empty mask
# Line 173  Line 154 
154       *)       *)
155        val setSigMask   : CI.system_const list option -> unit = signalFn "setSigMask"        val setSigMask   : CI.system_const list option -> unit = signalFn "setSigMask"
156        val getSigMask : unit -> CI.system_const list option = signalFn "getSigMask"        val getSigMask : unit -> CI.system_const list option = signalFn "getSigMask"
157        fun applyMask maskFn mask = let      (* sort a list of signals eliminating duplicates *)
158          fun sortSigs MASKALL = !sigList
159            | sortSigs (MASK l) = let
160            (* a simple insertion sort to eliminate duplicates *)            (* a simple insertion sort to eliminate duplicates *)
161              fun insert (s as SIG(id, _), []) = [s]              fun insert (s as SIG(id, _), []) = [s]
162                | insert (s as SIG(id, _), (s' as SIG(id', _))::r) =                | insert (s as SIG(id, _), (s' as SIG(id', _))::r) =
# Line 182  Line 165 
165                    else if (id = id')                    else if (id = id')
166                      then s' :: r                      then s' :: r
167                      else s' :: insert(s, r)                      else s' :: insert(s, r)
168              val sort = List.foldl insert []              in
169            (* apply the masking operations, return a list of signals that must                List.foldl insert [] l
170             * be masked/unmasked at the OS level.              end
171    (* FIXME: the following code is not right.  We need to preserve the mask state of
172     * any signals that are already masked but are not in the given list.
173     *)
174        (* test a masking operation against a list of signals, return a list of signals
175         * that is compatible with the runtime API (see above).
176         * Note that we do not change our internal state at this point.
177             *)             *)
178          fun testMask testFn mask = let
179              fun f ([], l, n) = (l, n)              fun f ([], l, n) = (l, n)
180                | f (s::r, l, n) =                | f (s::r, l, n) =
181                    if (maskFn s)                    if (testFn s)
182                      then f (r, (sigToConst s)::l, n+1)                      then f (r, (sigToConst s)::l, n+1)
183                      else f (r, l, n)                      else f (r, l, n)
184              val (l', numMasked) = (case mask              val (l, numMasked) = f (mask, [], 0)
                   of MASKALL => f (!sigList, [], 0)  
                    | (MASK l) => f (sort l, [], 0)  
                 (* end case *))  
185              in              in
186                if (numMasked = 0) then NONE                if (numMasked = 0) then NONE
187                else if (numMasked = !numSigs) then SOME[]                else if (numMasked = !numSigs) then SOME[]
188                else SOME l'                else SOME l
189              end              end
190      (* functions for incrementing a signal mask. *)
191        fun incMaskTest _ = true
192        fun incMask (SIG(sigId, _)) = let
193              val {act, mask, signal} = getInfo sigId
194              in
195                setInfo(sigId, {act=act, mask=mask+1, signal=signal})
196              end
197      (* functions for decrementing a signal mask. *)
198        fun decMaskTest (SIG(sigId, _)) = (#mask(getInfo sigId) > 1)
199        fun decMask (SIG(sigId, _)) = let
200              val {act, mask, signal} = getInfo sigId
201              in
202                if (mask > 0)
203                  then setInfo(sigId, {act=act, mask=mask-1, signal=signal})
204                  else ()
205              end
206    
207        in
208        fun maskSignals mask = let
209              val sigs = sortSigs mask
210      in      in
211      fun maskSignals mask = (case (applyMask incMask mask)              case (testMask incMaskTest sigs)
212             of NONE => ()               of NONE => () (* no signals are masked, so nothing to do *)
213              | m => setSigMask m                | m => (
214            (* end case *))                  (* NOTE: we must update the OS's view of the mask before we change
215      fun unmaskSignals mask = (case (applyMask decMask mask)                   * our own to avoid a race condition!
216             of SOME[] => ()                   *)
217              | m=> setSigMask m                    setSigMask m; (* update OS mask *)
218            (* end case *))                    List.app incMask sigs)
219                (* end case *)
220              end
221        fun unmaskSignals mask = let
222              val sigs = sortSigs mask
223              in
224                case (testMask decMaskTest sigs)
225                 of SOME[] => () (* all signals are masked, so nothing to do *)
226                  | m => (
227                    (* NOTE: we must update the OS's view of the mask before we change
228                     * our own to avoid a race condition!
229                     *)
230                      setSigMask m; (* update OS mask *)
231                      List.app decMask sigs)
232                (* end case *)
233              end
234      fun masked () = (case getSigMask()      fun masked () = (case getSigMask()
235             of NONE => MASK[]             of NONE => MASK[]
236              | SOME[] => MASKALL              | SOME[] => MASKALL

Legend:
Removed from v.1600  
changed lines
  Added in v.1601

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0