[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xine-cvslog
Subject:    [xine-cvs] =?utf-8?q?HG=3A_xine-lib-1=2E2=3A_Fix_race_in_profiler?= =?utf-8?q?_slot_allocation?=
From:       Petri_Hintukainen via Xine-cvslog <xine-cvslog () lists ! sourceforge ! net
Date:       2017-09-27 7:21:57
Message-ID: 3057a551467b382988f5.1506167802 () hg ! debian ! org
[Download RAW message or body]

# HG changeset patch
# User Petri Hintukainen <phintuka@users.sourceforge.net>
# Date 1506167802 -10800
# Node ID 3057a551467b382988f565f00118ca036139f35c
# Branch  default
# Parent  d842c1a22f83584b58cfbd5555500a92b4e3c1e4
Fix race in profiler slot allocation

diff --git a/src/xine-utils/monitor.c b/src/xine-utils/monitor.c
--- a/src/xine-utils/monitor.c
+++ b/src/xine-utils/monitor.c
@@ -40,21 +40,31 @@
 } xine_profiler_t;
 
 static xine_profiler_t profiler[MAX_ID];
+static pthread_mutex_t profiler_lock = PTHREAD_MUTEX_INITIALIZER;
 
 void xine_profiler_init () {
+  pthread_mutex_lock(&profiler_lock);
   memset(profiler, 0, sizeof(profiler));
+  pthread_mutex_unlock(&profiler_lock);
 }
 
 int xine_profiler_allocate_slot (const char *label) {
   int id;
 
+  pthread_mutex_lock(&profiler_lock);
+
   for (id = 0; id < MAX_ID && profiler[id].p_label != NULL; id++)
     ;
 
-  if (id >= MAX_ID)
+  if (id >= MAX_ID) {
+    pthread_mutex_unlock(&profiler_lock);
     return -1;
+  }
 
   profiler[id].p_label = label;
+
+  pthread_mutex_unlock(&profiler_lock);
+
   return id;
 }
 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Xine-cvslog mailing list
Xine-cvslog@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xine-cvslog
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic