dyld-46.16.tar.gz
[apple/dyld.git] / src / dyldLock.h
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved.
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
26 #ifndef __DYLDLOCK__
27 #define __DYLDLOCK__
28
29 //
30 // This file contains the syncronization utilities used by dyld to be thread safe.
31 // Access to all dyld data structures is protected by a reader-writer lock.
32 // This lock allows multiple "reader" threads to access dyld data structures at
33 // the same time. If there is a "writer" thread, it is the only thread allowed
34 // access to dyld data structures.
35 //
36 // The implementation of all dyld API's must acquire the global lock around accesses
37 // to dyld's data structures. This is done using the macros DYLD_*_LOCK_THIS_BLOCK.
38 // Example:
39 //
40 // void dyld_api_modifying_dyld() {
41 // DYLD_WRITER_LOCK_THIS_BLOCK;
42 // // free to do stuff here
43 // // that modifies dyld data structures
44 // }
45 //
46 // void dyld_api_examinging_dyld() {
47 // DYLD_READER_LOCK_THIS_BLOCK
48 // // can only do stuff here
49 // // that examines but does not modify dyld data structures
50 // }
51 //
52 // void dyld_api_state_free() {
53 // DYLD_NO_LOCK_THIS_BLOCK
54 // // can only do stuff here
55 // // that does not require locking
56 // }
57 //
58
59
60 #define DYLD_READER_LOCK_THIS_BLOCK LockReaderHelper _dyld_lock;
61 #define DYLD_WRITER_LOCK_THIS_BLOCK LockWriterHelper _dyld_lock;
62 #define DYLD_NO_LOCK_THIS_BLOCK
63
64 // used by dyld wrapper functions in libSystem
65 class LockReaderHelper
66 {
67 public:
68 LockReaderHelper() __attribute__((visibility("hidden")));
69 ~LockReaderHelper() __attribute__((visibility("hidden")));
70 };
71
72 // used by dyld wrapper functions in libSystem
73 class LockWriterHelper
74 {
75 public:
76 LockWriterHelper() __attribute__((visibility("hidden")));
77 ~LockWriterHelper() __attribute__((visibility("hidden")));
78 };
79
80 // used by lazy binding
81 extern void lockForLazyBinding() __attribute__((visibility("hidden")));
82 extern void unlockForLazyBinding() __attribute__((visibility("hidden")));
83
84
85
86 #endif // __DYLDLOCK__
87