summaryrefslogtreecommitdiff
path: root/storage/innobase/ut/ut0auxconf_have_gcc_atomics.c
blob: da5c13d7d79ffb0c8e86c899c752529046424f21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*****************************************************************************

Copyright (c) 2009, Innobase Oy. All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA

*****************************************************************************/

/*****************************************************************************
If this program compiles and returns 0, then GCC atomic funcions are available.

Created September 12, 2009 Vasil Dimov
*****************************************************************************/

int
main(int argc, char** argv)
{
	long	x;
	long	y;
	long	res;
	char	c;

	x = 10;
	y = 123;
	res = __sync_bool_compare_and_swap(&x, x, y);
	if (!res || x != y) {
		return(1);
	}

	x = 10;
	y = 123;
	res = __sync_bool_compare_and_swap(&x, x + 1, y);
	if (res || x != 10) {
		return(1);
	}

	x = 10;
	y = 123;
	res = __sync_add_and_fetch(&x, y);
	if (res != 123 + 10 || x != 123 + 10) {
		return(1);
	}

	c = 10;
	res = __sync_lock_test_and_set(&c, 123);
	if (res != 10 || c != 123) {
		return(1);
	}

	return(0);
}