1
/* $Id: atomic.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
* \page page_pjlib_atomic_test Test: Atomic Variable
26
* This file provides implementation of \b atomic_test(). It tests the
27
* functionality of the atomic variable API.
29
* \section atomic_test_sec Scope of the Test
32
* - pj_atomic_create()
37
* - pj_atomic_destroy()
40
* This file is <b>pjlib-test/atomic.c</b>
42
* \include pjlib-test/atomic.c
46
#if INCLUDE_ATOMIC_TEST
51
pj_atomic_t *atomic_var;
54
pool = pj_pool_create(mem, NULL, 4096, 0, NULL);
59
rc = pj_atomic_create(pool, 111, &atomic_var);
64
/* get: check the value. */
65
if (pj_atomic_get(atomic_var) != 111)
69
pj_atomic_inc(atomic_var);
70
if (pj_atomic_get(atomic_var) != 112)
74
pj_atomic_dec(atomic_var);
75
if (pj_atomic_get(atomic_var) != 111)
79
pj_atomic_set(atomic_var, 211);
80
if (pj_atomic_get(atomic_var) != 211)
84
pj_atomic_add(atomic_var, 10);
85
if (pj_atomic_get(atomic_var) != 221)
88
/* check the value again. */
89
if (pj_atomic_get(atomic_var) != 221)
93
rc = pj_atomic_destroy(atomic_var);
97
pj_pool_release(pool);
104
/* To prevent warning about "translation unit is empty"
105
* when this test is disabled.
107
int dummy_atomic_test;
108
#endif /* INCLUDE_ATOMIC_TEST */