zxs 2 months ago
parent
commit
ef271dff3f
1 changed files with 6 additions and 3 deletions
  1. 6 3
      robot/robotics/singleton.hpp

+ 6 - 3
robot/robotics/singleton.hpp

@@ -13,11 +13,14 @@
 #ifdef WINDOWS_BUILD
 #include <windows.h>
 #elif LINUX_BUILD
-#include <fcntl.h>
+#include <sys/file.h>
 #include <unistd.h>
 #include <stdio.h>
 #endif
-
+#ifdef SINGLETON
+#else
+#define SINGLETON(value) {v3::singleton single; if (single.locker(value)) return 0;}
+#endif // SINGLETON
 namespace robotics {
     namespace v3 {
         class singleton {
@@ -31,7 +34,7 @@ namespace robotics {
 #elif LINUX_BUILD
                 std::string file = "/tmp/" + value + ".lock";
                 fd_ = open(file.c_str(), O_CREAT | O_RDWR, 0666);
-                return flock(fd, LOCK_EX | LOCK_NB) == -1;
+                return flock(fd_, LOCK_EX | LOCK_NB) == -1;
 #endif
             }
             ~singleton() {