commit a3fc3b943e46fff905e5357d2586e95ffcf1ad3e from: Omar Polo date: Tue Dec 19 14:26:11 2023 UTC ev: move some functions to ev/global.ha Move there functions that relies on the global event loop. commit - 64c4c1bc702cca4cefd4df5fab7f10dc371aa5a8 commit + a3fc3b943e46fff905e5357d2586e95ffcf1ad3e blob - cf0eebee28a4d065a9c24c36bcc3ec474bd6b4e3 blob + db1d7586b8e8f93428b6bca83e0be3c663dcc5cb --- ev/ev.ha +++ ev/ev.ha @@ -67,18 +67,6 @@ type base = struct { // TODO: timeout }; -let _default = base { - add = &evadd, - del = &evdel, - loop = &loop, - loopbreak = &evloopbreak, - sigpipe = void, - sigcb = void, - ... -}; - -let global = &_default; - export fn new() *evloop = alloc(base { add = &evadd, del = &evdel, @@ -101,18 +89,11 @@ fn poll2ev(ev: i16) event = { return event::READ; }; -export fn add( - fd: io::file, - ev: event, - f: *fn(io::file, event, nullable *opaque) void, data: nullable *opaque -) void = { - global.add(global, fd, ev, f, data); -}; - export fn evadd( evloop: *evloop, fd: io::file, - ev: event, f: *fn(io::file, event, nullable *opaque) void, + ev: event, + f: *fn(io::file, event, nullable *opaque) void, data: nullable *opaque ) void = { const b = evloop: *base; @@ -127,10 +108,6 @@ export fn evadd( }); }; -export fn del(fd: io::file) void = { - global.del(global, fd); -}; - export fn evdel(evloop: *evloop, fd: io::file) void = { const b = evloop: *base; for (let i = 0z; i < len(b.wip.pfds); i += 1) { @@ -155,8 +132,6 @@ fn prepare_queue(b: *base) void = { }; }; -export fn mainloop() (void | poll::error) = global.loop(global); - export fn loop(evloop: *evloop) (void | poll::error) = { const b = evloop: *base; @@ -179,10 +154,6 @@ export fn loop(evloop: *evloop) (void | poll::error) = }; }; -export fn loopbreak() void = { - global.loopbreak(global); -}; - export fn evloopbreak(evloop: *evloop) void = { const b = evloop: *base; b.stop = true; blob - /dev/null blob + 51d4b17b7da61ca306270a0473d13670dc035f8b (mode 644) --- /dev/null +++ ev/global.ha @@ -0,0 +1,56 @@ +// This is free and unencumbered software released into the public domain. +// +// Anyone is free to copy, modify, publish, use, compile, sell, or +// distribute this software, either in source code form or as a compiled +// binary, for any purpose, commercial or non-commercial, and by any +// means. +// +// In jurisdictions that recognize copyright laws, the author or authors +// of this software dedicate any and all copyright interest in the +// software to the public domain. We make this dedication for the benefit +// of the public at large and to the detriment of our heirs and +// successors. We intend this dedication to be an overt act of +// relinquishment in perpetuity of all present and future rights to this +// software under copyright law. +// +// 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 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. + +use io; +use unix::poll; + +let _default = base { + add = &evadd, + del = &evdel, + loop = &loop, + loopbreak = &evloopbreak, + sigpipe = void, + sigcb = void, + ... +}; + +let global = &_default; + +export fn add( + fd: io::file, + ev: event, + f: *fn(io::file, event, nullable *opaque) void, + data: nullable *opaque +) void = { + global.add(global, fd, ev, f, data); +}; + +export fn del(fd: io::file) void = { + global.del(global, fd); +}; + +export fn mainloop() (void | poll::error) = global.loop(global); + +export fn loopbreak() void = { + global.loopbreak(global); +};