summaryrefslogtreecommitdiff
path: root/src/pulp.h
AgeCommit message (Collapse)Author
2018-09-23libpulp: introduce pulp_init()Vito Caputo
Rather than having pulp_tick() on win32 always fiberize/unfiberize the thread at the start/end of the tick, just fiberize once at library initialization time. The old approach was problematic with nested pulp instances. As in, when a fiber called pulp_tick() on another pulp_t, in scenarios where the programmer has arranged for a fiber heirarchy of sorts, the nested pulp_tick() would once again fiberize the already fiberized thread, then unfiberize, and poof the magic smoke comes out. Rather than maintaining some kind of reference count and transparently fiberize vs. getcurrentfiber in pulp_tick(), I'm just introducing the explicit initialization to address this limitation. This way pulp_tick() can just always get the current fiber for the calling context on win32. The initializer currently does nothing on *nix/ucontext.h systems, this is just a win32 issue.
2018-06-03libpulp: add pulp_exit() public prototypeVito Caputo
2018-05-13libpulp: introduce mailbox conceptVito Caputo
The sleep functions, which are few, and the only current means for fibers to block/enter the scheduler, now take an optional pulp_mailbox_t * parameter. When supplied, other fibers may communicate with the sleeping fiber via pulp_fiber_get_mailslot(). This function checks the destination fiber for a mailbox and verifies there's space available. On success, it returns a pointer to the next available mailslot while advancing the mailboxes mail count. The caller may then use this mailslot pointer to write directly to the void * it references in the mailbox. If the receiving fiber took care to populate its mailbox with slots referencing external memory, the sender could dereference the mailslot's value to find the external memory and write larger messages without needing to allocate new space itself only for the reciever to have to free it shortly. It's also possible to not do anything at all with the mailslot. Simply successfully getting a mailslot communicates _something_ to the recipient by virtue of the count advancing. The returned mailslot can only be considered valid by the calling fiber until it sleeps, after that the slot must be treated as reclaimed from the perspective of the fiber that called pulp_fiber_get_mailslot(). When the sleeping fiber wakes and returns from its mailbox-enabled sleep call, it simply looks at the count member of the mailbox to see if any mail was received. It's up to the implementation what is done with the contents of the mailbox. The mailbox count is always reset to 0 automatically at the start of a mailbox-enabled sleep.
2018-05-13libpulp: add pulp_self() current fiber accessorVito Caputo
Analogous to pthread_self()
2018-05-03libpulp: forward declare thunk_t, omit thunk.hVito Caputo
Let the user of pulp.h control how they get at this struct, our libthunk submodule fulfills our implementation needs but the caller's build architecture should be free to fulfill this type however it wants - there may be no thunk.h at all but they still would include pulp.h.
2018-05-02*: initial commit of libpulpVito Caputo
libpulp is a very basic cooperatively-scheduled userspace threading library. It refers to the userspace threads as fibers, and uses my other little library libthunk to bind the functions and their calling environment into tidy little structures having a uniform calling convention. At this time there's no build system or anything of the sort, it's early days and I'll probably be submoduling this into another project for direct inclusion and compilation.
© All Rights Reserved