1
/* cairo - a vector graphics library with display and print output
2
 *
3
 * Copyright © 2007 Chris Wilson
4
 * Copyright © 2010 Andrea Canciani
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it either under the terms of the GNU Lesser General Public
8
 * License version 2.1 as published by the Free Software Foundation
9
 * (the "LGPL") or, at your option, under the terms of the Mozilla
10
 * Public License Version 1.1 (the "MPL"). If you do not alter this
11
 * notice, a recipient may use your version of this file under either
12
 * the MPL or the LGPL.
13
 *
14
 * You should have received a copy of the LGPL along with this library
15
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
17
 * You should have received a copy of the MPL along with this library
18
 * in the file COPYING-MPL-1.1
19
 *
20
 * The contents of this file are subject to the Mozilla Public License
21
 * Version 1.1 (the "License"); you may not use this file except in
22
 * compliance with the License. You may obtain a copy of the License at
23
 * http://www.mozilla.org/MPL/
24
 *
25
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
27
 * the specific language governing rights and limitations.
28
 *
29
 * The Original Code is the cairo graphics library.
30
 *
31
 * The Initial Developer of the Original Code is University of Southern
32
 * California.
33
 *
34
 * Contributor(s):
35
 *	Chris Wilson <chris@chris-wilson.co.uk>
36
 *	Andrea Canciani <ranma42@gmail.com>
37
 */
38

            
39
#ifndef CAIRO_ATOMIC_PRIVATE_H
40
#define CAIRO_ATOMIC_PRIVATE_H
41

            
42
#include "cairo-compiler-private.h"
43

            
44
#include "config.h"
45

            
46
#include <assert.h>
47

            
48
CAIRO_BEGIN_DECLS
49

            
50
#if HAVE_C11_ATOMIC_PRIMITIVES
51

            
52
#include <stdatomic.h>
53

            
54
#define HAS_ATOMIC_OPS 1
55

            
56
typedef atomic_int cairo_atomic_int_t;
57
typedef _Atomic(void *) cairo_atomic_intptr_t;
58

            
59
static cairo_always_inline int
60
_cairo_atomic_int_get (cairo_atomic_int_t *x)
61
{
62
7022480
    return atomic_load_explicit (x, memory_order_seq_cst);
63
}
64

            
65
static cairo_always_inline int
66
_cairo_atomic_int_get_relaxed (cairo_atomic_int_t *x)
67
{
68
4987311
    return atomic_load_explicit (x, memory_order_relaxed);
69
}
70

            
71
static cairo_always_inline void
72
_cairo_atomic_int_set_relaxed (cairo_atomic_int_t *x, int val)
73
{
74
4992175
    atomic_store_explicit (x, val, memory_order_relaxed);
75
4992175
}
76

            
77
static cairo_always_inline void *
78
_cairo_atomic_ptr_get (cairo_atomic_intptr_t *x)
79
{
80
2873698
    return atomic_load_explicit (x, memory_order_seq_cst);
81
}
82

            
83
# define _cairo_atomic_int_inc(x) ((void) atomic_fetch_add_explicit(x, 1, memory_order_seq_cst))
84
# define _cairo_atomic_int_dec(x) ((void) atomic_fetch_sub_explicit(x, 1, memory_order_seq_cst))
85
# define _cairo_atomic_int_dec_and_test(x) (atomic_fetch_sub_explicit(x, 1, memory_order_seq_cst) == 1)
86

            
87

            
88
static cairo_always_inline cairo_bool_t
89
_cairo_atomic_int_cmpxchg_impl(cairo_atomic_int_t *x,
90
			       int                oldv,
91
			       int                newv)
92
{
93
226922
    int expected = oldv;
94
226922
    return atomic_compare_exchange_strong_explicit (x, &expected, newv, memory_order_seq_cst, memory_order_seq_cst);
95
}
96

            
97
#define _cairo_atomic_int_cmpxchg(x, oldv, newv) \
98
  _cairo_atomic_int_cmpxchg_impl(x, oldv, newv)
