2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-25 15:07:05 +00:00

ovs-thread: Issue better diagnostics for locking uninitialized mutexes.

This makes the message issued refer to the file and line that called
ovs_mutex_lock(), instead of to the file and line *inside*
ovs_mutex_lock().

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
This commit is contained in:
Ben Pfaff
2014-05-08 09:20:09 -07:00
parent fd1844891a
commit 6d765f17a8

View File

@@ -55,11 +55,14 @@ static bool multithreaded;
int error; \ int error; \
\ \
/* Verify that 'l' was initialized. */ \ /* Verify that 'l' was initialized. */ \
ovs_assert(l->where); \ if (OVS_UNLIKELY(!l->where)) { \
ovs_abort(0, "%s: %s() passed uninitialized ovs_"#TYPE, \
where, __func__); \
} \
\ \
error = pthread_##TYPE##_##FUN(&l->lock); \ error = pthread_##TYPE##_##FUN(&l->lock); \
if (OVS_UNLIKELY(error)) { \ if (OVS_UNLIKELY(error)) { \
ovs_abort(error, "pthread_%s_%s failed", #TYPE, #FUN); \ ovs_abort(error, "%s: pthread_%s_%s failed", where, #TYPE, #FUN); \
} \ } \
l->where = where; \ l->where = where; \
} }
@@ -77,11 +80,14 @@ LOCK_FUNCTION(rwlock, wrlock);
int error; \ int error; \
\ \
/* Verify that 'l' was initialized. */ \ /* Verify that 'l' was initialized. */ \
ovs_assert(l->where); \ if (OVS_UNLIKELY(!l->where)) { \
ovs_abort(0, "%s: %s() passed uninitialized ovs_"#TYPE, \
where, __func__); \
} \
\ \
error = pthread_##TYPE##_##FUN(&l->lock); \ error = pthread_##TYPE##_##FUN(&l->lock); \
if (OVS_UNLIKELY(error) && error != EBUSY) { \ if (OVS_UNLIKELY(error) && error != EBUSY) { \
ovs_abort(error, "pthread_%s_%s failed", #TYPE, #FUN); \ ovs_abort(error, "%s: pthread_%s_%s failed", where, #TYPE, #FUN); \
} \ } \
if (!error) { \ if (!error) { \
l->where = where; \ l->where = where; \