You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
60 lines
1.4 KiB
9 years ago
|
#ifndef DEPTREE_H
|
||
|
#define DEPTREE_H
|
||
|
#include <set>
|
||
|
#include <vector>
|
||
|
#include <string>
|
||
9 years ago
|
#include <pthread.h>
|
||
|
#include <time.h>
|
||
9 years ago
|
#include "globals.h"
|
||
9 years ago
|
|
||
|
class DepTree
|
||
|
{
|
||
9 years ago
|
typedef std::vector<DepTree*> LeafVector;
|
||
9 years ago
|
typedef std::map<std::string,DepTree*> DepTreeVars;
|
||
9 years ago
|
typedef std::set<DepTree*> NodeVector;
|
||
|
typedef std::set<DepTree*> CallStack;
|
||
9 years ago
|
enum NodeType {NOTDEF,ROOT,SAVE,PRINT,VAR};
|
||
|
|
||
|
typedef struct
|
||
|
{
|
||
|
const DepTree* root;
|
||
|
int exitcode;
|
||
|
LeafVector leafs;
|
||
|
pthread_mutex_t leaf_mtx;
|
||
|
pthread_mutex_t root_mtx;
|
||
|
pthread_mutex_t vars_mtx;
|
||
|
pthread_mutex_t prsv_mtx;
|
||
|
pthread_mutex_t tree_mtx;
|
||
|
} thread_params;
|
||
|
|
||
9 years ago
|
NodeVector parents;
|
||
|
NodeVector childrens;
|
||
9 years ago
|
NodeType type;
|
||
9 years ago
|
G_toType::size_type index;
|
||
9 years ago
|
std::string name;
|
||
9 years ago
|
mutable bool visited;
|
||
9 years ago
|
|
||
9 years ago
|
int CreateNodeFromVar(const std::string& var, DepTreeVars& vars, CallStack& callstack);
|
||
|
int CreateNodeFromSP(NodeType list, G_toType::size_type ind, DepTreeVars& vars);
|
||
9 years ago
|
LeafVector FindLeafNodes() const;
|
||
9 years ago
|
public:
|
||
9 years ago
|
DepTree():type(DepTree::NOTDEF),visited(false) {}
|
||
9 years ago
|
DepTree(const DepTree&) = delete;
|
||
|
~DepTree()
|
||
|
{
|
||
|
for(auto& i:parents) i->childrens.erase(this);
|
||
|
for(auto& i:childrens)
|
||
|
{
|
||
|
i->parents.erase(this);
|
||
|
if(i->parents.size()==0) delete i;
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
int CreateGlobalTree(UsedType& used);
|
||
9 years ago
|
int EvaluateTree(unsigned int nthreads);
|
||
|
friend void* TreeEvaluateM(void* arg);
|
||
|
friend void* TreeEvaluate (void* arg);
|
||
9 years ago
|
};
|
||
|
|
||
|
#endif
|