Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync traps #103

Merged
merged 7 commits into from Nov 12, 2016
Merged

Sync traps #103

merged 7 commits into from Nov 12, 2016

Conversation

njsmith
Copy link
Contributor

@njsmith njsmith commented Nov 12, 2016

Refactor trap internals to formalize the distinction between regular and "synchronous" traps. See #101 for motivation. Also convert the "obvious" traps to make them sync traps.

Specifically, the following traps are made sync:

  • adjust_cancel_defer_depth
  • get_kernel
  • get_current
  • set_timeout
  • unset_timeout
  • queue_reschedule_function
  • clock
  • sigwatch
  • sigunwatch

The following traps in principle could be made sync, but either there's some complication or it isn't obvious whether those are actually the semantics we want, so I left them alone for now:

  • cancel_task
  • spawn
  • reschedule_tasks

When switching traps to make them synchronous I also renamed them. This isn't at all mandatory, but since the name of the trap = the name of the trap handler function, and sync trap handlers have a different calling convention than regular trap handlers, I thought it was helpful to have that reminder in the name of which kind of handler we're implementing.

This also contains some small cleanups to regular trap handling and adds some missing docs.

Adds a SyncTraps enum, and refactors various bits of the trap code to
simplify it in general -- in particular, drops the useless 0th argument
to every trap.

Doesn't yet contain any code to call a sync trap, or any sync trap
implementations.
And convert _trap_adjust_cancel_depth to use the new calling mechanism,
as a kind of proof-of-concept.
This covers all the obvious ones. There are a few that could become sync
traps, but where things are a bit more complicated:

- _trap_cancel_task is synchronous in most cases... except that
  sometimes it yields while waiting for the other task to block on a
  cancellation point. Probably this should be fixed

- _trap_reschedule_tasks has a synchronous kind of feel -- it marks some
  other task(s) as runnable, and never needs to block. But there are
  tests that fail if we return immediately without rescheduling.

- _trap_spawn: it could be synchronous, but there are a few options here
  and it's not clear which is better. Options include at least: (a)
  Always return immediately. (b) Always run the child task until its
  first blocking point before resuming the parent task. (c) Don't
  provide any guarantees any way.

So we'll defer those for now...
Also add docs for some undocumented traps
See test case -- you'd expect sleep(0) to yield the event loop and give
other things a chance to run, but it didn't quite work before.
@njsmith
Copy link
Contributor Author

njsmith commented Nov 12, 2016

Just did the poor-form thing and added some small cleanups and an only-semi-related bug fix here... I can split them off if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants