[erlang-patches] [PATCH] erts: mtrace: use mutex lock correctly
Jovi Zhang
bookjovi@REDACTED
Fri Dec 23 10:16:37 CET 2011
>From 6ef85dd92e7bbf9de4dbb4d676348023458481d8 Mon Sep 17 00:00:00 2001
From: Jovi Zhang <bookjovi@REDACTED>
Date: Fri, 16 Dec 2011 04:54:49 +0800
Subject: [PATCH] erts: mtrace: use mutex lock correctly
mtrace_op_mutex and mtrace_buf_mutex should be use under
protect of erts_mtrace_enabled
---
erts/emulator/beam/erl_mtrace.c | 33 +++++++++++++++++++--------------
1 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/erts/emulator/beam/erl_mtrace.c b/erts/emulator/beam/erl_mtrace.c
index 358c67b..c97ac5b 100644
--- a/erts/emulator/beam/erl_mtrace.c
+++ b/erts/emulator/beam/erl_mtrace.c
@@ -641,9 +641,10 @@ erts_mtrace_install_wrapper_functions(void)
void
erts_mtrace_stop(void)
{
- erts_mtx_lock(&mtrace_op_mutex);
- erts_mtx_lock(&mtrace_buf_mutex);
if (erts_mtrace_enabled) {
+ erts_mtx_lock(&mtrace_op_mutex);
+ erts_mtx_lock(&mtrace_buf_mutex);
+
Uint32 ti = get_time_inc();
if (ti != INVALID_TIME_INC
@@ -669,17 +670,18 @@ erts_mtrace_stop(void)
socket_desc = ERTS_SOCK_INVALID_SOCKET;
}
}
+ erts_mtx_unlock(&mtrace_buf_mutex);
+ erts_mtx_unlock(&mtrace_op_mutex);
}
- erts_mtx_unlock(&mtrace_buf_mutex);
- erts_mtx_unlock(&mtrace_op_mutex);
}
void
erts_mtrace_exit(Uint32 exit_value)
{
- erts_mtx_lock(&mtrace_op_mutex);
- erts_mtx_lock(&mtrace_buf_mutex);
if (erts_mtrace_enabled) {
+ erts_mtx_lock(&mtrace_op_mutex);
+ erts_mtx_lock(&mtrace_buf_mutex);
+
Uint32 ti = get_time_inc();
if (ti != INVALID_TIME_INC
@@ -709,9 +711,9 @@ erts_mtrace_exit(Uint32 exit_value)
socket_desc = ERTS_SOCK_INVALID_SOCKET;
}
}
+ erts_mtx_unlock(&mtrace_buf_mutex);
+ erts_mtx_unlock(&mtrace_op_mutex);
}
- erts_mtx_unlock(&mtrace_buf_mutex);
- erts_mtx_unlock(&mtrace_op_mutex);
}
static ERTS_INLINE void
@@ -721,8 +723,9 @@ write_alloc_entry(byte tag,
ErtsAlcType_t y,
Uint size)
{
- erts_mtx_lock(&mtrace_buf_mutex);
if (erts_mtrace_enabled) {
+ erts_mtx_lock(&mtrace_buf_mutex);
+
Uint32 ti = get_time_inc();
if (ti != INVALID_TIME_INC
@@ -784,8 +787,8 @@ write_alloc_entry(byte tag,
}
+ erts_mtx_unlock(&mtrace_buf_mutex);
}
- erts_mtx_unlock(&mtrace_buf_mutex);
}
@@ -797,8 +800,9 @@ write_realloc_entry(byte tag,
void *ptr,
Uint size)
{
- erts_mtx_lock(&mtrace_buf_mutex);
if (erts_mtrace_enabled) {
+ erts_mtx_lock(&mtrace_buf_mutex);
+
Uint32 ti = get_time_inc();
if (ti != INVALID_TIME_INC
@@ -864,8 +868,8 @@ write_realloc_entry(byte tag,
#endif
}
+ erts_mtx_unlock(&mtrace_buf_mutex);
}
- erts_mtx_unlock(&mtrace_buf_mutex);
}
static ERTS_INLINE void
@@ -874,8 +878,9 @@ write_free_entry(byte tag,
ErtsAlcType_t y,
void *ptr)
{
- erts_mtx_lock(&mtrace_buf_mutex);
if (erts_mtrace_enabled) {
+ erts_mtx_lock(&mtrace_buf_mutex);
+
Uint32 ti = get_time_inc();
if (ti != INVALID_TIME_INC
@@ -931,8 +936,8 @@ write_free_entry(byte tag,
#endif
}
+ erts_mtx_unlock(&mtrace_buf_mutex);
}
- erts_mtx_unlock(&mtrace_buf_mutex);
}
static void *
--
1.7.2.3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-erts-mtrace-use-mutex-lock-correctly.patch
Type: application/octet-stream
Size: 3199 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20111223/dd2ac433/attachment.obj>
More information about the erlang-patches
mailing list