Scheduler jobs.
burn/1 and hold/2 run on a dirty CPU scheduler. io_ping/0 runs on a
dirty I/O scheduler. An Elixir timeout does not cancel the native work.
Task.yield/2 returning nil means the caller stopped waiting. The native
function runs until it returns.
Summary
Functions
Spins for milliseconds on a dirty CPU scheduler, then returns :ok.
Copies bin, spins for milliseconds, and returns the same bytes.
Returns :ok from a dirty I/O scheduler.
Loads priv/native/libsched.so.
Functions
@spec burn(non_neg_integer()) :: :ok
Spins for milliseconds on a dirty CPU scheduler, then returns :ok.
milliseconds is an integer greater than or equal to 0. The loop reads the
monotonic clock. A caller timeout does not stop it.
Raises
ArgumentErrorwhenmillisecondsis not an integer, or is negative
Examples
iex> Mojoler.Sched.burn(0)
:ok
iex> Mojoler.Sched.burn(-1)
** (ArgumentError) argument error
@spec hold(binary(), non_neg_integer()) :: binary()
Copies bin, spins for milliseconds, and returns the same bytes.
The borrowed view of bin is released before the spin. The loop reads the
copy. milliseconds is an integer greater than or equal to 0.
Returns
The copied binary.
Raises
ArgumentErrorwhenbinis not a binary, ormillisecondsis not an integer greater than or equal to 0
Examples
iex> Mojoler.Sched.hold(<<1, 2, 3>>, 0)
<<1, 2, 3>>
iex> Mojoler.Sched.hold(<<1::7>>, 0)
** (ArgumentError) argument error
@spec io_ping() :: :ok
Returns :ok from a dirty I/O scheduler.
There are no arguments.
Examples
iex> Mojoler.Sched.io_ping()
:ok
@spec load_nif() :: :ok | {:error, term()}
Loads priv/native/libsched.so.
A second call returns {:error, {:reload, charlist}}.
Examples
iex> Mojoler.Sched.load_nif()
{:error, {:reload, ~c"NIF library already loaded (reload disallowed since OTP 20)."}}