|
@@ -822,33 +822,20 @@ struct graph
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-
|
|
|
-std::atomic<int> g_init_flag(0);
|
|
|
-graph g_graph;
|
|
|
-
|
|
|
+safe_shared_ptr<graph> g_graph(std::make_shared<graph>());
|
|
|
}//namespace
|
|
|
|
|
|
void card_path::init()
|
|
|
{
|
|
|
- //Ensure only ont thread can init path.
|
|
|
- int expect=0;
|
|
|
- if(g_init_flag.compare_exchange_strong(expect,1))
|
|
|
- {
|
|
|
- handle_path hp;
|
|
|
- //std::vector<base_path> opath=init_path(sites,v_list);
|
|
|
- sit_list::instance()->accept(hp);
|
|
|
- std::vector<base_path> opath=init_path(hp.ret,hp.v);
|
|
|
- g_graph.init(hp.v,opath);
|
|
|
+ std::shared_ptr<graph> local_graph=std::make_shared<graph>();
|
|
|
|
|
|
- ++g_init_flag;
|
|
|
- }
|
|
|
- //if != 2 then wait here until init over.
|
|
|
- while(g_init_flag.load()!=2)
|
|
|
- {
|
|
|
- std::this_thread::sleep_for (std::chrono::seconds(1));
|
|
|
- }
|
|
|
-}
|
|
|
+ handle_path hp;
|
|
|
+ sit_list::instance()->accept(hp);
|
|
|
+ std::vector<base_path> opath=init_path(hp.ret,hp.v);
|
|
|
+ local_graph->init(hp.v,opath);
|
|
|
|
|
|
+ g_graph.set(local_graph);
|
|
|
+}
|
|
|
|
|
|
card_path&card_path::inst()
|
|
|
{
|
|
@@ -858,17 +845,17 @@ card_path&card_path::inst()
|
|
|
|
|
|
std::vector<point> card_path::find_path(const point&from,const point&to)const
|
|
|
{
|
|
|
- return g_graph.find(from,to);
|
|
|
+ return g_graph.get()->find(from,to);
|
|
|
}
|
|
|
|
|
|
bool card_path::is_at_path(const point&pt)const
|
|
|
{
|
|
|
- return g_graph.is_at_path(pt);
|
|
|
+ return g_graph.get()->is_at_path(pt);
|
|
|
}
|
|
|
|
|
|
std::vector<line_v> card_path::find_possible_path(const point&from,double dist) const
|
|
|
{
|
|
|
- return std::move(g_graph.find_possible_path(from,dist));
|
|
|
+ return std::move(g_graph.get()->find_possible_path(from,dist));
|
|
|
}
|
|
|
|
|
|
#ifdef __DEBUG__
|