Move template parameter in Thread to a more logical scope location.

This commit is contained in:
Adam Ierymenko 2013-08-08 09:19:36 -04:00
parent 20f8668c28
commit 8a46452a70
10 changed files with 20 additions and 21 deletions

View file

@ -187,7 +187,7 @@ EthernetTap::EthernetTap(
TRACE("tap %s created",_dev); TRACE("tap %s created",_dev);
_thread = Thread<EthernetTap>::start(this); _thread = Thread::start(this);
} }
#endif // __LINUX__ #endif // __LINUX__
@ -271,14 +271,14 @@ EthernetTap::EthernetTap(
::pipe(_shutdownSignalPipe); ::pipe(_shutdownSignalPipe);
_thread = Thread<EthernetTap>::start(this); _thread = Thread::start(this);
} }
#endif // __APPLE__ #endif // __APPLE__
EthernetTap::~EthernetTap() EthernetTap::~EthernetTap()
{ {
::write(_shutdownSignalPipe[1],"\0",1); // causes thread to exit ::write(_shutdownSignalPipe[1],"\0",1); // causes thread to exit
Thread<EthernetTap>::join(_thread); Thread::join(_thread);
::close(_fd); ::close(_fd);
} }

View file

@ -180,7 +180,7 @@ private:
const unsigned int _mtu; const unsigned int _mtu;
const RuntimeEnvironment *_r; const RuntimeEnvironment *_r;
Thread<EthernetTap> _thread; Thread _thread;
std::set<InetAddress> _ips; std::set<InetAddress> _ips;
Mutex _ips_m; Mutex _ips_m;

View file

@ -431,7 +431,7 @@ Node::ReasonForTermination Node::run()
if (lastDelayDelta >= ZT_SLEEP_WAKE_DETECTION_THRESHOLD) { if (lastDelayDelta >= ZT_SLEEP_WAKE_DETECTION_THRESHOLD) {
resynchronize = true; resynchronize = true;
LOG("probable suspend/resume detected, pausing a moment for things to settle..."); LOG("probable suspend/resume detected, pausing a moment for things to settle...");
Thread<Node>::sleep(ZT_SLEEP_WAKE_SETTLE_TIME); Thread::sleep(ZT_SLEEP_WAKE_SETTLE_TIME);
} }
// Periodically check our network environment, sending pings out to all // Periodically check our network environment, sending pings out to all

View file

@ -62,7 +62,7 @@ Service::Service(const RuntimeEnvironment *renv,const char *name,const char *pat
_childStderr(0), _childStderr(0),
_run(true) _run(true)
{ {
_thread = Thread<Service>::start(this); _thread = Thread::start(this);
} }
Service::~Service() Service::~Service()
@ -77,14 +77,14 @@ Service::~Service()
pid = 0; pid = 0;
break; break;
} }
Thread<Service>::sleep(100); Thread::sleep(100);
} }
if (pid > 0) { if (pid > 0) {
::kill(pid,SIGKILL); ::kill(pid,SIGKILL);
waitpid(pid,&st,0); waitpid(pid,&st,0);
} }
} }
Thread<Service>::join(_thread); Thread::join(_thread);
} }
bool Service::send(const Dictionary &msg) bool Service::send(const Dictionary &msg)
@ -136,7 +136,7 @@ void Service::threadMain()
close(in[0]); close(in[0]);
close(out[1]); close(out[1]);
close(err[1]); close(err[1]);
Thread<Service>::sleep(500); // give child time to start Thread::sleep(500); // give child time to start
_childStdin = in[1]; _childStdin = in[1];
_childStdout = out[0]; _childStdout = out[0];
_childStderr = err[0]; _childStderr = err[0];
@ -168,7 +168,7 @@ void Service::threadMain()
LOG("service %s exited with exit code: %d, delaying 1s to attempt relaunch",_name.c_str(),st); LOG("service %s exited with exit code: %d, delaying 1s to attempt relaunch",_name.c_str(),st);
Thread<Service>::sleep(1000); // wait to relaunch Thread::sleep(1000); // wait to relaunch
continue; continue;
} }
} }

View file

@ -114,7 +114,7 @@ public:
private: private:
const RuntimeEnvironment *_r; const RuntimeEnvironment *_r;
Thread<Service> _thread; Thread _thread;
std::string _path; std::string _path;
std::string _name; std::string _name;
void *_arg; void *_arg;

View file

@ -57,11 +57,8 @@ static void *___zt_threadMain(void *instance)
} }
/** /**
* A thread of a given class type * A thread identifier, and static methods to start and join threads
*
* @tparam C Class using Thread
*/ */
template<typename C>
class Thread class Thread
{ {
public: public:
@ -90,7 +87,9 @@ public:
* @param instance Instance whose threadMain() method gets called by new thread * @param instance Instance whose threadMain() method gets called by new thread
* @return Thread identifier * @return Thread identifier
* @throws std::runtime_error Unable to create thread * @throws std::runtime_error Unable to create thread
* @tparam C Class containing threadMain()
*/ */
template<typename C>
static inline Thread start(C *instance) static inline Thread start(C *instance)
throw(std::runtime_error) throw(std::runtime_error)
{ {

View file

@ -54,7 +54,7 @@ Topology::Topology(const RuntimeEnvironment *renv,const char *dbpath)
Utils::lockDownFile(dbpath,false); // node.db caches secrets Utils::lockDownFile(dbpath,false); // node.db caches secrets
_thread = Thread<Topology>::start(this); _thread = Thread::start(this);
} }
Topology::~Topology() Topology::~Topology()
@ -67,7 +67,7 @@ Topology::~Topology()
_peerDeepVerifyJobs.back().type = _PeerDeepVerifyJob::EXIT_THREAD; _peerDeepVerifyJobs.back().type = _PeerDeepVerifyJob::EXIT_THREAD;
} }
_peerDeepVerifyJobs_c.signal(); _peerDeepVerifyJobs_c.signal();
Thread<Topology>::join(_thread); Thread::join(_thread);
KISSDB_close(&_dbm); KISSDB_close(&_dbm);
} }

View file

@ -299,7 +299,7 @@ private:
}; };
const RuntimeEnvironment *const _r; const RuntimeEnvironment *const _r;
Thread<Topology> _thread; Thread _thread;
std::map< Address,SharedPtr<Peer> > _activePeers; std::map< Address,SharedPtr<Peer> > _activePeers;
Mutex _activePeers_m; Mutex _activePeers_m;

View file

@ -120,7 +120,7 @@ UdpSocket::UdpSocket(
} }
} }
_thread = Thread<UdpSocket>::start(this); _thread = Thread::start(this);
} }
UdpSocket::~UdpSocket() UdpSocket::~UdpSocket()
@ -131,7 +131,7 @@ UdpSocket::~UdpSocket()
::shutdown(s,SHUT_RDWR); ::shutdown(s,SHUT_RDWR);
::close(s); ::close(s);
} }
Thread<UdpSocket>::join(_thread); Thread::join(_thread);
} }
bool UdpSocket::send(const InetAddress &to,const void *data,unsigned int len,int hopLimit) bool UdpSocket::send(const InetAddress &to,const void *data,unsigned int len,int hopLimit)

View file

@ -94,7 +94,7 @@ public:
throw(); throw();
private: private:
Thread<UdpSocket> _thread; Thread _thread;
void (*_packetHandler)(UdpSocket *,void *,const InetAddress &,const void *,unsigned int); void (*_packetHandler)(UdpSocket *,void *,const InetAddress &,const void *,unsigned int);
void *_arg; void *_arg;
int _localPort; int _localPort;