suricata
util-atomic.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2012 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
22  */
23 
24 #include "suricata-common.h"
25 #include "suricata.h"
26 #include "util-atomic.h"
27 
28 #ifdef UNITTESTS
29 
30 static int SCAtomicTest01(void)
31 {
32  int result = 0;
33  int a = 10;
34  int b = 20;
35  int *temp_int = NULL;
36 
37  SC_ATOMIC_DECLARE(void *, temp);
38  SC_ATOMIC_INITPTR(temp);
39 
40  temp_int = SC_ATOMIC_GET(temp);
41  if (temp_int != NULL)
42  goto end;
43 
44  (void)SC_ATOMIC_SET(temp, &a);
45  temp_int = SC_ATOMIC_GET(temp);
46  if (temp_int == NULL)
47  goto end;
48  if (*temp_int != a)
49  goto end;
50 
51  (void)SC_ATOMIC_SET(temp, &b);
52  temp_int = SC_ATOMIC_GET(temp);
53  if (temp_int == NULL)
54  goto end;
55  if (*temp_int != b)
56  goto end;
57 
58  result = 1;
59 
60  end:
61  return result;
62 }
63 
64 #endif /* UNITTESTS */
65 
67 {
68 #ifdef UNITTESTS
69  UtRegisterTest("SCAtomicTest01", SCAtomicTest01);
70 #endif
71 }
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:386
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:101
util-atomic.h
SC_ATOMIC_DECLARE
#define SC_ATOMIC_DECLARE(type, name)
wrapper for declaring atomic variables.
Definition: util-atomic.h:280
SCAtomicRegisterTests
void SCAtomicRegisterTests(void)
Definition: util-atomic.c:66
suricata-common.h
SC_ATOMIC_INITPTR
#define SC_ATOMIC_INITPTR(name)
Definition: util-atomic.h:317
suricata.h
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:375