aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2016-06-13 10:08:47 +0200
committerLukas Larsson <[email protected]>2016-06-13 10:10:56 +0200
commit4e87bebe004039465548ed432d363f2d7e42fee6 (patch)
treeeeaa1d1fa4a91f5e90538a70448d54eaf20fda7e
parent7979f72ce15ec5eeb8e0e9cfc1c291f10c4f0432 (diff)
downloadotp-4e87bebe004039465548ed432d363f2d7e42fee6.tar.gz
otp-4e87bebe004039465548ed432d363f2d7e42fee6.tar.bz2
otp-4e87bebe004039465548ed432d363f2d7e42fee6.zip
erts: Allow enif_port_command in non-sched thread
It has to be possible to send trace messages to a port from non-schedulers threads (specifically from the sys_msg_dispatcher).
-rw-r--r--erts/emulator/beam/erl_nif.c25
-rw-r--r--erts/emulator/test/trace_port_SUITE.erl22
2 files changed, 31 insertions, 16 deletions
diff --git a/erts/emulator/beam/erl_nif.c b/erts/emulator/beam/erl_nif.c
index 039f97ef43..23931f0e54 100644
--- a/erts/emulator/beam/erl_nif.c
+++ b/erts/emulator/beam/erl_nif.c
@@ -769,32 +769,25 @@ enif_port_command(ErlNifEnv *env, const ErlNifPort* to_port,
if (scheduler > 0)
prt = erts_port_lookup(to_port->port_id, iflags);
-#ifdef ERTS_DIRTY_SCHEDULERS
- else if (scheduler < 0) {
+ else {
+#ifdef ERTS_SMP
if (ERTS_PROC_IS_EXITING(c_p))
return 0;
prt = erts_thr_port_lookup(to_port->port_id, iflags);
- }
+#else
+ erts_exit(ERTS_ABORT_EXIT,
+ "enif_port_command: called from non-scheduler "
+ "thread on non-SMP VM");
#endif
- else {
- erts_exit(ERTS_ABORT_EXIT, "enif_port_command: "
- "called from non-scheduler thread");
}
if (!prt)
res = 0;
- else {
-
- if (IS_TRACED_FL(prt, F_TRACE_RECEIVE))
- trace_port_receive(prt, c_p->common.id, am_command, msg);
-
- res = erts_port_output_async(prt, c_p->common.id, msg);
- }
+ else
+ res = erts_port_output_async(prt, c_p->common.id, msg);
-#ifdef ERTS_DIRTY_SCHEDULERS
- if (scheduler < 0)
+ if (scheduler <= 0)
erts_port_dec_refc(prt);
-#endif
return res;
}
diff --git a/erts/emulator/test/trace_port_SUITE.erl b/erts/emulator/test/trace_port_SUITE.erl
index a66563d15b..e4db368ea1 100644
--- a/erts/emulator/test/trace_port_SUITE.erl
+++ b/erts/emulator/test/trace_port_SUITE.erl
@@ -26,6 +26,7 @@
return_trace/1,
send/1,
receive_trace/1,
+ receive_trace_non_scheduler/1,
process_events/1,
schedule/1,
gc/1,
@@ -40,6 +41,7 @@ suite() ->
all() ->
[call_trace, return_trace, send, receive_trace,
+ receive_trace_non_scheduler,
process_events, schedule, gc,
default_tracer, tracer_port_crash].
@@ -184,6 +186,26 @@ receive_trace(Config) when is_list(Config) ->
expect({trace_ts,Receiver,'receive',Huge,ts}),
ok.
+%% Test sending receive traces to a port.
+receive_trace_non_scheduler(Config) when is_list(Config) ->
+ start_tracer(Config),
+ S = self(),
+ Receiver = spawn(
+ fun() ->
+ receive
+ go ->
+ Ref = S ! erlang:trace_delivered(all),
+ receive {trace_delivered, Ref, all} -> ok end
+ end
+ end),
+ trac(Receiver, true, ['receive']),
+ Receiver ! go,
+ Ref = receive R -> R end,
+ expect({trace,Receiver,'receive',go}),
+ expect({trace,Receiver,'receive',{trace_delivered, all, Ref}}),
+
+ ok.
+
%% Tests a few process events (like getting linked).
process_events(Config) when is_list(Config) ->
start_tracer(Config),