1402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
2402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Copyright 2011 Google Inc. All Rights Reserved.
3402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
4zt+:�<���sz� * Licensed under the Apache License, Version 2.0 (the "License");
5402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * you may not use this file except in compliance with the License.
6402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * You may obtain a copy of the License at
7N֭�>����>Pۚi��P�� *
8402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *      http://www.apache.org/licenses/LICENSE-2.0
9402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
10402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Unless required by applicable law or agreed to in writing, software
11Ji��dB� * distributed under the License is distributed on an "AS IS" BASIS,
12402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * See the License for the specific language governing permissions and
14402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * limitations under the License.
15i�N�ʲ��USc;>� */
16402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
17s�OC�"U��biS;+�;b�e!�f�{�=F�	кpI�`N�#ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_ATOMIC_H_
18402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#define SFNTLY_CPP_SRC_SFNTLY_PORT_ATOMIC_H_
196sl
20402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#if defined (WIN32)
21402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
22402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <windows.h>
23402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
24uSp>�kƳa�W�o�e_�static inline size_t AtomicIncrement(size_t* address) {
25D���vUuWw�^�^�QV�<yr���,)�S�����-�#if defined (_WIN64)
265��&[�:�����kV��y�]�}�>���>Y�g�Y  return InterlockedIncrement64(reinterpret_cast<LONGLONG*>(address));
27402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#else
28402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  return InterlockedIncrement(reinterpret_cast<LONG*>(address));
29402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#endif
30402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
31402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
32402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollstatic inline size_t AtomicDecrement(size_t* address) {
33402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#if defined (_WIN64)
34402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  return InterlockedDecrement64(reinterpret_cast<LONGLONG*>(address));
35x����GVAXZ�YՄڨ[m�^{����KP%�^U���Ԍl`��]!#else
36402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  return InterlockedDecrement(reinterpret_cast<LONG*>(address));
37eLa_L����mw�\�#endif
38402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
396�]|� `���y�a�΅(W��
40402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#elif defined (__APPLE__)
41402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
42402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <libkern/OSAtomic.h>
43402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
44402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollstatic inline size_t AtomicIncrement(size_t* address) {
45402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  return OSAtomicIncrement32Barrier(reinterpret_cast<int32_t*>(address));
46m"�±�E����|!xo����Eo�}�]I�������cR�>�`,��>H	���,�+֦�}
47_X
48402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollstatic inline size_t AtomicDecrement(size_t* address) {
49G��j|����xm��{���f�l�|�_  return OSAtomicDecrement32Barrier(reinterpret_cast<int32_t*>(address));
50402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
51402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
52402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll// Originally we check __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4, however, there are
53402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll// issues that clang not carring over this definition.  Therefore we boldly
54402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll// assume it's gcc or gcc-compatible here.  Compilation shall still fail since
55402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll// the intrinsics used are GCC-specific.
56402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
57402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#else
58rW�@
59402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include <stddef.h>
60402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
61402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollstatic inline size_t AtomicIncrement(size_t* address) {
62402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  return __sync_add_and_fetch(address, 1);
63k�V��]���#Vs�>{�e���u��<�o�#���H��j���}
64_W��}r�J�
65402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollstatic inline size_t AtomicDecrement(size_t* address) {
66PK�ON-.NMQ(-��KW�J,*��q$&g�%�+�*躚�����R  return __sync_sub_and_fetch(address, 1);
67402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
68402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
69402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#endif  // WIN32
70402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
71Zq�t#endif  // SFNTLY_CPP_SRC_SFNTLY_PORT_ATOMIC_H_
72402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll