this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Inject scheduler_pid directly in Scheduler spawn

+9 -12
+7 -1
lib/construct/scheduler.ex
··· 351 351 352 352 defp perform(%State{} = state, %Spawn{} = spawn) do 353 353 parent_pid = spawn.parent_resume.pid 354 - child_pid = spawn(spawn.module, spawn.function, spawn.args) 354 + 355 + scheduler_pid = self() 356 + %Spawn{module: m, function: f, args: a} = spawn 357 + child_pid = spawn(fn -> 358 + Hobbes.Construct.SimServer.set_scheduler_pid(scheduler_pid) 359 + apply(m, f, a) 360 + end) 355 361 356 362 ProcStore.add_process(state.proc_store, child_pid) 357 363 if spawn.link, do: ProcStore.add_link(state.proc_store, parent_pid, child_pid)
-2
lib/construct/sim_internal.ex
··· 30 30 31 31 def server_init(module, arg, _options, parent, scheduler_pid) 32 32 when is_atom(module) and is_pid(parent) and is_pid(scheduler_pid) do 33 - SimServer.set_scheduler_pid(scheduler_pid) 34 - 35 33 {:ok, initial_state} = module.init(arg) 36 34 Scheduler.send(scheduler_pid, parent, {:ack, self()}) 37 35
+2 -9
lib/construct/sim_server.ex
··· 267 267 def spawn(fun) when is_function(fun) do 268 268 case get_scheduler_pid() do 269 269 scheduler_pid when is_pid(scheduler_pid) -> 270 - Scheduler.spawn_and_yield(scheduler_pid, :nolink, __MODULE__, :sim_apply, [scheduler_pid, fun, []]) 270 + Scheduler.spawn_and_yield(scheduler_pid, :nolink, Kernel, :apply, [fun, []]) 271 271 nil -> 272 272 Kernel.spawn(fun) 273 273 end ··· 277 277 def spawn_link(fun) when is_function(fun) do 278 278 case get_scheduler_pid() do 279 279 scheduler_pid when is_pid(scheduler_pid) -> 280 - Scheduler.spawn_and_yield(scheduler_pid, :link, __MODULE__, :sim_apply, [scheduler_pid, fun, []]) 280 + Scheduler.spawn_and_yield(scheduler_pid, :link, Kernel, :apply, [fun, []]) 281 281 nil -> 282 282 Kernel.spawn_link(fun) 283 283 end 284 - end 285 - 286 - @doc false 287 - # Like apply/2 but also injects the scheduler_pid into the child process 288 - def sim_apply(scheduler_pid, fun, args) when is_pid(scheduler_pid) and is_function(fun) do 289 - set_scheduler_pid(scheduler_pid) 290 - apply(fun, args) 291 284 end 292 285 293 286 @spec sleep(non_neg_integer) :: term