@ -87,10 +87,12 @@ sandbox_io_nowait(void)
}
struct sandbox *
sandbox_schedule ( void )
sandbox_schedule ( int interrupt )
{
struct sandbox * s = NULL ;
if ( ps_list_head_empty ( & runq ) ) {
// this is in an interrupt context, don't steal work here!
if ( interrupt ) return NULL ;
if ( sandbox_pull ( ) = = 0 ) {
//debuglog("[null: null]\n");
return NULL ;
@ -130,7 +132,7 @@ sandbox_schedule_io(void)
if ( ! in_callback ) sandbox_io_nowait ( ) ;
softint_disable ( ) ;
struct sandbox * s = sandbox_schedule ( ) ;
struct sandbox * s = sandbox_schedule ( 0 ) ;
softint_enable ( ) ;
assert ( s = = NULL | | s - > state = = SANDBOX_RUNNABLE ) ;
@ -143,11 +145,12 @@ sandbox_wakeup(sandbox_t *s)
# ifndef STANDALONE
softint_disable ( ) ;
debuglog ( " [%p: %s] \n " , s , s - > mod - > name ) ;
// perhaps 2 lists in the sandbox to make sure sandbox is either in runlist or waitlist..
if ( s - > state ! = SANDBOX_BLOCKED ) goto done ;
assert ( s - > state = = SANDBOX_BLOCKED ) ;
assert ( ps_list_singleton_d ( s ) ) ;
s - > state = SANDBOX_RUNNABLE ;
ps_list_head_append_d ( & runq , s ) ;
done :
softint_enable ( ) ;
# endif
}
@ -156,13 +159,12 @@ void
sandbox_block ( void )
{
# ifndef STANDALONE
// perhaps 2 lists in the sandbox to make sure sandbox is either in runlist or waitlist..
assert ( in_callback = = 0 ) ;
softint_disable ( ) ;
struct sandbox * c = sandbox_current ( ) ;
ps_list_rem_d ( c ) ;
c - > state = SANDBOX_BLOCKED ;
struct sandbox * s = sandbox_schedule ( ) ;
struct sandbox * s = sandbox_schedule ( 0 ) ;
debuglog ( " [%p: %s, %p: %s] \n " , c , c - > mod - > name , s , s ? s - > mod - > name : " " ) ;
softint_enable ( ) ;
sandbox_switch ( s ) ;
@ -171,6 +173,24 @@ sandbox_block(void)
# endif
}
void
sandbox_block_http ( void )
{
# ifdef USE_HTTP_UVIO
# ifdef USE_HTTP_SYNC
// realistically, we're processing all async I/O on this core when a sandbox blocks on http processing, not great!
// if there is a way (TODO), perhaps RUN_ONCE and check if your I/O is processed, if yes, return
// else do async block!
uv_run ( runtime_uvio ( ) , UV_RUN_DEFAULT ) ;
# else
sandbox_block ( ) ;
# endif
# else
assert ( 0 ) ;
//it should not be called if not using uvio for http
# endif
}
void __attribute__ ( ( noinline ) ) __attribute__ ( ( noreturn ) )
sandbox_switch_preempt ( void )
{
@ -248,7 +268,7 @@ sandbox_exit(void)
sandbox_local_stop ( curr ) ;
curr - > state = SANDBOX_RETURNED ;
// free resources from "main function execution", as stack still in use.
struct sandbox * n = sandbox_schedule ( ) ;
struct sandbox * n = sandbox_schedule ( 0 ) ;
assert ( n ! = curr ) ;
softint_enable ( ) ;
//sandbox_local_end(curr);