From: David Schleef Date: Sun, 28 Aug 2011 03:51:37 +0000 (-0700) Subject: Protect codemem globals with mutex X-Git-Tag: orc-0.4.15~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b06d6f77247a37db49c7ca0ff582e0e47c7ff11f;p=platform%2Fupstream%2Forc.git Protect codemem globals with mutex --- diff --git a/orc/orccodemem.c b/orc/orccodemem.c index 032f7fc..f470be5 100644 --- a/orc/orccodemem.c +++ b/orc/orccodemem.c @@ -120,10 +120,12 @@ orc_code_region_get_free_chunk (int size) OrcCodeRegion *region; OrcCodeChunk *chunk; + orc_global_mutex_lock (); for(i=0;ichunks; chunk; chunk = chunk->next) { if (!chunk->used && size <= chunk->size) { + orc_global_mutex_unlock (); return chunk; } } @@ -137,9 +139,11 @@ orc_code_region_get_free_chunk (int size) for(chunk = region->chunks; chunk; chunk = chunk->next) { if (!chunk->used && size <= chunk->size){ + orc_global_mutex_unlock (); return chunk; } } + orc_global_mutex_unlock (); ORC_ASSERT(0); diff --git a/orc/orconce.c b/orc/orconce.c index bcc7a1b..86315c1 100644 --- a/orc/orconce.c +++ b/orc/orconce.c @@ -12,6 +12,7 @@ #include static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t global_mutex = PTHREAD_MUTEX_INITIALIZER; void orc_once_mutex_lock (void) @@ -25,11 +26,24 @@ orc_once_mutex_unlock (void) pthread_mutex_unlock (&once_mutex); } +void +orc_global_mutex_lock (void) +{ + pthread_mutex_lock (&global_mutex); +} + +void +orc_global_mutex_unlock (void) +{ + pthread_mutex_unlock (&global_mutex); +} + #elif defined(HAVE_THREAD_WIN32) #include static CRITICAL_SECTION once_mutex; +static CRITICAL_SECTION global_mutex; void orc_once_mutex_lock (void) @@ -43,6 +57,18 @@ orc_once_mutex_unlock (void) LeaveCriticalSection (&once_mutex); } +void +orc_global_mutex_lock (void) +{ + EnterCriticalSection (&global_mutex); +} + +void +orc_global_mutex_unlock (void) +{ + LeaveCriticalSection (&global_mutex); +} + #ifdef _MSC_VER #pragma section(".CRT$XCU",read) @@ -51,6 +77,7 @@ static void __cdecl orc_once_cs_init (void) { InitializeCriticalSection (&once_mutex); + InitializeCriticalSection (&global_mutex); } __declspec(allocate(".CRT$XCU")) @@ -64,6 +91,7 @@ static void orc_once_cs_init (void) { InitializeCriticalSection (&once_mutex); + InitializeCriticalSection (&global_mutex); } #else diff --git a/orc/orcutils.h b/orc/orcutils.h index 9df479d..04b532a 100644 --- a/orc/orcutils.h +++ b/orc/orcutils.h @@ -185,6 +185,9 @@ char * get_tag_value (char *s, const char *tag); orc_int64 _strtoll (const char *nptr, char **endptr, int base); +void orc_global_mutex_lock (void); +void orc_global_mutex_unlock (void); + #endif ORC_END_DECLS