Skip to content

Commit

Permalink
replace frames vector with wait-free queue to eliminate data races
Browse files Browse the repository at this point in the history
  • Loading branch information
jmellorcrummey committed Nov 14, 2017
1 parent f27790a commit 425350e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion parseAPI/h/WaitFreeQueue.h
Expand Up @@ -127,13 +127,13 @@ class WaitFreeQueue {
}
return first;
};
private:
void clear() {
item_type *first;
while((first = pop())) {
delete first;
}
};
private:
void reset() {
head.store(0);
};
Expand Down
31 changes: 20 additions & 11 deletions parseAPI/src/Parser.C
Expand Up @@ -142,9 +142,9 @@ Parser::~Parser()
if(_parse_data)
delete _parse_data;

vector<ParseFrame *>::iterator fit = frames.begin();
for( ; fit != frames.end(); ++fit)
for(auto fit = frames.begin() ; fit != frames.end(); ++fit)
delete *fit;

frames.clear();
}

Expand Down Expand Up @@ -235,7 +235,7 @@ Parser::parse_at(
if(!(pf = _parse_data->findFrame(region,target))) {
pf = new ParseFrame(f,_parse_data);
init_frame(*pf);
frames.push_back(pf);
frames.insert(pf);
_parse_data->record_frame(pf);
}

Expand Down Expand Up @@ -303,7 +303,7 @@ Parser::parse_vanilla()

pf = new ParseFrame(hf,_parse_data);
init_frame(*pf);
frames.push_back(pf);
frames.insert(pf);
work.push_back(pf);
_parse_data->record_frame(pf);
}
Expand Down Expand Up @@ -465,7 +465,7 @@ vector<ParseFrame *> Parser::postProcessFrame(ParseFrame *pf, bool recursive) {

tf = new ParseFrame(pf->call_target,_parse_data);
init_frame(*tf);
frames.push_back(tf);
frames.insert(tf);
_parse_data->record_frame(tf);
}
if(likely(recursive))
Expand Down Expand Up @@ -798,12 +798,21 @@ void Parser::processCycle(vector<ParseFrame *> &work, bool recursive) {// If we'

void Parser::cleanup_frames() {
#if USE_OPENMP
#pragma omp parallel for schedule(auto)
for(unsigned i=0; i < frames.size(); ++i) {
ParseFrame *pf = frames[i];
if (pf) {
_parse_data->remove_frame(pf);
delete pf;
#pragma omp parallel
{
#pragma omp master
for (;;) {
auto entry = frames.pop();
if (!entry) break;
#pragma omp task
{
ParseFrame *pf = entry->value();
if (pf) {
_parse_data->remove_frame(pf);
delete pf;
}
delete entry;
}
}
}
#elif USE_CILK
Expand Down
2 changes: 1 addition & 1 deletion parseAPI/src/Parser.h
Expand Up @@ -83,7 +83,7 @@ class Parser {
ParseData * _parse_data;

// All allocated frames
vector<ParseFrame *> frames;
WaitFreeQueue<ParseFrame *> frames;

// Delayed frames
struct DelayedFrames : public boost::basic_lockable_adapter<boost::recursive_mutex> {
Expand Down
2 changes: 1 addition & 1 deletion parseAPI/src/ParserDetails.C
Expand Up @@ -277,7 +277,7 @@ Parser::tamper_post_processing(vector<ParseFrame *> &work, ParseFrame *pf) {
if (tf && !_parse_data->findFrame(tf->func->region(),
tf->func->addr())) {
init_frame(*tf);
frames.push_back(tf);
frames.insert(tf);
_parse_data->record_frame(tf);
_pcb.updateCodeBytes(pf->func->_tamper_addr - objLoad);
}
Expand Down

0 comments on commit 425350e

Please sign in to comment.