]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-auto.h
objc4-371.1.tar.gz
[apple/objc4.git] / runtime / objc-auto.h
1 /*
2 * Copyright (c) 2004-2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _OBJC_AUTO_H_
25 #define _OBJC_AUTO_H_
26
27 #import <objc/objc.h>
28 #include <sys/types.h>
29 #include <stddef.h>
30 #include <stdint.h>
31 #include <AvailabilityMacros.h>
32
33 /* Collection utilities */
34
35 enum {
36 // choose one
37 OBJC_RATIO_COLLECTION = (0 << 0), // run "ratio" generational collections, then a full
38 OBJC_GENERATIONAL_COLLECTION = (1 << 0), // run fast incremental collection
39 OBJC_FULL_COLLECTION = (2 << 0), // run full collection.
40 OBJC_EXHAUSTIVE_COLLECTION = (3 << 0), // run full collections until memory available stops improving
41
42 OBJC_COLLECT_IF_NEEDED = (1 << 3), // run collection only if needed (allocation threshold exceeded)
43 OBJC_WAIT_UNTIL_DONE = (1 << 4), // wait (when possible) for collection to end before returning (when collector is running on dedicated thread)
44 };
45
46 OBJC_EXPORT void objc_collect(unsigned long options);
47 OBJC_EXPORT BOOL objc_collectingEnabled(void);
48
49
50 /* GC configuration */
51
52 /* Tells collector to wait until specified bytes have been allocated before trying to collect again. */
53 OBJC_EXPORT void objc_setCollectionThreshold(size_t threshold);
54
55 /* Tells collector to run a full collection for every ratio generational collections. */
56 OBJC_EXPORT void objc_setCollectionRatio(size_t ratio);
57
58 /* Tells collector to start collecting on dedicated thread */
59 OBJC_EXPORT void objc_startCollectorThread(void);
60
61
62 // atomic update of a global variable
63 OBJC_EXPORT BOOL objc_atomicCompareAndSwapGlobal(id predicate, id replacement, volatile id *objectLocation);
64 OBJC_EXPORT BOOL objc_atomicCompareAndSwapGlobalBarrier(id predicate, id replacement, volatile id *objectLocation);
65 // atomic update of an instance variable
66 OBJC_EXPORT BOOL objc_atomicCompareAndSwapInstanceVariable(id predicate, id replacement, volatile id *objectLocation);
67 OBJC_EXPORT BOOL objc_atomicCompareAndSwapInstanceVariableBarrier(id predicate, id replacement, volatile id *objectLocation);
68
69 /* Write barriers. Used by the compiler. */
70 OBJC_EXPORT id objc_assign_strongCast(id val, id *dest);
71 OBJC_EXPORT id objc_assign_global(id val, id *dest);
72 OBJC_EXPORT id objc_assign_ivar(id value, id dest, ptrdiff_t offset);
73 OBJC_EXPORT void *objc_memmove_collectable(void *dst, const void *src, size_t size);
74
75 OBJC_EXPORT id objc_read_weak(id *location);
76 OBJC_EXPORT id objc_assign_weak(id value, id *location);
77
78
79 //
80 // SPI. The following routines are available as debugging and transitional aides.
81 //
82
83 /* Tells runtime to issue finalize calls on the main thread only. */
84 OBJC_EXPORT void objc_finalizeOnMainThread(Class cls)
85 AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER_BUT_DEPRECATED;
86
87
88 /* ask if object is scheduled for finalization. Safe only when called from within a finalizer. */
89 OBJC_EXPORT BOOL objc_is_finalized(void *ptr);
90
91 enum {
92 OBJC_CLEAR_RESIDENT_STACK = (1 << 0)
93 };
94
95 /* Stack management */
96 OBJC_EXPORT void objc_clear_stack(unsigned long options);
97
98 //
99 // Obsolete. Present only until all uses can be migrated to newer API.
100 //
101
102 OBJC_EXPORT BOOL objc_collecting_enabled(void);
103 OBJC_EXPORT void objc_set_collection_threshold(size_t threshold);
104 OBJC_EXPORT void objc_set_collection_ratio(size_t ratio);
105 OBJC_EXPORT void objc_start_collector_thread(void);
106
107 /* Memory management */
108 OBJC_EXPORT id objc_allocate_object(Class cls, int extra);
109
110 enum {
111 OBJC_GENERATIONAL = (1 << 0)
112 };
113
114 OBJC_EXPORT void objc_collect_if_needed(unsigned long options);
115
116 #endif