summaryrefslogtreecommitdiff
path: root/node/Condition.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@zerotier.com>2013-08-12 16:18:35 -0400
committerAdam Ierymenko <adam.ierymenko@zerotier.com>2013-08-12 16:18:35 -0400
commit36af3d92ecb4148a74c14896f5b6a9dcea0c1700 (patch)
tree0474c2add280ea6a33f25eff9bdf7ada7fe0c70d /node/Condition.hpp
parent2ad80063ec6e7d78d0d5b492f6065563792de05c (diff)
downloadinfinitytier-36af3d92ecb4148a74c14896f5b6a9dcea0c1700.tar.gz
infinitytier-36af3d92ecb4148a74c14896f5b6a9dcea0c1700.zip
Windows build work: condition, mutex, thread, udp socket...
Diffstat (limited to 'node/Condition.hpp')
-rw-r--r--node/Condition.hpp66
1 files changed, 50 insertions, 16 deletions
diff --git a/node/Condition.hpp b/node/Condition.hpp
index 2ce8c98f..4b2d32ca 100644
--- a/node/Condition.hpp
+++ b/node/Condition.hpp
@@ -28,9 +28,57 @@
#ifndef _ZT_CONDITION_HPP
#define _ZT_CONDITION_HPP
+#include "Constants.hpp"
#include "NonCopyable.hpp"
-#if defined(__APPLE__) || defined(__linux__) || defined(linux) || defined(__LINUX__) || defined(__linux)
+#ifdef __WINDOWS__
+
+#include <Windows.h>
+#include <stdlib.h>
+
+#include "Utils.hpp"
+
+namespace ZeroTier {
+
+class Condition : NonCopyable
+{
+public:
+ Condition()
+ throw()
+ {
+ _sem = CreateSemaphore(NULL,0,1,NULL);
+ }
+
+ ~Condition()
+ {
+ CloseHandle(_sem);
+ }
+
+ inline void wait() const
+ throw()
+ {
+ WaitForSingleObject(_sem,INFINITE);
+ }
+
+ inline void wait(unsigned long ms) const
+ throw()
+ {
+ WaitForSingleObject(_sem,(DWORD)ms);
+ }
+
+ inline void signal() const
+ throw()
+ {
+ ReleaseSemaphore(_sem,1,NULL);
+ }
+
+private:
+ HANDLE _sem;
+};
+
+} // namespace ZeroTier
+
+#else // !__WINDOWS__
#include <time.h>
#include <stdlib.h>
@@ -88,20 +136,6 @@ private:
} // namespace ZeroTier
-#endif // Apple / Linux
-
-#ifdef _WIN32
-
-#include <stdlib.h>
-#include <Windows.h>
-
-namespace ZeroTier {
-
-error need windoze;
-// On Windows this will probably be implemented via Semaphores
-
-} // namespace ZeroTier
-
-#endif // _WIN32
+#endif // !__WINDOWS__
#endif