|
Last change
on this file since 577 was 536, checked in by meunier, 13 years ago |
|
Added a tool which generates tests for the LL/SC table, in the soft/ directory.
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 |
|
|---|
| 2 | #ifndef _increment_hpp_
|
|---|
| 3 | #define _increment_hpp_
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | #include <stdio.h>
|
|---|
| 7 | #include <stdlib.h>
|
|---|
| 8 | #include <iostream>
|
|---|
| 9 | #include <sstream>
|
|---|
| 10 |
|
|---|
| 11 | #include "functions.h"
|
|---|
| 12 |
|
|---|
| 13 | using namespace std;
|
|---|
| 14 |
|
|---|
| 15 | class Increment {
|
|---|
| 16 | int lock_index;
|
|---|
| 17 | int var_index;
|
|---|
| 18 | int line_size;
|
|---|
| 19 |
|
|---|
| 20 | public:
|
|---|
| 21 |
|
|---|
| 22 | Increment(int nb_locks, int line_size, bool lock_in_line, bool vars_in_line){
|
|---|
| 23 | this->line_size = line_size;
|
|---|
| 24 |
|
|---|
| 25 | int index = randint(0, nb_locks - 1);
|
|---|
| 26 | int lock_size = (lock_in_line ? ceil((float) nb_locks / line_size) * line_size : nb_locks * line_size);
|
|---|
| 27 |
|
|---|
| 28 | lock_index = (lock_in_line ? index : index * line_size);
|
|---|
| 29 | var_index = (vars_in_line ? lock_size + index : lock_size + index * line_size);
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | ~Increment() {}
|
|---|
| 33 |
|
|---|
| 34 | string write_output() {
|
|---|
| 35 | stringstream res;
|
|---|
| 36 | res << " tab[" << var_index << "]++;" << endl;
|
|---|
| 37 |
|
|---|
| 38 | return res.str();
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | string write_task() {
|
|---|
| 42 | stringstream res;
|
|---|
| 43 | res << " take_lock(&tab[" << lock_index << "]);" << endl;
|
|---|
| 44 | res << " tab[" << var_index << "]++;" << endl;
|
|---|
| 45 | res << " release_lock(&tab[" << lock_index << "]);" << endl;
|
|---|
| 46 |
|
|---|
| 47 | return res.str();
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | };
|
|---|
| 51 |
|
|---|
| 52 | #endif
|
|---|
| 53 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.