| 1 | #include <locks.hfa>
|
|---|
| 2 | #include <mutex_stmt.hfa>
|
|---|
| 3 | #include <stdio.h>
|
|---|
| 4 |
|
|---|
| 5 | #include "../bench.h"
|
|---|
| 6 |
|
|---|
| 7 | test_spinlock LOCKS;
|
|---|
| 8 |
|
|---|
| 9 | inline void lock( test_spinlock &a, test_spinlock &b ) {
|
|---|
| 10 | lock(a); lock(b);
|
|---|
| 11 | }
|
|---|
| 12 | inline void lock( test_spinlock &a, test_spinlock &b, test_spinlock &c, test_spinlock &d ) {
|
|---|
| 13 | lock(a); lock(b); lock(c); lock(d);
|
|---|
| 14 | }
|
|---|
| 15 | inline void lock( test_spinlock &a, test_spinlock &b, test_spinlock &c, test_spinlock &d, test_spinlock &e, test_spinlock &f, test_spinlock &g, test_spinlock &h ) {
|
|---|
| 16 | lock(a); lock(b); lock(c); lock(d); lock(e); lock(f); lock(g); lock(h);
|
|---|
| 17 | }
|
|---|
| 18 | inline void unlock( test_spinlock &a, test_spinlock &b ) {
|
|---|
| 19 | unlock(a); unlock(b);
|
|---|
| 20 | }
|
|---|
| 21 | inline void unlock( test_spinlock &a, test_spinlock &b, test_spinlock &c, test_spinlock &d ) {
|
|---|
| 22 | unlock(a); unlock(b); unlock(c); unlock(d);
|
|---|
| 23 | }
|
|---|
| 24 | inline void unlock( test_spinlock &a, test_spinlock &b, test_spinlock &c, test_spinlock &d, test_spinlock &e, test_spinlock &f, test_spinlock &g, test_spinlock &h ) {
|
|---|
| 25 | unlock(a); unlock(b); unlock(c); unlock(d); unlock(e); unlock(f); unlock(g); unlock(h);
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | bool done = false;
|
|---|
| 29 | uint64_t total = 0;
|
|---|
| 30 | thread worker {};
|
|---|
| 31 | static inline void ?{}( worker & this, cluster & clu ) {
|
|---|
| 32 | ((thread &)this){ clu };
|
|---|
| 33 | }
|
|---|
| 34 | void main( worker & w ) {
|
|---|
| 35 | BENCH( lock( LOCKS ); unlock( LOCKS );, total, done )
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | int main( int argc, char * argv[] ) {
|
|---|
| 39 | BENCH_START()
|
|---|
| 40 | cluster clus;
|
|---|
| 41 | processor * proc[threads];
|
|---|
| 42 | for ( i; threads ) // create procs
|
|---|
| 43 | (*(proc[i] = alloc())){clus};
|
|---|
| 44 |
|
|---|
| 45 | worker * w[threads];
|
|---|
| 46 | for ( i; threads ) // create threads
|
|---|
| 47 | (*(w[i] = alloc())){ clus };
|
|---|
| 48 |
|
|---|
| 49 | sleep( 10`s );
|
|---|
| 50 | done = true;
|
|---|
| 51 |
|
|---|
| 52 | for ( i; threads ) // delete threads
|
|---|
| 53 | delete(w[i]);
|
|---|
| 54 |
|
|---|
| 55 | for ( i; threads ) // delete procs
|
|---|
| 56 | delete(proc[i]);
|
|---|
| 57 | printf( "%lu\n", total );
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | // Local Variables: //
|
|---|
| 61 | // tab-width: 4 //
|
|---|
| 62 | // End: //
|
|---|