ST / ST_Events-old

Dependents:   HelloWorld_CCA01M1 HelloWorld_CCA02M1 CI-data-logger-server HelloWorld_CCA02M1 ... more

This is a fork of the events subdirectory of https://github.com/ARMmbed/mbed-os.

Note, you must import this library with import name: events!!!

Files at this revision

API Documentation at this revision

Comitter:
Seppo Takalo
Date:
Wed Oct 05 16:09:58 2016 +0300
Parent:
201:dd058cec5f28
Child:
8543:3a7827632971
Commit message:
Squashed 'features/FEATURE_COMMON_PAL/mbed-trace/' changes from b17e969..31e338c

31e338c Use temp variable in mutex release loop (#52)

git-subtree-dir: features/FEATURE_COMMON_PAL/mbed-trace
git-subtree-split: 31e338c23934491fcb852ee4d2788d34851d01a2

Changed in this revision

source/mbed_trace.c Show annotated file Show diff for this revision Revisions of this file
--- a/source/mbed_trace.c	Mon Oct 03 14:40:33 2016 +0300
+++ b/source/mbed_trace.c	Wed Oct 05 16:09:58 2016 +0300
@@ -454,10 +454,20 @@
 
 end:
     if ( m_trace.mutex_release_f ) {
-        while (m_trace.mutex_lock_count > 0) {
-            m_trace.mutex_lock_count--;
+        // Store the mutex lock count to temp variable so that it won't get
+        // clobbered during last loop iteration when mutex gets released
+        int count = m_trace.mutex_lock_count;
+        m_trace.mutex_lock_count = 0;
+        // Since the helper functions (eg. mbed_trace_array) are used like this:
+        //   mbed_tracef(TRACE_LEVEL_INFO, "grp", "%s", mbed_trace_array(some_array))
+        // The helper function MUST acquire the mutex if it modifies any buffers. However
+        // it CANNOT unlock the mutex because that would allow another thread to acquire
+        // the mutex after helper function unlocks it and before mbed_tracef acquires it
+        // for itself. This means that here we have to unlock the mutex as many times
+        // as it was acquired by trace function and any possible helper functions.
+        do {
             m_trace.mutex_release_f();
-        }
+        } while (--count > 0);
     }
 }
 static void mbed_trace_reset_tmp(void)