(***********************************************************************) (* *) (* ATS/contrib/libats-hwxi *) (* *) (***********************************************************************) (* ** Copyright (C) 2017 Hongwei Xi, ATS Trustful Software, Inc. ** ** Permission is hereby granted, free of charge, to any person obtaining a ** copy of this software and associated documentation files (the "Software"), ** to deal in the Software without restriction, including without limitation ** the rights to use, copy, modify, merge, publish, distribute, sublicense, ** and/or sell copies of the Software, and to permit persons to whom the ** Software is furnished to do so, subject to the following stated conditions: ** ** The above copyright notice and this permission notice shall be included in ** all copies or substantial portions of the Software. ** ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ** FROM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS ** IN THE SOFTWARE. *) (* ****** ****** *) // HX-2017-02-11: // A fworkshop where: // fws$store = channel // fws$fwork = lincloptr (* ****** ****** *) #define ATS_PACKNAME"ATSCNTRB.HX.fworkshop_channel" #define ATS_DYNLOADFLAG 0 (* ****** ****** *) #include "./fworkshop.dats" (* ****** ****** *) extern fun fworkshop_insert_lincloptr( fws : fworkshop , fwork : () - int ) : void (* ****** ****** *) local vtypedef fwork = fws$fwork assume fws$store_type() = channel(fws$fwork) #staload $CHANNEL_t #include "./../mydepies.hats" in implement fws$store_takeout (store) = channel_takeout(store) (* extern fun{} fws$store_takeout (store: fws$store): fws$fwork *) implement fws$store_insert (store, fwork) = let val opt = channel_insert_opt(store, fwork) in case+ opt of | ~None_vt() => () | ~Some_vt (fwork) => () where { val status = fws$fwork_process{}(fwork) } end (*extern fun{} fws$store_insert (fws$store, fws$fwork): void *) implement fws$store_create_exn () = let val cap = i2sz(fws$store_capacity{}(())) in channel_create_exn(cap) end (* extern fun{} fws$store_create_exn(): fws$store *) end (* ****** ****** *) local assume fws$fwork_vtype() = () - int in implement fworkshop_insert_lincloptr (fws, fwork) = fworkshop_insert_work{}(fws, fwork) implement fws$fwork_process (fwork) = status where { val status = fwork() val () = cloptr_free($UN.castvwtp0{cloptr(void)}(fwork)) } (* extern fun{} fws$fwork_process(fws$fwork): int *) end (* ****** ****** *) (* end of [fworkshop_channel.dats] *)