]> git.saurik.com Git - apple/dyld.git/blame - src/dyldLock.cpp
dyld-195.6.tar.gz
[apple/dyld.git] / src / dyldLock.cpp
CommitLineData
0959b6d4
A
1/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
bac542e6 3 * Copyright (c) 2004-2007 Apple Inc. All rights reserved.
0959b6d4
A
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25#include <pthread.h>
26
27#include "dyldLock.h"
28
0959b6d4
A
29
30
bac542e6 31static pthread_mutex_t sGlobalMutex;
0959b6d4 32
39a8cd10
A
33// <rdar://problem/6361143> Need a way to determine if a gdb call to dlopen() would block
34int __attribute__((visibility("hidden"))) _dyld_global_lock_held = 0;
35
0959b6d4
A
36
37//
bac542e6
A
38// This initializer can go away once the following is available:
39// <rdar://problem/4927311> implement PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
0959b6d4 40//
bac542e6 41void dyldGlobalLockInitialize()
0959b6d4 42{
bac542e6
A
43 pthread_mutexattr_t recursiveMutexAttr;
44 pthread_mutexattr_init(&recursiveMutexAttr);
45 pthread_mutexattr_settype(&recursiveMutexAttr, PTHREAD_MUTEX_RECURSIVE);
46 pthread_mutex_init(&sGlobalMutex, &recursiveMutexAttr);
0959b6d4
A
47}
48
0959b6d4 49
bac542e6 50LockHelper::LockHelper()
0959b6d4 51{
39a8cd10 52 dyldGlobalLockAcquire();
0959b6d4
A
53}
54
bac542e6 55LockHelper::~LockHelper()
0959b6d4 56{
39a8cd10 57 dyldGlobalLockRelease();
0959b6d4
A
58}
59
bac542e6 60void dyldGlobalLockAcquire()
0959b6d4 61{
bac542e6 62 pthread_mutex_lock(&sGlobalMutex);
39a8cd10 63 _dyld_global_lock_held = 1;
0959b6d4
A
64}
65
bac542e6 66void dyldGlobalLockRelease()
0959b6d4 67{
39a8cd10 68 _dyld_global_lock_held = 0;
bac542e6 69 pthread_mutex_unlock(&sGlobalMutex);
0959b6d4
A
70}
71
72