Skip to content

piboistudios/hxsynchapi

Repository files navigation

HxSynchAPI

HxSynchAPI is a HashLink port of several Windows Synchronization APIs.

It is a WIP.

TODO:

  • - Create Haxe Native FFI Proxy
  • - Events
  • - Mutexes (needs working test.. need some shared I/O/IPC message passing)
  • - Critical Sections (needs try access)
  • - SRW Locks
  • - Synchronization Barriers (needs test)
  • - Maybe Interlocked Variables?
  • - Maybe Interlocked SLists?
  • - Expose User Friendly Haxe API
  • - Build automation
  • - Add usage examples

Events

final FOREVER = -1;
final callbacks:Array<Void->Void> = [];
var task = Event.create('task$eventId');
var ready = Event.create('ready$eventId');
var kill = false;
sys.thread.Thread.create(() -> {
    inline function backgroundJob() {
        trace('running background job');
    }
    while(!kill) {
        ready.signal();
        task.wait(FOREVER);
        ready.reset();
        backgroundJob();
        if(callbacks.length != 0) callbacks.shift()();
    }
    ready.close();
    task.close();
});
inline function queueTask(t:Void->Void) {
    callbacks.push(t);
    task.signal();
    ready.wait(FOREVER);
    task.reset();
}
inline function kill() {
    kill = true;
}
queueTask(() -> {
    trace('foo');
});

About

Windows Synchronization API for Haxe

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published