]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/threading_internal.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // threading_internal - internal support classes and functions for threading implementation
22 #ifndef _H_THREADING_INTERNAL
23 #define _H_THREADING_INTERNAL
25 #include <Security/utilities.h>
32 // Architecture-specific atomic operation primitives.
33 // AtomicWord is an integer type that works with these;
34 // we'll assume that a pointer fits into it (using reinterpret_cast).
38 #define _HAVE_ATOMIC_OPERATIONS
40 typedef unsigned int AtomicWord
;
42 inline AtomicWord
atomicLoad(AtomicWord
&atom
)
56 inline AtomicWord
atomicStore(AtomicWord
&atom
, AtomicWord newValue
, AtomicWord oldValue
)
60 "0: lwarx %0,0,%1 \n" // load and reserve -> %0
61 " cmpw %0,%3 \n" // compare to old
62 " bne 1f \n" // fail if not equal
63 " stwcx. %2,0,%1 \n" // store and check
64 " bne 0b \n" // retry if contended
67 : "b"(&atom
), "r"(newValue
), "r"(oldValue
)
73 inline AtomicWord
atomicOffset(AtomicWord
&atom
, int offset
)
82 : "b"(&atom
), "r"(offset
)
88 inline AtomicWord
atomicIncrement(AtomicWord
&atom
)
89 { return atomicOffset(atom
, +1); }
91 inline AtomicWord
atomicDecrement(AtomicWord
&atom
)
92 { return atomicOffset(atom
, -1); }
94 #endif //TARGET_CPU_PPC
96 } // end namespace Security
98 #endif //_H_THREADING_INTERNAL