ovs-thread: Issue better diagnostics for locking uninitialized mutexes.
authorBen Pfaff <blp@nicira.com>
Thu, 8 May 2014 16:20:09 +0000 (09:20 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 8 May 2014 16:20:09 +0000 (09:20 -0700)
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>
lib/ovs-thread.c

index fbdd7fc..49b3474 100644 (file)
@@ -55,11 +55,14 @@ static bool multithreaded;
         int error; \
  \
         /* 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); \
         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; \
  }
@@ -77,11 +80,14 @@ LOCK_FUNCTION(rwlock, wrlock);
         int error; \
  \
         /* 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); \
         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) { \
             l->where = where; \