99

            
100
static cairo_always_inline int
101
_cairo_atomic_int_cmpxchg_return_old_impl(cairo_atomic_int_t *x,
102
					  int                 oldv,
103
					  int                 newv)
104
{
105
367894
    int expected = oldv;
106
367894
    (void) atomic_compare_exchange_strong_explicit (x, &expected, newv, memory_order_seq_cst, memory_order_seq_cst);
107
367894
    return expected;
108
}
109

            
110
#define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) \
111
  _cairo_atomic_int_cmpxchg_return_old_impl(x, oldv, newv)
112

            
113
static cairo_always_inline cairo_bool_t
114
_cairo_atomic_ptr_cmpxchg_impl(cairo_atomic_intptr_t *x, void *oldv, void *newv)
115
{
116
5384796
    void *expected = oldv;
117
5384796
    return atomic_compare_exchange_strong_explicit (x, &expected, newv, memory_order_seq_cst, memory_order_seq_cst);
118
}
119

            
120
#define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \
121
  _cairo_atomic_ptr_cmpxchg_impl(x, oldv, newv)
122

            
123
static cairo_always_inline void *
124
_cairo_atomic_ptr_cmpxchg_return_old_impl(cairo_atomic_intptr_t *x, void *oldv, void *newv)
125
{
126
    void *expected = oldv;
127
    (void) atomic_compare_exchange_strong_explicit (x, &expected, newv, memory_order_seq_cst, memory_order_seq_cst);
128
    return expected;
129
}
130

            
131
#define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) \
132
  _cairo_atomic_ptr_cmpxchg_return_old_impl(x, oldv, newv)
133

            
134
#endif /* HAVE_C11_ATOMIC_PRIMITIVES */
135

            
136
/* C++11 atomic primitives were designed to be more flexible than the
137
 * __sync_* family of primitives.  Despite the name, they are available
138
 * in C as well as C++.  The motivating reason for using them is that
139
 * for _cairo_atomic_{int,ptr}_get, the compiler is able to see that
140
 * the load is intended to be atomic, as opposed to the __sync_*
141
 * version, below, where the load looks like a plain load.  Having
142
 * the load appear atomic to the compiler is particular important for
143
 * tools like ThreadSanitizer so they don't report false positives on
144
 * memory operations that we intend to be atomic.
145
 */
146
#if HAVE_CXX11_ATOMIC_PRIMITIVES
147

            
148
#define HAS_ATOMIC_OPS 1
149

            
150
typedef int cairo_atomic_int_t;
151
typedef intptr_t cairo_atomic_intptr_t;
152

            
153
static cairo_always_inline int
154
_cairo_atomic_int_get (cairo_atomic_int_t *x)
155
{
156
    return __atomic_load_n(x, __ATOMIC_SEQ_CST);
157
}
158

            
159
static cairo_always_inline int
160
_cairo_atomic_int_get_relaxed (cairo_atomic_int_t *x)
161
{
162
    return __atomic_load_n(x, __ATOMIC_RELAXED);
163
}
164

            
165
static cairo_always_inline void
166
_cairo_atomic_int_set_relaxed (cairo_atomic_int_t *x, int val)
167
{
168
    __atomic_store_n(x, val, __ATOMIC_RELAXED);
169
}
170

            
171
static cairo_always_inline void *
172
_cairo_atomic_ptr_get (cairo_atomic_intptr_t *x)
173
{
174
    return (void*)__atomic_load_n(x, __ATOMIC_SEQ_CST);
175
}
176

            
177
# define _cairo_atomic_int_inc(x) ((void) __atomic_fetch_add(x, 1, __ATOMIC_SEQ_CST))
178
# define _cairo_atomic_int_dec(x) ((void) __atomic_fetch_sub(x, 1, __ATOMIC_SEQ_CST))
179
# define _cairo_atomic_int_dec_and_test(x) (__atomic_fetch_sub(x, 1, __ATOMIC_SEQ_CST) == 1)
180

            
181
static cairo_always_inline cairo_bool_t
182
_cairo_atomic_int_cmpxchg_impl(cairo_atomic_int_t *x,
183
			       int                 oldv,
184
			       int                 newv)
