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 #include "util-unittest.h"
28 
29 #ifdef UNITTESTS
30 
31 static int SCAtomicTest01(void)
32 {
33  int result = 0;
34  int a = 10;
35  int b = 20;
36  int *temp_int = NULL;
37 
38  SC_ATOMIC_DECLARE(void *, temp);
39  SC_ATOMIC_INITPTR(temp);
40 
41  temp_int = SC_ATOMIC_GET(temp);
42  if (temp_int != NULL)
43  goto end;
44 
45  (void)SC_ATOMIC_SET(temp, &a);
46  temp_int = SC_ATOMIC_GET(temp);
47  if (temp_int == NULL)
48  goto end;
49  if (*temp_int != a)
50  goto end;
51 
52  (void)SC_ATOMIC_SET(temp, &b);
53  temp_int = SC_ATOMIC_GET(temp);
54  if (temp_int == NULL)
55  goto end;
56  if (*temp_int != b)
57  goto end;
58 
59  result = 1;
60 
61  end:
62  return result;
63 }
64 
65 #endif /* UNITTESTS */
66 
68 {
69 #ifdef UNITTESTS
70  UtRegisterTest("SCAtomicTest01", SCAtomicTest01);
71 #endif
72 }
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:103
util-unittest.h
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:67
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