summaryrefslogtreecommitdiff
path: root/src/pulp.c
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: remove now unused enter_context()Vito Caputo
2018-06-03libpulp: some assert cleanupsVito Caputo
2018-06-03libpulp: always swap contextsVito Caputo
In cases where the run queue was empty, the trampoline context would immediately enter the caller context. Then the trampoline would be reused again without being re-setup. This seemed to work fine on Linux but was causing bus errors on OSX. So instead now enter_context never used and contexts are always swapped to preserve the state of the context being left, which seems to have fixed the problem on OSX.
2018-05-16libpulp: experimental considerations for OSXVito Caputo
I don't have an OSX system to test with, but after some digging this looks like it might suffice.
2018-05-16libpulp: waking note in pulp_fiber_get_mailslot()Vito Caputo
2018-05-16libpulp: add win32 supportVito Caputo
This adds a rudimentary win32 implementation based on the fibers system API. It seems to work reasonably under wine when built w/mingw32.
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: move expire_alarms() to pulp_tick() beginVito Caputo
Expiring alarms of sleeping fibers in pulp_schedule() has the potential to prevent pulp_tick() from ever returning if there's always another fiber expiring @ schedule. In order to allow simple integration with external event loops, pulp_tick() is supposed to operate on what is essentially a slice of runnable fibers then immediately return control to the caller.
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