lichao
2021-05-10 77a6c3512a44dfe6540dde71946e6484fe4f173f
src/robust.h
@@ -86,6 +86,8 @@
class NullMutex
{
public:
   template <class... T>
   explicit NullMutex(T &&...t) {} // easy test.
   bool try_lock() { return true; }
   void lock() {}
   void unlock() {}
@@ -113,8 +115,10 @@
      mkdir(dir.c_str(), 0777);
      return dir + "/fm_" + std::to_string(id);
   }
   static int Open(id_t id) { return open(GetPath(id).c_str(), O_CREAT | O_RDWR, 0666); }
   static int Open(id_t id) { return open(GetPath(id).c_str(), O_CREAT | O_RDONLY, 0666); }
   static int Close(int fd) { return close(fd); }
   void FLock();
   void FUnlock();
   id_t id_;
   int fd_;
   std::mutex mtx_;
@@ -132,17 +136,11 @@
{
public:
   SemMutex(key_t key) :
       key_(key), sem_id_(semget(key, 1, 0666 | IPC_CREAT))
       key_(key), sem_id_(semget(key, 1, 0666))
   {
      if (sem_id_ == -1) { throw "error create semaphore."; }
      union semun init_val;
      init_val.val = 1;
      semctl(sem_id_, 0, SETVAL, init_val);
   }
   ~SemMutex()
   {
      // semctl(sem_id_, 0, IPC_RMID, semun{});
   }
   ~SemMutex() {}
   bool try_lock()
   {