185
{
186
    int expected = oldv;
187
    return __atomic_compare_exchange_n(x, &expected, newv, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
188
}
189

            
190
#define _cairo_atomic_int_cmpxchg(x, oldv, newv) \
191
  _cairo_atomic_int_cmpxchg_impl(x, oldv, newv)
192

            
193
static cairo_always_inline int
194
_cairo_atomic_int_cmpxchg_return_old_impl(cairo_atomic_int_t *x,
195
					  int                 oldv,
196
					  int                 newv)
197
{
198
    int expected = oldv;
199
    (void) __atomic_compare_exchange_n(x, &expected, newv, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
200
    return expected;
201
}
202

            
203
#define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) \
204
  _cairo_atomic_int_cmpxchg_return_old_impl(x, oldv, newv)
205

            
206
static cairo_always_inline cairo_bool_t
207
_cairo_atomic_ptr_cmpxchg_impl(cairo_atomic_intptr_t *x, void *oldv, void *newv)
208
{
209
    intptr_t expected = (intptr_t)oldv;
210
    return __atomic_compare_exchange_n(x, &expected, (intptr_t)newv, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
211
}
212

            
213
#define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \
214
  _cairo_atomic_ptr_cmpxchg_impl(x, oldv, newv)
215

            
216
static cairo_always_inline void *
217
_cairo_atomic_ptr_cmpxchg_return_old_impl(cairo_atomic_intptr_t *x, void *oldv, void *newv)
218
{
219
    intptr_t expected = (intptr_t)oldv;
220
    (void) __atomic_compare_exchange_n(x, &expected, (intptr_t)newv, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
221
    return (void*)expected;
222
}
223

            
224
#define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) \
225
  _cairo_atomic_ptr_cmpxchg_return_old_impl(x, oldv, newv)
226

            
227
#endif /* HAVE_CXX11_ATOMIC_PRIMITIVES */
228

            
229
#if HAVE_GCC_LEGACY_ATOMICS
230

            
231
#define HAS_ATOMIC_OPS 1
232

            
233
typedef int cairo_atomic_int_t;
234
typedef intptr_t cairo_atomic_intptr_t;
235

            
236
static cairo_always_inline int
237
_cairo_atomic_int_get (cairo_atomic_int_t *x)
238
{
239
    __sync_synchronize ();
240
    return *x;
241
}
242

            
243
static cairo_always_inline int
244
_cairo_atomic_int_get_relaxed (cairo_atomic_int_t *x)
245
{
246
    return *x;
247
}
248

            
249
static cairo_always_inline void
250
_cairo_atomic_int_set_relaxed (cairo_atomic_int_t *x, int val)
251
{
252
    *x = val;
253
}
254

            
255
static cairo_always_inline void *
256
_cairo_atomic_ptr_get (cairo_atomic_intptr_t *x)
257
{
258
    __sync_synchronize ();
259
    return (void*)*x;
260
}
261

            
262
# define _cairo_atomic_int_inc(x) ((void) __sync_fetch_and_add(x, 1))
263
# define _cairo_atomic_int_dec(x) ((void) __sync_fetch_and_add(x, -1))
264
# define _cairo_atomic_int_dec_and_test(x) (__sync_fetch_and_add(x, -1) == 1)
265
# define _cairo_atomic_int_cmpxchg(x, oldv, newv) __sync_bool_compare_and_swap (x, oldv, newv)
266
# define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) __sync_val_compare_and_swap (x, oldv, newv)
267

            
268
# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \
269
    __sync_bool_compare_and_swap ((cairo_atomic_intptr_t*)x, (cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv)
270

            
271
# define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) \
272
    _cairo_atomic_intptr_to_voidptr (__sync_val_compare_and_swap ((cairo_atomic_intptr_t*)x, (cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv))
273

            
274
#endif /* HAVE_GCC_LEGACY_ATOMICS */
275

            
276
#if HAVE_LIB_ATOMIC_OPS
277
#include <atomic_ops.h>
278

            
279
#define HAS_ATOMIC_OPS 1
280

            
281
typedef  AO_t cairo_atomic_int_t;
282

            
283
# define _cairo_atomic_int_get(x) (AO_load_full (x))
284
# define _cairo_atomic_int_get_relaxed(x) (AO_load_full (x))
285
# define _cairo_atomic_int_set_relaxed(x, val) (AO_store_full ((x), (val)))
286

            
287
# define _cairo_atomic_int_inc(x) ((void) AO_fetch_and_add1_full(x))
288
# define _cairo_atomic_int_dec(x) ((void) AO_fetch_and_sub1_full(x))
289
# define _cairo_atomic_int_dec_and_test(x) (AO_fetch_and_sub1_full(x) == 1)
290
# define _cairo_atomic_int_cmpxchg(x, oldv, newv) AO_compare_and_swap_full(x, oldv, newv)
291

            
292
typedef intptr_t cairo_atomic_intptr_t;
293

            
294
# define _cairo_atomic_ptr_get(x) _cairo_atomic_intptr_to_voidptr (AO_load_full (x))
295
# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \
296
    _cairo_atomic_int_cmpxchg ((cairo_atomic_intptr_t*)(x), (cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv)
297

            
298
#endif
299

            
300
#if HAVE_OS_ATOMIC_OPS
301
#include <libkern/OSAtomic.h>
302

            
303
#define HAS_ATOMIC_OPS 1
304

            
305
typedef int32_t cairo_atomic_int_t;
306
typedef intptr_t cairo_atomic_intptr_t;
307

            
308
# define _cairo_atomic_int_get(x) (OSMemoryBarrier(), *(x))
309
# define _cairo_atomic_int_get_relaxed(x) *(x)
310
# define _cairo_atomic_int_set_relaxed(x, val) *(x) = (val)
311

            
312
# define _cairo_atomic_int_inc(x) ((void) OSAtomicIncrement32Barrier (x))
313
# define _cairo_atomic_int_dec(x) ((void) OSAtomicDecrement32Barrier (x))
314
# define _cairo_atomic_int_dec_and_test(x) (OSAtomicDecrement32Barrier (x) == 0)
315
# define _cairo_atomic_int_cmpxchg(x, oldv, newv) OSAtomicCompareAndSwap32Barrier(oldv, newv, x)
316

            
317
#if SIZEOF_VOID_P==4
318
# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \
319
    OSAtomicCompareAndSwap32Barrier((cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv, (cairo_atomic_intptr_t *)x)
320

            
321
#elif SIZEOF_VOID_P==8
322
# define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) \
323
    OSAtomicCompareAndSwap64Barrier((cairo_atomic_intptr_t)oldv, (cairo_atomic_intptr_t)newv, (cairo_atomic_intptr_t *)x)
324

            
325
#else
326
#error No matching integer pointer type
327
#endif
328

            
329
# define _cairo_atomic_ptr_get(x) (OSMemoryBarrier(), *(x))
330

            
331
#endif /* HAVE_OS_ATOMIC_OPS */
332

            
333
#if !defined(HAS_ATOMIC_OPS) && defined(_WIN32)
334
#include <windows.h>
335

            
336
#define HAS_ATOMIC_OPS 1
337

            
338
typedef LONG cairo_atomic_int_t;
339
typedef PVOID cairo_atomic_intptr_t;
340

            
341
static cairo_always_inline int
342
_cairo_atomic_int_get (cairo_atomic_int_t *x)
343
{
344
    MemoryBarrier ();
345
    return *x;
346
}
347

            
348
# define _cairo_atomic_int_get_relaxed(x) *(x)
349
# define _cairo_atomic_int_set_relaxed(x, val) *(x) = (val)
350

            
351
# define _cairo_atomic_int_inc(x) ((void) InterlockedIncrement (x))
352
# define _cairo_atomic_int_dec(x) ((void) InterlockedDecrement (x))
353
# define _cairo_atomic_int_dec_and_test(x) (InterlockedDecrement (x) == 0)
354

            
355
static cairo_always_inline cairo_bool_t
356
_cairo_atomic_int_cmpxchg (cairo_atomic_int_t *x,
357
                           int                 oldv,
358
                           int                 newv)
359
{
360
    return InterlockedCompareExchange (x, (LONG)newv, (LONG)oldv) == oldv;
361
}
362

            
363
static cairo_always_inline void *
364
_cairo_atomic_ptr_get (cairo_atomic_intptr_t *x)
365
{
366
    MemoryBarrier ();
367
    return (void *) *x;
368
}
369

            
370
static cairo_always_inline cairo_bool_t
371
_cairo_atomic_ptr_cmpxchg (cairo_atomic_intptr_t *x, void *oldv, void *newv)
372
{
373
    return InterlockedCompareExchangePointer (x, newv, oldv) == oldv;
374
}
375

            
376
static cairo_always_inline void *
377
_cairo_atomic_ptr_cmpxchg_return_old (cairo_atomic_intptr_t *x, void *oldv, void *newv)
378
{
379
    return InterlockedCompareExchangePointer (x, newv, oldv);
380
}
381

            
382
#endif /* !defined(HAS_ATOMIC_OPS) && defined(_WIN32) */
383

            
384

            
385
#ifndef HAS_ATOMIC_OPS
386

            
387
typedef int cairo_atomic_int_t;
388
typedef intptr_t cairo_atomic_intptr_t;
389

            
390
cairo_private void
391
_cairo_atomic_int_inc (cairo_atomic_int_t *x);
392

            
393
#define _cairo_atomic_int_dec(x) _cairo_atomic_int_dec_and_test(x)
394

            
395
cairo_private cairo_bool_t
396
_cairo_atomic_int_dec_and_test (cairo_atomic_int_t *x);
397

            
398
cairo_private int
399
_cairo_atomic_int_cmpxchg_return_old_impl (cairo_atomic_int_t *x, int oldv, int newv);
400

            
401
cairo_private void *
402
_cairo_atomic_ptr_cmpxchg_return_old_impl (cairo_atomic_intptr_t *x, void *oldv, void *newv);
403

            
404
#define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_int_cmpxchg_return_old_impl (x, oldv, newv)
405
#define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_ptr_cmpxchg_return_old_impl (x, oldv, newv)
406

            
407
#ifdef ATOMIC_OP_NEEDS_MEMORY_BARRIER
408
cairo_private int
409
_cairo_atomic_int_get (cairo_atomic_int_t *x);
410
cairo_private int
411
_cairo_atomic_int_get_relaxed (cairo_atomic_int_t *x);
412
void
413
_cairo_atomic_int_set_relaxed (cairo_atomic_int_t *x, int val);
414
cairo_private void*
415
_cairo_atomic_ptr_get(cairo_atomic_intptr_t *x);
416
#else
417
# define _cairo_atomic_int_get(x) (*x)
418
# define _cairo_atomic_int_get_relaxed(x) (*x)
419
# define _cairo_atomic_int_set_relaxed(x, val) (*x) = (val)
420
# define _cairo_atomic_ptr_get(x) (*x)
421
#endif
422

            
423
#else
424

            
425
/* Workaround GCC complaining about casts */
426
static cairo_always_inline void *
427
_cairo_atomic_intptr_to_voidptr (cairo_atomic_intptr_t x)
428
{
429
  return (void *) x;
430
}
431

            
432
static cairo_always_inline int
433
_cairo_atomic_int_cmpxchg_return_old_fallback(cairo_atomic_int_t *x, int oldv, int newv)
434
{
435
    int curr;
436

            
437
    do {
438
        curr = _cairo_atomic_int_get (x);
439
    } while (curr == oldv && !_cairo_atomic_int_cmpxchg (x, oldv, newv));
440

            
441
    return curr;
442
}
443

            
444
static cairo_always_inline void *
445
_cairo_atomic_ptr_cmpxchg_return_old_fallback(cairo_atomic_intptr_t *x, void *oldv, void *newv)
446
{
447
    void *curr;
448

            
449
    do {
450
        curr = _cairo_atomic_ptr_get (x);
451
    } while (curr == oldv && !_cairo_atomic_ptr_cmpxchg (x, oldv, newv));
452

            
453
    return curr;
454
}
455
#endif
456

            
457
#ifndef _cairo_atomic_int_cmpxchg_return_old
458
#define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_int_cmpxchg_return_old_fallback (x, oldv, newv)
459
#endif
460

            
461
#ifndef _cairo_atomic_ptr_cmpxchg_return_old
462
#define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) _cairo_atomic_ptr_cmpxchg_return_old_fallback (x, oldv, newv)
463
#endif
464

            
465
#ifndef _cairo_atomic_int_cmpxchg
466
#define _cairo_atomic_int_cmpxchg(x, oldv, newv) (_cairo_atomic_int_cmpxchg_return_old (x, oldv, newv) == oldv)
467
#endif
468

            
469
#ifndef _cairo_atomic_ptr_cmpxchg
470
#define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) (_cairo_atomic_ptr_cmpxchg_return_old (x, oldv, newv) == oldv)
471
#endif
472

            
473
#define _cairo_atomic_uint_get(x) _cairo_atomic_int_get(x)
474
#define _cairo_atomic_uint_cmpxchg(x, oldv, newv) \
475
    _cairo_atomic_int_cmpxchg((cairo_atomic_int_t *)x, oldv, newv)
476

            
477
#define _cairo_status_set_error(status, err) do { \
478
    int ret__; \
479
    assert (err < CAIRO_STATUS_LAST_STATUS); \
480
    assert (sizeof(*status) == sizeof(cairo_atomic_int_t)); \
481
    /* hide compiler warnings about cairo_status_t != int (gcc treats its as \
482
     * an unsigned integer instead, and about ignoring the return value. */  \
483
    ret__ = _cairo_atomic_int_cmpxchg ((cairo_atomic_int_t *) status, CAIRO_STATUS_SUCCESS, err); \
484
    (void) ret__; \
485
} while (0)
486

            
487
typedef cairo_atomic_int_t cairo_atomic_once_t;
488

            
489
#define CAIRO_ATOMIC_ONCE_UNINITIALIZED (0)
490
#define CAIRO_ATOMIC_ONCE_INITIALIZING  (1)
491
#define CAIRO_ATOMIC_ONCE_INITIALIZED   (2)
492
#define CAIRO_ATOMIC_ONCE_INIT          CAIRO_ATOMIC_ONCE_UNINITIALIZED
493

            
494
static cairo_always_inline cairo_bool_t
495
_cairo_atomic_init_once_enter(cairo_atomic_once_t *once)
496
{
497
56314
    if (likely(_cairo_atomic_int_get(once) == CAIRO_ATOMIC_ONCE_INITIALIZED))
498
52822
	return 0;
499

            
500
3492
    if (_cairo_atomic_int_cmpxchg(once,
501
				  CAIRO_ATOMIC_ONCE_UNINITIALIZED,
502
				  CAIRO_ATOMIC_ONCE_INITIALIZING))
503
3492
	return 1;
504

            
505
    while (_cairo_atomic_int_get(once) != CAIRO_ATOMIC_ONCE_INITIALIZED) {}
506
    return 0;
507
}
508

            
509
static cairo_always_inline void
510
_cairo_atomic_init_once_leave(cairo_atomic_once_t *once)
511
{
512
3492
    if (unlikely(!_cairo_atomic_int_cmpxchg(once,
513
					    CAIRO_ATOMIC_ONCE_INITIALIZING,
514
					    CAIRO_ATOMIC_ONCE_INITIALIZED)))
515
	assert (0 && "incorrect use of _cairo_atomic_init_once API (once != CAIRO_ATOMIC_ONCE_INITIALIZING)");
516
3492
}
517

            
518
CAIRO_END_DECLS
519

            
520
#endif