Skip to content

Commit 7385e53

Browse files
committed
fixup: avoid mutex naming unless tracing, remove extra delivery lock details
1 parent 72d852a commit 7385e53

File tree

4 files changed

+25
-34
lines changed

4 files changed

+25
-34
lines changed

src/posix/threading.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ static inline uint64_t timediff(const struct timespec start,
5555
return stop.tv_nsec + nsecs - start.tv_nsec;
5656
}
5757

58-
#define TRACE_INIT(M) \
58+
#define TRACE_INIT(M, N) \
5959
do { \
60+
(M)->name = qd_strdup((N)); \
6061
(M)->nsec_wait = 0; \
6162
(M)->lock_count = 0; \
6263
(M)->max_wait[0] = 0; \
@@ -65,15 +66,19 @@ static inline uint64_t timediff(const struct timespec start,
6566
} while (0);
6667

6768
#define TRACE_DUMP(M) \
68-
if ((M)->lock_count) { \
69-
fprintf(stderr, \
70-
"%30s: total(nsec)= %-10"PRIu64 \
71-
" avg= %-10"PRIu64" count= %-6"PRIu64 \
72-
" max= %"PRIu64" %"PRIu64" %"PRIu64"\n", \
73-
(M)->name, (M)->nsec_wait, \
74-
(M)->nsec_wait/(M)->lock_count, (M)->lock_count, \
75-
(M)->max_wait[0], (M)->max_wait[1], (M)->max_wait[2]); \
76-
}
69+
do { \
70+
if ((M)->lock_count) { \
71+
fprintf(stderr, \
72+
"%30s: total(nsec)= %-10"PRIu64 \
73+
" avg= %-10"PRIu64" count= %-6"PRIu64 \
74+
" max= %"PRIu64" %"PRIu64" %"PRIu64"\n", \
75+
(M)->name, (M)->nsec_wait, \
76+
(M)->nsec_wait/(M)->lock_count, (M)->lock_count, \
77+
(M)->max_wait[0], (M)->max_wait[1], \
78+
(M)->max_wait[2]); \
79+
} \
80+
free((M)->name); \
81+
} while (0)
7782

7883
#define TRACE_UPDATE(M,N) \
7984
if ((N) > 1000) { \
@@ -96,15 +101,15 @@ static inline uint64_t timediff(const struct timespec start,
96101
}
97102

98103
#else
99-
#define TRACE_INIT(M)
104+
#define TRACE_INIT(M, N) (void)(N)
100105
#define TRACE_DUMP(M)
101106
#endif
102107

103108

104109
struct sys_mutex_t {
105110
pthread_mutex_t mutex;
106-
char *name;
107111
#ifdef QD_TRACE_LOCK_CONTENTION
112+
char *name;
108113
uint64_t nsec_wait;
109114
uint64_t lock_count;
110115
uint64_t max_wait[3];
@@ -117,10 +122,9 @@ sys_mutex_t *sys_mutex(const char *name)
117122
sys_mutex_t *mutex = 0;
118123
NEW_CACHE_ALIGNED(sys_mutex_t, mutex);
119124
_CHECK(mutex != 0);
120-
mutex->name = qd_strdup(name);
121125
int result = pthread_mutex_init(&(mutex->mutex), 0);
122126
_CHECK(result == 0);
123-
TRACE_INIT(mutex);
127+
TRACE_INIT(mutex, name);
124128
return mutex;
125129
}
126130

@@ -130,7 +134,6 @@ void sys_mutex_free(sys_mutex_t *mutex)
130134
int result = pthread_mutex_destroy(&(mutex->mutex));
131135
_CHECK(result == 0);
132136
TRACE_DUMP(mutex);
133-
free(mutex->name);
134137
free(mutex);
135138
}
136139

@@ -206,8 +209,8 @@ void sys_cond_signal_all(sys_cond_t *cond)
206209

207210
struct sys_rwlock_t {
208211
pthread_rwlock_t lock;
209-
char *name;
210212
#ifdef QD_TRACE_LOCK_CONTENTION
213+
char *name;
211214
uint64_t nsec_wait;
212215
uint64_t lock_count;
213216
uint64_t max_wait[3];
@@ -218,10 +221,9 @@ struct sys_rwlock_t {
218221
sys_rwlock_t *sys_rwlock(const char *name)
219222
{
220223
sys_rwlock_t *lock = NEW(sys_rwlock_t);
221-
lock->name = qd_strdup(name);
222224
int result = pthread_rwlock_init(&(lock->lock), 0);
223225
_CHECK(result == 0);
224-
TRACE_INIT(lock);
226+
TRACE_INIT(lock, name);
225227
return lock;
226228
}
227229

@@ -231,7 +233,6 @@ void sys_rwlock_free(sys_rwlock_t *lock)
231233
int result = pthread_rwlock_destroy(&(lock->lock));
232234
_CHECK(result == 0);
233235
TRACE_DUMP(lock);
234-
free(lock->name);
235236
free(lock);
236237
}
237238

src/router_core/core_link_endpoint.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ qdr_delivery_t *qdrc_endpoint_delivery_CT(qdr_core_t *core, qdrc_endpoint_t *end
147147
dlv->delivery_id = next_delivery_id();
148148
dlv->link_id = endpoint->link->identity;
149149
dlv->conn_id = endpoint->link->conn_id;
150-
char name[64];
151-
snprintf(name, sizeof(name), "delivery-%"PRIu32, dlv->delivery_id);
152-
dlv->dispo_lock = sys_mutex(name);
150+
dlv->dispo_lock = sys_mutex("dlv-dispo");
153151
qd_log(core->log, QD_LOG_DEBUG, DLV_FMT" Delivery created qdrc_endpoint_delivery_CT", DLV_ARGS(dlv));
154152
return dlv;
155153
}

src/router_core/forwarder.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ qdr_delivery_t *qdr_forward_new_delivery_CT(qdr_core_t *core, qdr_delivery_t *in
154154
out_dlv->delivery_id = next_delivery_id();
155155
out_dlv->link_id = out_link->identity;
156156
out_dlv->conn_id = out_link->conn_id;
157-
char name[64];
158-
snprintf(name, sizeof(name), "delivery-%"PRIu32, out_dlv->delivery_id);
159-
out_dlv->dispo_lock = sys_mutex(name);
157+
out_dlv->dispo_lock = sys_mutex("dlv-dispo");
160158
qd_log(core->log, QD_LOG_DEBUG, DLV_FMT" Delivery created qdr_forward_new_delivery_CT", DLV_ARGS(out_dlv));
161159

162160
if (in_dlv) {

src/router_core/transfer.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ qdr_delivery_t *qdr_link_deliver(qdr_link_t *link, qd_message_t *msg, qd_iterato
5959
dlv->delivery_id = next_delivery_id();
6060
dlv->link_id = link->identity;
6161
dlv->conn_id = link->conn_id;
62-
char name[64];
63-
snprintf(name, sizeof(name), "delivery-%"PRIu32, dlv->delivery_id);
64-
dlv->dispo_lock = sys_mutex(name);
62+
dlv->dispo_lock = sys_mutex("dlv-dispo");
6563
qd_log(link->core->log, QD_LOG_DEBUG, DLV_FMT" Delivery created qdr_link_deliver", DLV_ARGS(dlv));
6664

6765
qdr_delivery_incref(dlv, "qdr_link_deliver - newly created delivery, add to action list");
@@ -97,9 +95,7 @@ qdr_delivery_t *qdr_link_deliver_to(qdr_link_t *link, qd_message_t *msg,
9795
dlv->delivery_id = next_delivery_id();
9896
dlv->link_id = link->identity;
9997
dlv->conn_id = link->conn_id;
100-
char name[64];
101-
snprintf(name, sizeof(name), "delivery-%"PRIu32, dlv->delivery_id);
102-
dlv->dispo_lock = sys_mutex(name);
98+
dlv->dispo_lock = sys_mutex("dlv-dispo");
10399
qd_log(link->core->log, QD_LOG_DEBUG, DLV_FMT" Delivery created qdr_link_deliver_to", DLV_ARGS(dlv));
104100

105101
qdr_delivery_incref(dlv, "qdr_link_deliver_to - newly created delivery, add to action list");
@@ -130,9 +126,7 @@ qdr_delivery_t *qdr_link_deliver_to_routed_link(qdr_link_t *link, qd_message_t *
130126
dlv->delivery_id = next_delivery_id();
131127
dlv->link_id = link->identity;
132128
dlv->conn_id = link->conn_id;
133-
char name[64];
134-
snprintf(name, sizeof(name), "delivery-%"PRIu32, dlv->delivery_id);
135-
dlv->dispo_lock = sys_mutex(name);
129+
dlv->dispo_lock = sys_mutex("dlv-dispo");
136130
qd_log(link->core->log, QD_LOG_DEBUG, DLV_FMT" Delivery created qdr_link_deliver_to_routed_link", DLV_ARGS(dlv));
137131

138132
qdr_delivery_incref(dlv, "qdr_link_deliver_to_routed_link - newly created delivery, add to action list");

0 commit comments

Comments
 (0)