Line data Source code
1 :
2 : /* Copyright (c) 2010-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #include <pthread.h>
20 : #include <test.h>
21 : #include <lunchbox/clock.h>
22 : #include <lunchbox/compiler.h>
23 : #include <lunchbox/mtQueue.h>
24 : #include <lunchbox/thread.h>
25 : #include <iostream>
26 :
27 : #define NOPS 100000
28 : #define NTHREADS 4
29 :
30 1 : lunchbox::MTQueue< uint64_t > queue;
31 1 : lunchbox::MTQueue< uint64_t >::Group group( NTHREADS + 1 );
32 :
33 : #ifdef LB_GCC_4_6_OR_LATER
34 : # pragma GCC diagnostic ignored "-Wunused-but-set-variable"
35 : #endif
36 4 : class ReadThread : public lunchbox::Thread
37 : {
38 : public:
39 4 : virtual ~ReadThread() {}
40 4 : virtual void run() { run_(); }
41 :
42 5 : static void run_()
43 : {
44 5 : uint64_t item = 0xffffffffffffffffull;
45 : #ifndef NDEBUG
46 5 : uint64_t last = 0;
47 : #endif
48 99610 : while( queue.popBarrier( item, group ))
49 : {
50 : #ifndef NDEBUG
51 99661 : TESTINFO( last < item, last << " >= " << item );
52 99600 : last = item;
53 : #endif
54 : }
55 5 : TEST( queue.isEmpty( ));
56 5 : }
57 : };
58 :
59 1 : int main( int, char** )
60 : {
61 5 : ReadThread reader[ NTHREADS ];
62 5 : for( size_t i = 0; i < NTHREADS; ++i )
63 4 : TEST( reader[i].start( ));
64 :
65 2 : lunchbox::Clock clock;
66 100000 : for( size_t i = 1 ; i < NOPS; ++i )
67 99999 : queue.push( i );
68 1 : const float time = clock.getTimef();
69 :
70 1 : ReadThread::run_();
71 :
72 5 : for( size_t i = 0; i < NTHREADS; ++i )
73 4 : TEST( reader[i].join( ));
74 :
75 1 : std::cout << NOPS/time << " writes/ms" << std::endl;
76 6 : return EXIT_SUCCESS;
77 3 : }
|