1087882c2SAxel Dörfler/*
229e8fa59SJohn Scipione * Copyright 2004-2010 Haiku, Inc. All rights reserved.
3087882c2SAxel Dörfler * Distributed under the terms of the MIT License.
4087882c2SAxel Dörfler *
5087882c2SAxel Dörfler * Author:
6087882c2SAxel Dörfler *		Erik Jaesler (erik@cgsoftware.com)
7087882c2SAxel Dörfler */
852a38012Sejakowatz#ifndef _SUPPORT_DEFS_H
952a38012Sejakowatz#define _SUPPORT_DEFS_H
1052a38012Sejakowatz
11087882c2SAxel Dörfler
1252a38012Sejakowatz#include <BeBuild.h>
1330fd5147Shaydentech#include <Errors.h>
1452a38012Sejakowatz
152222d055SIngo Weinhold#include <inttypes.h>
16087882c2SAxel Dörfler#include <sys/types.h>
17087882c2SAxel Dörfler
1852a38012Sejakowatz
192222d055SIngo Weinhold/* fixed-size integer types */
202222d055SIngo Weinholdtypedef	__haiku_int8			int8;
212222d055SIngo Weinholdtypedef __haiku_uint8			uint8;
222222d055SIngo Weinholdtypedef	__haiku_int16			int16;
232222d055SIngo Weinholdtypedef __haiku_uint16			uint16;
242222d055SIngo Weinholdtypedef	__haiku_int32			int32;
252222d055SIngo Weinholdtypedef __haiku_uint32			uint32;
262222d055SIngo Weinholdtypedef	__haiku_int64			int64;
272222d055SIngo Weinholdtypedef __haiku_uint64			uint64;
282222d055SIngo Weinhold
292222d055SIngo Weinhold/* shorthand types */
30a05bfeb4SMichael Lotztypedef volatile int8			vint8;
312222d055SIngo Weinholdtypedef volatile uint8			vuint8;
322222d055SIngo Weinholdtypedef volatile int16			vint16;
332222d055SIngo Weinholdtypedef volatile uint16			vuint16;
342222d055SIngo Weinholdtypedef volatile int32			vint32;
352222d055SIngo Weinholdtypedef volatile uint32			vuint32;
362222d055SIngo Weinholdtypedef volatile int64			vint64;
372222d055SIngo Weinholdtypedef volatile uint64			vuint64;
3852a38012Sejakowatz
3952a38012Sejakowatztypedef volatile long			vlong;
4052a38012Sejakowatztypedef volatile int			vint;
4152a38012Sejakowatztypedef volatile short			vshort;
4252a38012Sejakowatztypedef volatile char			vchar;
4352a38012Sejakowatz
4452a38012Sejakowatztypedef volatile unsigned long	vulong;
4552a38012Sejakowatztypedef volatile unsigned int	vuint;
4652a38012Sejakowatztypedef volatile unsigned short	vushort;
4752a38012Sejakowatztypedef volatile unsigned char	vuchar;
4852a38012Sejakowatz
4952a38012Sejakowatztypedef unsigned char			uchar;
50a05bfeb4SMichael Lotztypedef unsigned short			unichar;
5152a38012Sejakowatz
522222d055SIngo Weinhold/* descriptive types */
5352a38012Sejakowatztypedef int32					status_t;
5452a38012Sejakowatztypedef int64					bigtime_t;
5534a48c70SIngo Weinholdtypedef int64					nanotime_t;
5652a38012Sejakowatztypedef uint32					type_code;
5752a38012Sejakowatztypedef uint32					perform_code;
5852a38012Sejakowatz
59ea021b94SIngo Weinholdtypedef __haiku_phys_addr_t		phys_addr_t;
60ea021b94SIngo Weinholdtypedef phys_addr_t				phys_size_t;
61ea021b94SIngo Weinhold
624a57f843SIngo Weinholdtypedef	__haiku_generic_addr_t	generic_addr_t;
634a57f843SIngo Weinholdtypedef	generic_addr_t			generic_size_t;
644a57f843SIngo Weinhold
6552a38012Sejakowatz
662222d055SIngo Weinhold/* printf()/scanf() format strings for [u]int* types */
670fde9192SIngo Weinhold#define B_PRId8			"d"
680fde9192SIngo Weinhold#define B_PRIi8			"i"
690fde9192SIngo Weinhold#define B_PRId16		"d"
700fde9192SIngo Weinhold#define B_PRIi16		"i"
710fde9192SIngo Weinhold#define B_PRId32		__HAIKU_PRI_PREFIX_32 "d"
720fde9192SIngo Weinhold#define B_PRIi32		__HAIKU_PRI_PREFIX_32 "i"
730fde9192SIngo Weinhold#define B_PRId64		__HAIKU_PRI_PREFIX_64 "d"
740fde9192SIngo Weinhold#define B_PRIi64		__HAIKU_PRI_PREFIX_64 "i"
750fde9192SIngo Weinhold#define B_PRIu8			"u"
760fde9192SIngo Weinhold#define B_PRIo8			"o"
770fde9192SIngo Weinhold#define B_PRIx8			"x"
780fde9192SIngo Weinhold#define B_PRIX8			"X"
790fde9192SIngo Weinhold#define B_PRIu16		"u"
800fde9192SIngo Weinhold#define B_PRIo16		"o"
810fde9192SIngo Weinhold#define B_PRIx16		"x"
820fde9192SIngo Weinhold#define B_PRIX16		"X"
830fde9192SIngo Weinhold#define B_PRIu32		__HAIKU_PRI_PREFIX_32 "u"
840fde9192SIngo Weinhold#define B_PRIo32		__HAIKU_PRI_PREFIX_32 "o"
850fde9192SIngo Weinhold#define B_PRIx32		__HAIKU_PRI_PREFIX_32 "x"
860fde9192SIngo Weinhold#define B_PRIX32		__HAIKU_PRI_PREFIX_32 "X"
870fde9192SIngo Weinhold#define B_PRIu64		__HAIKU_PRI_PREFIX_64 "u"
880fde9192SIngo Weinhold#define B_PRIo64		__HAIKU_PRI_PREFIX_64 "o"
890fde9192SIngo Weinhold#define B_PRIx64		__HAIKU_PRI_PREFIX_64 "x"
900fde9192SIngo Weinhold#define B_PRIX64		__HAIKU_PRI_PREFIX_64 "X"
912222d055SIngo Weinhold
92a05bfeb4SMichael Lotz#define B_SCNd8			"hhd"
93a05bfeb4SMichael Lotz#define B_SCNi8			"hhi"
940fde9192SIngo Weinhold#define B_SCNd16		"hd"
95a05bfeb4SMichael Lotz#define B_SCNi16		"hi"
96a05bfeb4SMichael Lotz#define B_SCNd32		__HAIKU_PRI_PREFIX_32 "d"
97a05bfeb4SMichael Lotz#define B_SCNi32		__HAIKU_PRI_PREFIX_32 "i"
980fde9192SIngo Weinhold#define B_SCNd64		__HAIKU_PRI_PREFIX_64 "d"
99a05bfeb4SMichael Lotz#define B_SCNi64		__HAIKU_PRI_PREFIX_64 "i"
100a05bfeb4SMichael Lotz#define B_SCNu8			"hhu"
101a05bfeb4SMichael Lotz#define B_SCNo8			"hho"
102a05bfeb4SMichael Lotz#define B_SCNx8			"hhx"
1030fde9192SIngo Weinhold#define B_SCNu16		"hu"
1040fde9192SIngo Weinhold#define B_SCNo16		"ho"
1050fde9192SIngo Weinhold#define B_SCNx16		"hx"
106a05bfeb4SMichael Lotz#define B_SCNu32		__HAIKU_PRI_PREFIX_32 "u"
107a05bfeb4SMichael Lotz#define B_SCNo32		__HAIKU_PRI_PREFIX_32 "o"
108a05bfeb4SMichael Lotz#define B_SCNx32		__HAIKU_PRI_PREFIX_32 "x"
1090fde9192SIngo Weinhold#define B_SCNu64		__HAIKU_PRI_PREFIX_64 "u"
1100fde9192SIngo Weinhold#define B_SCNo64		__HAIKU_PRI_PREFIX_64 "o"
1110fde9192SIngo Weinhold#define B_SCNx64		__HAIKU_PRI_PREFIX_64 "x"
1122222d055SIngo Weinhold
1135ae3af6cSMichael Lotz/* printf()/scanf() format strings for some standard types */
1142222d055SIngo Weinhold/* size_t */
1152222d055SIngo Weinhold#define B_PRIuSIZE		__HAIKU_PRI_PREFIX_ADDR "u"
1162222d055SIngo Weinhold#define B_PRIoSIZE		__HAIKU_PRI_PREFIX_ADDR "o"
1172222d055SIngo Weinhold#define B_PRIxSIZE		__HAIKU_PRI_PREFIX_ADDR "x"
1182222d055SIngo Weinhold#define B_PRIXSIZE		__HAIKU_PRI_PREFIX_ADDR "X"
1195ae3af6cSMichael Lotz
1205ae3af6cSMichael Lotz#define B_SCNuSIZE		__HAIKU_PRI_PREFIX_ADDR "u"
1215ae3af6cSMichael Lotz#define B_SCNoSIZE		__HAIKU_PRI_PREFIX_ADDR "o"
1225ae3af6cSMichael Lotz#define B_SCNxSIZE		__HAIKU_PRI_PREFIX_ADDR "x"
1235ae3af6cSMichael Lotz
1242222d055SIngo Weinhold/* ssize_t */
1252222d055SIngo Weinhold#define B_PRIdSSIZE		__HAIKU_PRI_PREFIX_ADDR "d"
1262222d055SIngo Weinhold#define B_PRIiSSIZE		__HAIKU_PRI_PREFIX_ADDR "i"
1275ae3af6cSMichael Lotz
1285ae3af6cSMichael Lotz#define B_SCNdSSIZE		__HAIKU_PRI_PREFIX_ADDR "d"
1295ae3af6cSMichael Lotz#define B_SCNiSSIZE		__HAIKU_PRI_PREFIX_ADDR "i"
1305ae3af6cSMichael Lotz
1312222d055SIngo Weinhold/* addr_t */
1322222d055SIngo Weinhold#define B_PRIuADDR		__HAIKU_PRI_PREFIX_ADDR "u"
1332222d055SIngo Weinhold#define B_PRIoADDR		__HAIKU_PRI_PREFIX_ADDR "o"
1342222d055SIngo Weinhold#define B_PRIxADDR		__HAIKU_PRI_PREFIX_ADDR "x"
1352222d055SIngo Weinhold#define B_PRIXADDR		__HAIKU_PRI_PREFIX_ADDR "X"
1365ae3af6cSMichael Lotz
1375ae3af6cSMichael Lotz#define B_SCNuADDR		__HAIKU_PRI_PREFIX_ADDR "u"
1385ae3af6cSMichael Lotz#define B_SCNoADDR		__HAIKU_PRI_PREFIX_ADDR "o"
1395ae3af6cSMichael Lotz#define B_SCNxADDR		__HAIKU_PRI_PREFIX_ADDR "x"
1405ae3af6cSMichael Lotz
141d34daac8SIngo Weinhold/* phys_addr_t */
142d34daac8SIngo Weinhold#define B_PRIuPHYSADDR	__HAIKU_PRI_PREFIX_PHYS_ADDR "u"
143d34daac8SIngo Weinhold#define B_PRIoPHYSADDR	__HAIKU_PRI_PREFIX_PHYS_ADDR "o"
144d34daac8SIngo Weinhold#define B_PRIxPHYSADDR	__HAIKU_PRI_PREFIX_PHYS_ADDR "x"
145d34daac8SIngo Weinhold#define B_PRIXPHYSADDR	__HAIKU_PRI_PREFIX_PHYS_ADDR "X"
1465ae3af6cSMichael Lotz
1475ae3af6cSMichael Lotz#define B_SCNuPHYSADDR	__HAIKU_PRI_PREFIX_PHYS_ADDR "u"
1485ae3af6cSMichael Lotz#define B_SCNoPHYSADDR	__HAIKU_PRI_PREFIX_PHYS_ADDR "o"
1495ae3af6cSMichael Lotz#define B_SCNxPHYSADDR	__HAIKU_PRI_PREFIX_PHYS_ADDR "x"
1505ae3af6cSMichael Lotz
1514a57f843SIngo Weinhold/* generic_addr_t */
1524a57f843SIngo Weinhold#define B_PRIuGENADDR	__HAIKU_PRI_PREFIX_GENERIC_ADDR "u"
1534a57f843SIngo Weinhold#define B_PRIoGENADDR	__HAIKU_PRI_PREFIX_GENERIC_ADDR "o"
1544a57f843SIngo Weinhold#define B_PRIxGENADDR	__HAIKU_PRI_PREFIX_GENERIC_ADDR "x"
1554a57f843SIngo Weinhold#define B_PRIXGENADDR	__HAIKU_PRI_PREFIX_GENERIC_ADDR "X"
1565ae3af6cSMichael Lotz
1575ae3af6cSMichael Lotz#define B_SCNuGENADDR	__HAIKU_PRI_PREFIX_GENERIC_ADDR "u"
1585ae3af6cSMichael Lotz#define B_SCNoGENADDR	__HAIKU_PRI_PREFIX_GENERIC_ADDR "o"
1595ae3af6cSMichael Lotz#define B_SCNxGENADDR	__HAIKU_PRI_PREFIX_GENERIC_ADDR "x"
1605ae3af6cSMichael Lotz
1612222d055SIngo Weinhold/* off_t */
1622222d055SIngo Weinhold#define B_PRIdOFF		B_PRId64
1632222d055SIngo Weinhold#define B_PRIiOFF		B_PRIi64
164dc4e3ce3SJérôme Duval#define B_PRIxOFF		B_PRIx64
1655ae3af6cSMichael Lotz
1665ae3af6cSMichael Lotz#define B_SCNdOFF		B_SCNd64
1675ae3af6cSMichael Lotz#define B_SCNiOFF		B_SCNi64
1685ae3af6cSMichael Lotz#define B_SCNxOFF		B_SCNx64
1695ae3af6cSMichael Lotz
1702222d055SIngo Weinhold/* dev_t */
1712222d055SIngo Weinhold#define B_PRIdDEV		B_PRId32
1722222d055SIngo Weinhold#define B_PRIiDEV		B_PRIi32
1735ae3af6cSMichael Lotz
1742222d055SIngo Weinhold/* ino_t */
1752222d055SIngo Weinhold#define B_PRIdINO		B_PRId64
1762222d055SIngo Weinhold#define B_PRIiINO		B_PRIi64
1775ae3af6cSMichael Lotz
178cf844822SIngo Weinhold/* time_t */
17939efd913SAugustin Cavalier#if defined(__i386__) && !defined(__x86_64__)
18039efd913SAugustin Cavalier#	define B_PRIdTIME	B_PRId32
18139efd913SAugustin Cavalier#	define B_PRIiTIME	B_PRIi32
18239efd913SAugustin Cavalier#else
18339efd913SAugustin Cavalier#	define B_PRIdTIME	B_PRId64
18439efd913SAugustin Cavalier#	define B_PRIiTIME	B_PRIi64
18539efd913SAugustin Cavalier#endif
1865ae3af6cSMichael Lotz
187843a122fSJérôme Duval/* bigtime_t */
188843a122fSJérôme Duval#define B_PRIdBIGTIME	B_PRId64
189843a122fSJérôme Duval#define B_PRIiBIGTIME	B_PRIi64
1902222d055SIngo Weinhold
1912222d055SIngo Weinhold
192c3f0fd28SAlex Smith/* Printed width of a pointer with the %p format (minus 0x prefix). */
193c3f0fd28SAlex Smith#ifdef B_HAIKU_64_BIT
194c3f0fd28SAlex Smith#	define B_PRINTF_POINTER_WIDTH	16
195c3f0fd28SAlex Smith#else
196c3f0fd28SAlex Smith#	define B_PRINTF_POINTER_WIDTH	8
197c3f0fd28SAlex Smith#endif
198c3f0fd28SAlex Smith
199c3f0fd28SAlex Smith
200e1f3108aSStephan Aßmus/* Empty string ("") */
20152a38012Sejakowatz#ifdef __cplusplus
202087882c2SAxel Dörflerextern const char *B_EMPTY_STRING;
20352a38012Sejakowatz#endif
20452a38012Sejakowatz
20552a38012Sejakowatz
206e1f3108aSStephan Aßmus/* min and max comparisons */
20752a38012Sejakowatz#ifndef __cplusplus
20861ad5bc2SAxel Dörfler#	ifndef min
20961ad5bc2SAxel Dörfler#		define min(a,b) ((a)>(b)?(b):(a))
21061ad5bc2SAxel Dörfler#	endif
21161ad5bc2SAxel Dörfler#	ifndef max
21261ad5bc2SAxel Dörfler#		define max(a,b) ((a)>(b)?(a):(b))
21361ad5bc2SAxel Dörfler#	endif
2142222d055SIngo Weinhold#endif
21552a38012Sejakowatz
2162222d055SIngo Weinhold/* min() and max() are functions in C++ */
217087882c2SAxel Dörfler#define min_c(a,b) ((a)>(b)?(b):(a))
218087882c2SAxel Dörfler#define max_c(a,b) ((a)>(b)?(a):(b))
219087882c2SAxel Dörfler
22052a38012Sejakowatz
221e1f3108aSStephan Aßmus/* Grandfathering */
22261ad5bc2SAxel Dörfler#ifndef __cplusplus
22361ad5bc2SAxel Dörfler#	include <stdbool.h>
2242222d055SIngo Weinhold#endif
22552a38012Sejakowatz
22652a38012Sejakowatz#ifndef NULL
22761ad5bc2SAxel Dörfler#	define NULL (0)
22852a38012Sejakowatz#endif
22952a38012Sejakowatz
23052a38012Sejakowatz
23152a38012Sejakowatz#ifdef __cplusplus
23252a38012Sejakowatzextern "C" {
23352a38012Sejakowatz#endif
23452a38012Sejakowatz
235e1f3108aSStephan Aßmus/* Other stuff */
236087882c2SAxel Dörflerextern void*	get_stack_frame(void);
23752a38012Sejakowatz
23852a38012Sejakowatz#ifdef __cplusplus
23952a38012Sejakowatz}
24052a38012Sejakowatz#endif
24152a38012Sejakowatz
242f2b20f88SAlexander von Gluck IV/* Count items in an array, count_of is a common define */
243f2b20f88SAlexander von Gluck IV#define B_COUNT_OF(a) (sizeof(a) / sizeof(a[0]))
244f2b20f88SAlexander von Gluck IV
245e1f3108aSStephan Aßmus/* Obsolete or discouraged API */
24652a38012Sejakowatz
247e1f3108aSStephan Aßmus/* use 'true' and 'false' */
24852a38012Sejakowatz#ifndef FALSE
24961ad5bc2SAxel Dörfler#	define FALSE	0
25052a38012Sejakowatz#endif
25152a38012Sejakowatz#ifndef TRUE
25261ad5bc2SAxel Dörfler#	define TRUE		1
25352a38012Sejakowatz#endif
25452a38012Sejakowatz
2554f7b2c67SIngo Weinhold
2564f7b2c67SIngo Weinhold/* Use the built-in atomic functions, if requested and available. */
2574f7b2c67SIngo Weinhold
25845615059SJonathan Schleifer#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) || defined(__clang__)
2592e2c9bd3SPaweł Dziepak
2602e2c9bd3SPaweł Dziepak
261c299b09cSAdrien Destuguesstatic __inline__ void
2622e2c9bd3SPaweł Dziepakatomic_set(int32* value, int32 newValue)
2632e2c9bd3SPaweł Dziepak{
2642e2c9bd3SPaweł Dziepak	__atomic_store_n(value, newValue, __ATOMIC_RELEASE);
2652e2c9bd3SPaweł Dziepak}
2662e2c9bd3SPaweł Dziepak
2672e2c9bd3SPaweł Dziepak
268c299b09cSAdrien Destuguesstatic __inline__ int32
2692e2c9bd3SPaweł Dziepakatomic_get_and_set(int32* value, int32 newValue)
2702e2c9bd3SPaweł Dziepak{
2712e2c9bd3SPaweł Dziepak	return __atomic_exchange_n(value, newValue, __ATOMIC_SEQ_CST);
2722e2c9bd3SPaweł Dziepak}
2732e2c9bd3SPaweł Dziepak
2742e2c9bd3SPaweł Dziepak
275c299b09cSAdrien Destuguesstatic __inline__ int32
2762e2c9bd3SPaweł Dziepakatomic_test_and_set(int32* value, int32 newValue, int32 testAgainst)
2772e2c9bd3SPaweł Dziepak{
2782e2c9bd3SPaweł Dziepak	__atomic_compare_exchange_n(value, &testAgainst, newValue, 1,
2792e2c9bd3SPaweł Dziepak		__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
2802e2c9bd3SPaweł Dziepak	return testAgainst;
2812e2c9bd3SPaweł Dziepak}
2822e2c9bd3SPaweł Dziepak
2832e2c9bd3SPaweł Dziepak
284c299b09cSAdrien Destuguesstatic __inline__ int32
2852e2c9bd3SPaweł Dziepakatomic_add(int32* value, int32 addValue)
2862e2c9bd3SPaweł Dziepak{
2872e2c9bd3SPaweł Dziepak	return __atomic_fetch_add(value, addValue, __ATOMIC_SEQ_CST);
2882e2c9bd3SPaweł Dziepak}
2892e2c9bd3SPaweł Dziepak
2902e2c9bd3SPaweł Dziepak
291c299b09cSAdrien Destuguesstatic __inline__ int32
2922e2c9bd3SPaweł Dziepakatomic_and(int32* value, int32 andValue)
2932e2c9bd3SPaweł Dziepak{
2942e2c9bd3SPaweł Dziepak	return __atomic_fetch_and(value, andValue, __ATOMIC_SEQ_CST);
2952e2c9bd3SPaweł Dziepak}
2962e2c9bd3SPaweł Dziepak
2972e2c9bd3SPaweł Dziepak
298c299b09cSAdrien Destuguesstatic __inline__ int32
2992e2c9bd3SPaweł Dziepakatomic_or(int32* value, int32 orValue)
3002e2c9bd3SPaweł Dziepak{
3012e2c9bd3SPaweł Dziepak	return __atomic_fetch_or(value, orValue, __ATOMIC_SEQ_CST);
3022e2c9bd3SPaweł Dziepak}
3032e2c9bd3SPaweł Dziepak
3042e2c9bd3SPaweł Dziepak
305c299b09cSAdrien Destuguesstatic __inline__ int32
3062e2c9bd3SPaweł Dziepakatomic_get(int32* value)
3072e2c9bd3SPaweł Dziepak{
3082e2c9bd3SPaweł Dziepak	return __atomic_load_n(value, __ATOMIC_ACQUIRE);
3092e2c9bd3SPaweł Dziepak}
3102e2c9bd3SPaweł Dziepak
3112e2c9bd3SPaweł Dziepak
312c299b09cSAdrien Destuguesstatic __inline__ void
3132e2c9bd3SPaweł Dziepakatomic_set64(int64* value, int64 newValue)
3142e2c9bd3SPaweł Dziepak{
3152e2c9bd3SPaweł Dziepak	__atomic_store_n(value, newValue, __ATOMIC_RELEASE);
3162e2c9bd3SPaweł Dziepak}
3172e2c9bd3SPaweł Dziepak
3182e2c9bd3SPaweł Dziepak
319c299b09cSAdrien Destuguesstatic __inline__ int64
3202e2c9bd3SPaweł Dziepakatomic_get_and_set64(int64* value, int64 newValue)
3212e2c9bd3SPaweł Dziepak{
3222e2c9bd3SPaweł Dziepak	return __atomic_exchange_n(value, newValue, __ATOMIC_SEQ_CST);
3232e2c9bd3SPaweł Dziepak}
3242e2c9bd3SPaweł Dziepak
3252e2c9bd3SPaweł Dziepak
326c299b09cSAdrien Destuguesstatic __inline__ int64
3272e2c9bd3SPaweł Dziepakatomic_test_and_set64(int64* value, int64 newValue, int64 testAgainst)
3282e2c9bd3SPaweł Dziepak{
3292e2c9bd3SPaweł Dziepak	__atomic_compare_exchange_n(value, &testAgainst, newValue, 1,
3302e2c9bd3SPaweł Dziepak		__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
3312e2c9bd3SPaweł Dziepak	return testAgainst;
3322e2c9bd3SPaweł Dziepak}
3332e2c9bd3SPaweł Dziepak
3342e2c9bd3SPaweł Dziepak
335c299b09cSAdrien Destuguesstatic __inline__ int64
3362e2c9bd3SPaweł Dziepakatomic_add64(int64* value, int64 addValue)
3372e2c9bd3SPaweł Dziepak{
3382e2c9bd3SPaweł Dziepak	return __atomic_fetch_add(value, addValue, __ATOMIC_SEQ_CST);
3392e2c9bd3SPaweł Dziepak}
3402e2c9bd3SPaweł Dziepak
3412e2c9bd3SPaweł Dziepak
342c299b09cSAdrien Destuguesstatic __inline__ int64
3432e2c9bd3SPaweł Dziepakatomic_and64(int64* value, int64 andValue)
3442e2c9bd3SPaweł Dziepak{
3452e2c9bd3SPaweł Dziepak	return __atomic_fetch_and(value, andValue, __ATOMIC_SEQ_CST);
3462e2c9bd3SPaweł Dziepak}
3472e2c9bd3SPaweł Dziepak
3484f7b2c67SIngo Weinhold
349c299b09cSAdrien Destuguesstatic __inline__ int64
3502e2c9bd3SPaweł Dziepakatomic_or64(int64* value, int64 orValue)
3512e2c9bd3SPaweł Dziepak{
3522e2c9bd3SPaweł Dziepak	return __atomic_fetch_or(value, orValue, __ATOMIC_SEQ_CST);
3532e2c9bd3SPaweł Dziepak}
3542e2c9bd3SPaweł Dziepak
3552e2c9bd3SPaweł Dziepak
356c299b09cSAdrien Destuguesstatic __inline__ int64
3572e2c9bd3SPaweł Dziepakatomic_get64(int64* value)
3582e2c9bd3SPaweł Dziepak{
3592e2c9bd3SPaweł Dziepak	return __atomic_load_n(value, __ATOMIC_ACQUIRE);
3602e2c9bd3SPaweł Dziepak}
3612e2c9bd3SPaweł Dziepak
3622e2c9bd3SPaweł Dziepak
363c299b09cSAdrien Destugues#else	/* __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) */
3644f7b2c67SIngo Weinhold
3652e2c9bd3SPaweł Dziepak#ifdef __cplusplus
3662e2c9bd3SPaweł Dziepakextern "C" {
3672e2c9bd3SPaweł Dziepak#endif
3682e2c9bd3SPaweł Dziepak
3692e2c9bd3SPaweł Dziepak/* Atomic functions; previous value is returned */
3702e2c9bd3SPaweł Dziepakextern void		atomic_set(int32* value, int32 newValue);
3712e2c9bd3SPaweł Dziepakextern int32	atomic_get_and_set(int32* value, int32 newValue);
3722e2c9bd3SPaweł Dziepakextern int32	atomic_test_and_set(int32 *value, int32 newValue, int32 testAgainst);
3732e2c9bd3SPaweł Dziepakextern int32	atomic_add(int32 *value, int32 addValue);
3742e2c9bd3SPaweł Dziepakextern int32	atomic_and(int32 *value, int32 andValue);
3752e2c9bd3SPaweł Dziepakextern int32	atomic_or(int32 *value, int32 orValue);
3762e2c9bd3SPaweł Dziepakextern int32	atomic_get(int32 *value);
3772e2c9bd3SPaweł Dziepak
3782e2c9bd3SPaweł Dziepakextern void		atomic_set64(int64* value, int64 newValue);
3792e2c9bd3SPaweł Dziepakextern int64	atomic_get_and_set64(int64* value, int64 newValue);
3802e2c9bd3SPaweł Dziepakextern int64	atomic_test_and_set64(int64 *value, int64 newValue, int64 testAgainst);
3812e2c9bd3SPaweł Dziepakextern int64	atomic_add64(int64 *value, int64 addValue);
3822e2c9bd3SPaweł Dziepakextern int64	atomic_and64(int64 *value, int64 andValue);
3832e2c9bd3SPaweł Dziepakextern int64	atomic_or64(int64 *value, int64 orValue);
3842e2c9bd3SPaweł Dziepakextern int64	atomic_get64(int64 *value);
3852e2c9bd3SPaweł Dziepak
3862e2c9bd3SPaweł Dziepak#ifdef __cplusplus
3872e2c9bd3SPaweł Dziepak}
3882e2c9bd3SPaweł Dziepak#endif
3892e2c9bd3SPaweł Dziepak
3902e2c9bd3SPaweł Dziepak#endif
3914f7b2c67SIngo Weinhold
3924f7b2c67SIngo Weinhold
393e1f3108aSStephan Aßmus#endif	/* _SUPPORT_DEFS_H */
394