Skip to content

Commit

Permalink
replace CFG factory edge, block, and function lists with wait-free lists
Browse files Browse the repository at this point in the history
  • Loading branch information
jmellorcrummey committed Nov 6, 2017
1 parent 5133612 commit 760af5c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 21 deletions.
39 changes: 35 additions & 4 deletions parseAPI/h/CFGFactory.h
Expand Up @@ -32,6 +32,7 @@

#include "dyntypes.h"

#include "WaitFreeQueue.h"
#include "CFG.h"
#include "InstructionSource.h"

Expand Down Expand Up @@ -70,7 +71,7 @@ class flist_iter {
return (cur_ != iter.cur_);
}
};

#if 0
template <class T>
class fact_list {
public:
Expand Down Expand Up @@ -104,6 +105,36 @@ class fact_list {
private:
allocatable head;
};
#else
template <class T>
class fact_list {
public:
typedef typename WaitFreeQueue<T>::iterator iterator;
typedef std::forward_iterator_tag iterator_category;
// typedef const WaitFreeQueue<T>::const_iterator;
typedef T elem;
typedef T &reference;

fact_list() {
}

~fact_list() { }

void add(elem new_elem) {
queue.insert(new_elem);
}

// iterators
iterator begin() { return queue.begin(); }
iterator end() { return queue.end(); }
// const_iterator begin() const { return queue.begin(); }
// const_iterator end() const { return queue.end(); }
private:
WaitFreeQueue<T> queue;
};

#endif

/** An implementation of CFGFactory is responsible for allocation and
deallocation of CFG objects like Blocks, Edges, and Functions.
Overriding the default methods of this interface allows the parsing
Expand Down Expand Up @@ -153,9 +184,9 @@ class PARSER_EXPORT CFGFactory : public boost::basic_lockable_adapter<boost::rec
virtual void free_block(Block * b);
virtual void free_edge(Edge * e);

fact_list<Edge> edges_;
fact_list<Block> blocks_;
fact_list<Function> funcs_;
fact_list<Edge *> edges_;
fact_list<Block *> blocks_;
fact_list<Function *> funcs_;
};


Expand Down
34 changes: 17 additions & 17 deletions parseAPI/src/CFGFactory.C
Expand Up @@ -94,9 +94,9 @@ Function *
CFGFactory::_mkfunc(Address addr, FuncSource src, string name,
CodeObject * obj, CodeRegion * reg, Dyninst::InstructionSource * isrc)
{
boost::lock_guard<CFGFactory> g(*this);
// boost::lock_guard<CFGFactory> g(*this);
Function * ret = mkfunc(addr,src,name,obj,reg,isrc);
funcs_.add(*ret);
funcs_.add(ret);
ret->_src = src;
return ret;
}
Expand All @@ -114,10 +114,10 @@ CFGFactory::mkfunc(Address addr, FuncSource, string name,
Block *
CFGFactory::_mkblock(Function * f , CodeRegion *r, Address addr)
{
boost::lock_guard<CFGFactory> g(*this);
// boost::lock_guard<CFGFactory> g(*this);

Block * ret = mkblock(f, r, addr);
blocks_.add(*ret);
blocks_.add(ret);
return ret;
}

Expand All @@ -131,10 +131,10 @@ CFGFactory::mkblock(Function * f , CodeRegion *r, Address addr) {

Block *
CFGFactory::_mksink(CodeObject * obj, CodeRegion *r) {
boost::lock_guard<CFGFactory> g(*this);
// boost::lock_guard<CFGFactory> g(*this);

Block * ret = mksink(obj,r);
blocks_.add(*ret);
blocks_.add(ret);
return ret;
}

Expand All @@ -146,10 +146,10 @@ CFGFactory::mksink(CodeObject * obj, CodeRegion *r) {

Edge *
CFGFactory::_mkedge(Block * src, Block * trg, EdgeTypeEnum type) {
boost::lock_guard<CFGFactory> g(*this);
// boost::lock_guard<CFGFactory> g(*this);

Edge * ret = mkedge(src,trg,type);
edges_.add(*ret);
edges_.add(ret);
return ret;
}

Expand Down Expand Up @@ -200,20 +200,20 @@ CFGFactory::destroy_all() {
// XXX carefully calling free_* routines; could be faster and just
// call delete

fact_list<Edge>::iterator eit = edges_.begin();
fact_list<Edge *>::iterator eit = edges_.begin();
while(eit != edges_.end()) {
fact_list<Edge>::iterator cur = eit++;
destroy_edge(&*cur);
fact_list<Edge *>::iterator cur = eit++;
destroy_edge(*cur);
}
fact_list<Block>::iterator bit = blocks_.begin();
fact_list<Block *>::iterator bit = blocks_.begin();
while(bit != blocks_.end()) {
fact_list<Block>::iterator cur = bit++;
destroy_block(&*cur);
fact_list<Block *>::iterator cur = bit++;
destroy_block(*cur);
}
fact_list<Function>::iterator fit = funcs_.begin();
fact_list<Function *>::iterator fit = funcs_.begin();
while(fit != funcs_.end()) {
fact_list<Function>::iterator cur = fit++;
destroy_func(&*cur);
fact_list<Function *>::iterator cur = fit++;
destroy_func(*cur);
}
}

0 comments on commit 760af5c

Please sign in to comment.