From 866438966dcdf6df25ba110e5b1814ced8b50436 Mon Sep 17 00:00:00 2001 From: Chris Freehill Date: Tue, 30 Jun 2020 15:12:58 -0500 Subject: [PATCH] Quiet spurious pthread_unlock warnings A message is output in debug builds when pthread_unlock returns an error. However, in most cases, it should return EPERM. In fact, if it doesn't return EPERM, it is an indication of a problem. This commit adjusts accordingly. Change-Id: Ia5cad89aa6e68e79c1291ea21adffb0fa68f2300 --- src/rocm_smi.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rocm_smi.cc b/src/rocm_smi.cc index 9d81ec5b1a..cc5102aa9c 100755 --- a/src/rocm_smi.cc +++ b/src/rocm_smi.cc @@ -460,11 +460,19 @@ rsmi_shut_down(void) { #if DEBUG int ret = 0; #endif - for (int i = 0; i < smi.monitor_devices().size(); ++i) { + for (uint32_t i = 0; i < smi.monitor_devices().size(); ++i) { #if DEBUG ret = pthread_mutex_unlock(smi.monitor_devices()[i]->mutex()); - std::cout << "pthread_mutex_unlock() returned " << ret << + if (ret != EPERM) { // We expect to get EPERM if the lock has already + // been released + if (ret == 0) { + std::cout << "WARNING: Unlocked monitor_devices lock; " << + "it should have already been unlocked." << std::endl; + } else { + std::cout << "WARNING: pthread_mutex_unlock() returned " << ret << " for device " << i << " in rsmi_shut_down()" << std::endl; + } + } #else (void)pthread_mutex_unlock(smi.monitor_devices()[i]->mutex()); #endif