diff options
Diffstat (limited to 'src/pulp.c')
-rw-r--r-- | src/pulp.c | 31 |
1 files changed, 17 insertions, 14 deletions
@@ -311,6 +311,20 @@ static pulp_usec_t now(void) } +/* initialize the pulp library */ +/* Call this prior to calling any other pulp functions. + * Returns 0 on success, negative value on error. + */ +int pulp_init(void) +{ +#ifdef __WIN32__ + if (!ConvertThreadToFiber(NULL)) + return -1; +#endif + return 0; +} + + /* create a new pulp scheduler instance */ pulp_t * pulp_new(void) { @@ -415,21 +429,10 @@ int pulp_tick(pulp_t *pulp, unsigned *next_tick_delay_us) expire_alarms(pulp); #ifdef __WIN32__ - /* XXX: Hopefully it's not too expensive on win32 to become fiberized - * then unfiberized on every tick. I'm doing it this way because - * employing multiple pulp_t instances in the same process is a use - * case I wish to support. There's value in being able to have e.g. - * a set of fibers for one game context which are only ticked when that - * context is active/visible, but otherwise has its state kept around - * in stasis while any number of other pulp_t intances get ticked when - * active. - */ - pulp->caller_context.win32_fiber = ConvertThreadToFiber(NULL); - swap_context(&pulp->caller_context, &pulp->trampoline_context); - ConvertFiberToThread(); -#else - swap_context(&pulp->caller_context, &pulp->trampoline_context); + /* TODO: maybe just move to win32 swap_context()? */ + pulp->caller_context.win32_fiber = GetCurrentFiber(); #endif + swap_context(&pulp->caller_context, &pulp->trampoline_context); if (pulp->exited) return -1; |