aboutsummaryrefslogtreecommitdiffstats
path: root/include/nvgpu/posix/atomic.h
blob: c9d92128ec1ce36cca1eeee6473b34cc66cd5108 (plain) (blame)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 * Copyright (c) 2017, NVIDIA CORPORATION.  All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#ifndef __NVGPU_POSIX_ATOMIC_H__
#define __NVGPU_POSIX_ATOMIC_H__

#include <nvgpu/types.h>

/*
 * Note: this code uses the GCC builtins to implement atomics.
 */

#define __atomic_cmpxchg(p, v, c)	__sync_val_compare_and_swap(p, v, c)
#define __atomic_and(p, v)		__sync_fetch_and_and(p, v)
#define __atomic_or(p, v)		__sync_fetch_and_or(p, v)

#define cmpxchg				__atomic_cmpxchg

/*
 * Place holders until real atomics can be implemented... Yay for GCC builtins!
 * We can use those eventually to define all the Linux atomic ops.
 *
 * TODO: make these _actually_ atomic!
 */
typedef struct __nvgpu_posix_atomic {
	int v;
} nvgpu_atomic_t;

typedef struct __nvgpu_posix_atomic64 {
	long v;
} nvgpu_atomic64_t;

#define __nvgpu_atomic_init(i)		{ i }
#define __nvgpu_atomic64_init(i)	{ i }

static inline void __nvgpu_atomic_set(nvgpu_atomic_t *v, int i)
{
	v->v = i;
}

static inline int __nvgpu_atomic_read(nvgpu_atomic_t *v)
{
	return v->v;
}

static inline void __nvgpu_atomic_inc(nvgpu_atomic_t *v)
{
	v->v++;
}

static inline int __nvgpu_atomic_inc_return(nvgpu_atomic_t *v)
{
	v->v++;
	return v->v;
}

static inline void __nvgpu_atomic_dec(nvgpu_atomic_t *v)
{
	v->v--;
}

static inline int __nvgpu_atomic_dec_return(nvgpu_atomic_t *v)
{
	v->v--;
	return v->v;
}

static inline int __nvgpu_atomic_cmpxchg(nvgpu_atomic_t *v, int old, int new)
{
	if (v->v == old)
		v->v = new;

	return v->v;
}

static inline int __nvgpu_atomic_xchg(nvgpu_atomic_t *v, int new)
{
	v->v = new;
	return new;
}

static inline bool __nvgpu_atomic_inc_and_test(nvgpu_atomic_t *v)
{
	v->v++;
	return v->v ? true : false;
}

static inline bool __nvgpu_atomic_dec_and_test(nvgpu_atomic_t *v)
{
	v->v--;
	return v->v ? true : false;
}

static inline bool __nvgpu_atomic_sub_and_test(int i, nvgpu_atomic_t *v)
{
	v->v -= i;
	return v->v ? true : false;
}

static inline int __nvgpu_atomic_add_return(int i, nvgpu_atomic_t *v)
{
	v->v += i;
	return v->v;
}

static inline int __nvgpu_atomic_add_unless(nvgpu_atomic_t *v, int a, int u)
{
	if (v->v != u)
		v->v += a;

	return v->v;
}

static inline void __nvgpu_atomic64_set(nvgpu_atomic64_t *v, long i)
{
	v->v = i;
}

static inline long __nvgpu_atomic64_read(nvgpu_atomic64_t *v)
{
	return v->v;
}

static inline void __nvgpu_atomic64_add(long x, nvgpu_atomic64_t *v)
{
	v->v += x;
}

static inline void __nvgpu_atomic64_inc(nvgpu_atomic64_t *v)
{
	v->v++;
}

static inline long __nvgpu_atomic64_inc_return(nvgpu_atomic64_t *v)
{
	v->v++;
	return v->v;
}

static inline void __nvgpu_atomic64_dec(nvgpu_atomic64_t *v)
{
	v->v--;
}

static inline long __nvgpu_atomic64_dec_return(nvgpu_atomic64_t *v)
{
	v->v--;
	return v->v;
}

static inline long __nvgpu_atomic64_cmpxchg(nvgpu_atomic64_t *v,
					long old, long new)
{

	if (v->v == old)
		v->v = new;

	return v->v;
}

static inline void __nvgpu_atomic64_sub(long x, nvgpu_atomic64_t *v)
{
	v->v -= x;
}

static inline long __nvgpu_atomic64_sub_return(long x, nvgpu_atomic64_t *v)
{
	v->v -= x;
	return v->v;
}

#endif
27'>627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946

















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
%PDF-1.3
%Äåòåë§ó ÐÄÆ
4 0 obj
<< /Length 5 0 R /Filter /FlateDecode >>
stream
x½ZÙŽ5}ï¯pÂ’ž�ñ´Ý«		�
^ˆt%h4‘@�	ü?Çö©Þ¸KÍèêN"µº¯}ª\uj±»?˜·æƒqÿ­óUåM;ôvLߥËÍ•ùÉüi.žtæò£©Ò¿�—˜SYßTñ/?ï\7X?D„ª³Cqymžm0Ðite6—�‘&ñ²¹6¯œuÆ™Í{SÞ»f6¿c