diff options
| author | Frank Warmerdam <warmerdam@pobox.com> | 2013-06-19 22:50:54 +0000 |
|---|---|---|
| committer | Frank Warmerdam <warmerdam@pobox.com> | 2013-06-19 22:50:54 +0000 |
| commit | 636454c531884ec3bb43147a0600f9430cc58aaa (patch) | |
| tree | adfbedb8b240482f175db8ea91d1c07712b4ac07 /src/pj_mutex.c | |
| parent | a12351d73508608107be0c846b377b567ea7a748 (diff) | |
| download | PROJ-636454c531884ec3bb43147a0600f9430cc58aaa.tar.gz PROJ-636454c531884ec3bb43147a0600f9430cc58aaa.zip | |
ensure core mutex created in recursive mode, forces use of -lpthread
git-svn-id: http://svn.osgeo.org/metacrs/proj/trunk@2339 4e78687f-474d-0410-85f9-8d5e500ac6b2
Diffstat (limited to 'src/pj_mutex.c')
| -rw-r--r-- | src/pj_mutex.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/pj_mutex.c b/src/pj_mutex.c index 39cedbc4..60a8e1aa 100644 --- a/src/pj_mutex.c +++ b/src/pj_mutex.c @@ -96,7 +96,9 @@ void pj_cleanup_lock() #include "pthread.h" -static pthread_mutex_t pj_core_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t pj_precreated_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t pj_core_lock; +static int pj_core_lock_created = 0; /************************************************************************/ /* pj_acquire_lock() */ @@ -106,6 +108,25 @@ static pthread_mutex_t pj_core_lock = PTHREAD_MUTEX_INITIALIZER; void pj_acquire_lock() { + if (!pj_core_lock_created) { + /* + ** We need to ensure the core mutex is created in recursive mode + ** and there is no portable way of doing that using automatic + ** initialization so we have pj_precreated_lock only for the purpose + ** of protecting the creation of the core lock. + */ + pthread_mutexattr_t mutex_attr; + + pthread_mutex_lock( &pj_precreated_lock); + + pthread_mutexattr_init(&mutex_attr); + pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&pj_core_lock, &mutex_attr); + pj_core_lock_created = 1; + + pthread_mutex_unlock( &pj_precreated_lock ); + } + pthread_mutex_lock( &pj_core_lock); } @@ -193,4 +214,3 @@ static void pj_init_lock() } #endif // def MUTEX_win32 - |
