From patchwork Fri Jul 2 19:49:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [gccgo] Initialize mutexes Date: Fri, 02 Jul 2010 09:49:39 -0000 From: Ian Taylor X-Patchwork-Id: 57764 Message-Id: To: gcc-patches@gcc.gnu.org This patch from Vinu Rajashekhar ensures that all mutexes in libgo are initialized. Committed to gccgo branch. Ian diff -r 960b7647b1da libgo/runtime/mfinal.c --- a/libgo/runtime/mfinal.c Fri Jul 02 09:53:03 2010 -0700 +++ b/libgo/runtime/mfinal.c Fri Jul 02 12:46:46 2010 -0700 @@ -5,7 +5,7 @@ #include "runtime.h" #include "malloc.h" -Lock finlock; +Lock finlock = LOCK_INITIALIZER; // Finalizer hash table. Direct hash, linear scan, at most 3/4 full. // Table size is power of 3 so that hash can be key % max. diff -r 960b7647b1da libgo/runtime/mprof.goc --- a/libgo/runtime/mprof.goc Fri Jul 02 09:53:03 2010 -0700 +++ b/libgo/runtime/mprof.goc Fri Jul 02 12:46:46 2010 -0700 @@ -14,7 +14,7 @@ typedef struct __go_open_array Slice; // NOTE(rsc): Everything here could use cas if contention became an issue. -static Lock proflock; +static Lock proflock = LOCK_INITIALIZER; // Per-call-stack allocation information. // Lookup by hashing call stack into a linked-list hash table. diff -r 960b7647b1da libgo/runtime/runtime.h --- a/libgo/runtime/runtime.h Fri Jul 02 09:53:03 2010 -0700 +++ b/libgo/runtime/runtime.h Fri Jul 02 12:46:46 2010 -0700 @@ -111,8 +111,8 @@ * mutual exclusion locks. in the uncontended case, * as fast as spin locks (just a few user-level instructions), * but on the contention path they sleep in the kernel. - * a zeroed Lock is unlocked (no need to initialize each lock). */ +#define LOCK_INITIALIZER { PTHREAD_MUTEX_INITIALIZER } void initlock(Lock*); void lock(Lock*); void unlock(Lock*);