diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-07-31 14:09:32 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-07-31 14:09:32 -0700 |
| commit | b80c229d873ca51bf679ff9df90c8360dca5d0d7 (patch) | |
| tree | e5c4342b78dcb83f6c9312fff42d073e1f134ae3 /node/Thread.hpp | |
| parent | 9b93141dd0f39af70a867231ce8ba7cb34cd23e6 (diff) | |
| download | infinitytier-b80c229d873ca51bf679ff9df90c8360dca5d0d7.tar.gz infinitytier-b80c229d873ca51bf679ff9df90c8360dca5d0d7.zip | |
Tons of code cleanup, refactor Network to use EthernetTapFactory, probably also fix GitHub issue #90
Diffstat (limited to 'node/Thread.hpp')
| -rw-r--r-- | node/Thread.hpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/node/Thread.hpp b/node/Thread.hpp index 6426d5bb..a796af33 100644 --- a/node/Thread.hpp +++ b/node/Thread.hpp @@ -87,6 +87,8 @@ public: CancelSynchronousIo(t._th);
}
+ inline operator bool() const throw() { return (_th != NULL); }
+
private:
HANDLE _th;
DWORD _tid;
@@ -123,18 +125,21 @@ public: throw()
{
memset(&_tid,0,sizeof(_tid));
+ _started = false;
}
Thread(const Thread &t)
throw()
{
memcpy(&_tid,&(t._tid),sizeof(_tid));
+ _started = t._started;
}
inline Thread &operator=(const Thread &t)
throw()
{
memcpy(&_tid,&(t._tid),sizeof(_tid));
+ _started = t._started;
return *this;
}
@@ -151,19 +156,21 @@ public: throw(std::runtime_error)
{
Thread t;
+ t._started = true;
if (pthread_create(&t._tid,(const pthread_attr_t *)0,&___zt_threadMain<C>,instance))
throw std::runtime_error("pthread_create() failed, unable to create thread");
return t;
}
/**
- * Join to a thread, waiting for it to terminate
+ * Join to a thread, waiting for it to terminate (does nothing on null Thread values)
*
* @param t Thread to join
*/
static inline void join(const Thread &t)
{
- pthread_join(t._tid,(void **)0);
+ if (t._started)
+ pthread_join(t._tid,(void **)0);
}
/**
@@ -171,13 +178,13 @@ public: *
* @param ms Number of milliseconds to sleep
*/
- static inline void sleep(unsigned long ms)
- {
- usleep(ms * 1000);
- }
+ static inline void sleep(unsigned long ms) { usleep(ms * 1000); }
+
+ inline operator bool() const throw() { return (_started); }
private:
pthread_t _tid;
+ volatile bool _started;
};
} // namespace ZeroTier
|
