Line data Source code
1 :
2 : /* Copyright (c) 2012-2014, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #define TEST_RUNTIME 300 // seconds
19 : #include "test.h"
20 :
21 : #include <lunchbox/clock.h>
22 : #include <lunchbox/monitor.h>
23 : #include <lunchbox/thread.h>
24 : #include <servus/uint128_t.h>
25 : #include <iostream>
26 :
27 : #define NLOOPS 200000
28 :
29 : using servus::uint128_t;
30 :
31 1 : lunchbox::Monitor< uint128_t > monitor;
32 1 : const uint128_t big( 10, 10 );
33 :
34 1 : class Thread : public lunchbox::Thread
35 : {
36 : public:
37 1 : virtual ~Thread() {}
38 1 : virtual void run()
39 : {
40 1 : const uint128_t invalid1( 0, 0 );
41 1 : const uint128_t invalid2( 1, 1 );
42 :
43 61829 : while( monitor != big )
44 : {
45 61827 : const uint128_t& result = monitor.waitLE( big );
46 61827 : TEST( result != invalid1 );
47 61827 : TEST( result != invalid2 );
48 61827 : TEST( monitor != invalid1 );
49 61827 : TEST( monitor != invalid2 );
50 : }
51 1 : }
52 : };
53 :
54 1 : int main( int, char** )
55 : {
56 1 : int64_t nOps = NLOOPS;
57 1 : const uint128_t valid1( 1, 0 );
58 1 : const uint128_t valid2( 0, 1 );
59 1 : Thread thread;
60 :
61 1 : monitor = valid1;
62 :
63 1 : TEST( thread.start( ));
64 200001 : while( --nOps )
65 : {
66 199999 : monitor = valid1; // cppcheck-suppress redundantAssignment
67 199999 : monitor = valid2;
68 : }
69 1 : monitor = big;
70 1 : TEST( thread.join( ));
71 :
72 1 : return EXIT_SUCCESS;
73 3 : }
|