1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
16 #include "sjme/multithread.h"
23 SJME_TEST_DECLARE(testSpinLock
)
26 sjme_thread_spinLock lock
;
29 /* Zero out lock state. */
30 memset(&lock
, 0, sizeof(lock
));
33 error
= sjme_thread_spinLockGrab(&lock
);
34 sjme_unit_equalI(test
, error
, SJME_ERROR_NONE
,
35 "Spin lock grab failed?");
36 sjme_unit_equalI(test
, sjme_atomic_sjme_jint_get(&lock
.count
), 1,
37 "Spin lock count not one?");
40 error
= sjme_thread_spinLockGrab(&lock
);
41 sjme_unit_equalI(test
, error
, SJME_ERROR_NONE
,
42 "Spin lock grab again failed?");
43 sjme_unit_equalI(test
, sjme_atomic_sjme_jint_get(&lock
.count
), 2,
44 "Spin lock count not two?");
48 error
= sjme_thread_spinLockRelease(&lock
, &count
);
49 sjme_unit_equalI(test
, error
, SJME_ERROR_NONE
,
50 "Spin lock release failed?");
51 sjme_unit_equalI(test
, count
, 1,
52 "Unlock count is not one?");
53 sjme_unit_equalI(test
, sjme_atomic_sjme_jint_get(&lock
.count
), 1,
54 "Spin lock count not one?");
58 error
= sjme_thread_spinLockRelease(&lock
, &count
);
59 sjme_unit_equalI(test
, error
, SJME_ERROR_NONE
,
60 "Spin lock release again failed?");
61 sjme_unit_equalI(test
, count
, 0,
62 "Unlock count is not zero?");
63 sjme_unit_equalI(test
, sjme_atomic_sjme_jint_get(&lock
.count
), 0,
64 "Spin lock count not zero?");
67 return SJME_TEST_RESULT_PASS
;