diff options
author | Ahmad Sharif <asharif@google.com> | 2012-12-06 20:09:25 +0000 |
---|---|---|
committer | Ahmad Sharif <asharif@google.com> | 2012-12-06 20:09:25 +0000 |
commit | 35c83150ddcbd7c6ef0c0f6191afe10dd38befa4 (patch) | |
tree | 8b5b421f8f51776c8a1b289f275905d273c54b75 /libgcc/libgcov.c | |
parent | 62d98723246e244ea0c37f3d201938799c7b5b03 (diff) |
2012-12-03 Ahmad Sharif <asharif@google.com>
Backport r185231 from trunk.
2012-03-12 Richard Guenther <rguenther@suse.de>
* gthr.h (__GTHREAD_MUTEX_INIT_FUNCTION): Adjust specification.
* gthr-posix.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define.
(__gthread_mutex_init_function): New function.
* gthr-single.h (__GTHREAD_MUTEX_INIT_FUNCTION): Define.
PR gcov/49484
* libgcov.c: Include gthr.h.
(__gcov_flush_mx): New global variable.
(init_mx, init_mx_once): New functions.
(__gcov_flush): Protect self with a mutex.
(__gcov_fork): Re-initialize mutex after forking.
* unwind-dw2-fde.c: Change condition under which to use
__GTHREAD_MUTEX_INIT_FUNCTION.
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/google/gcc-4_7@194264 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgcc/libgcov.c')
-rw-r--r-- | libgcc/libgcov.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/libgcc/libgcov.c b/libgcc/libgcov.c index fa61e23ddef..262161971bd 100644 --- a/libgcc/libgcov.c +++ b/libgcc/libgcov.c @@ -48,6 +48,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "tm.h" #endif /* __KERNEL__ */ #include "libgcc_tm.h" +#include "gthr.h" #if 1 #define THREAD_PREFIX __thread @@ -759,6 +760,25 @@ __gcov_init (struct gcov_info *info) info->version = 0; } +#ifdef __GTHREAD_MUTEX_INIT +ATTRIBUTE_HIDDEN __gthread_mutex_t __gcov_flush_mx = __GTHREAD_MUTEX_INIT; +#define init_mx_once() +#else +__gthread_mutex_t __gcov_flush_mx ATTRIBUTE_HIDDEN; + +static void +init_mx (void) +{ + __GTHREAD_MUTEX_INIT_FUNCTION (&mx); +} +static void +init_mx_once (void) +{ + static __gthread_once_t once = __GTHREAD_ONCE_INIT; + __gthread_once (&once, init_mx); +} +#endif + /* Called before fork or exec - write out profile information gathered so far and reset it to zero. This avoids duplication or loss of the profile information gathered so far. */ @@ -766,8 +786,13 @@ __gcov_init (struct gcov_info *info) void __gcov_flush (void) { + init_mx_once (); + __gthread_mutex_lock (&__gcov_flush_mx); + gcov_exit (); gcov_clear (); + + __gthread_mutex_unlock (&__gcov_flush_mx); } #else /* __GCOV_KERNEL__ */ @@ -1836,8 +1861,13 @@ __gcov_ior_profiler (gcov_type *counters, gcov_type value) pid_t __gcov_fork (void) { + pid_t pid; + extern __gthread_mutex_t __gcov_flush_mx; __gcov_flush (); - return fork (); + pid = fork (); + if (pid == 0) + __GTHREAD_MUTEX_INIT_FUNCTION (&__gcov_flush_mx); + return pid; } #endif |