fork download
  1. class sequential_mutex
  2. {
  3. public:
  4. sequential_mutex() = default;
  5.  
  6. void lock(uint32_t id, cmd_mod mod)
  7. {
  8. std::unique_lock<std::mutex> wait_lock(wait_mtx_);
  9.  
  10. if(que_.empty() && mtx_.try_lock())
  11. return;
  12.  
  13. if(mod != cmd_mod::skip_enque)
  14. que_.push_back(id);
  15.  
  16. cv_.wait(wait_lock, [this, id](){
  17. return id == que_.front();
  18. });
  19.  
  20. assert(id == que_.front());
  21. que_.pop_front();
  22.  
  23. mtx_.lock();
  24. }
  25.  
  26. void unlock()
  27. {
  28. mtx_.unlock();
  29. cv_.notify_all();
  30. }
  31.  
  32. void enque(uint32_t tid)
  33. {
  34. std::unique_lock<std::mutex> wait_lock(wait_mtx_);
  35.  
  36. que_.push_back(tid);
  37. }
  38.  
  39. private:
  40. std::list<uint32_t> que_;
  41. std::mutex wait_mtx_;
  42. std::mutex mtx_;
  43. std::condition_variable cv_;
  44. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:6:19: error: ‘uint32_t’ has not been declared
         void lock(uint32_t id, cmd_mod mod)
                   ^~~~~~~~
prog.cpp:6:32: error: ‘cmd_mod’ has not been declared
         void lock(uint32_t id, cmd_mod mod)
                                ^~~~~~~
prog.cpp:32:20: error: ‘uint32_t’ has not been declared
         void enque(uint32_t tid)
                    ^~~~~~~~
prog.cpp:40:14: error: ‘list’ in namespace ‘std’ does not name a template type
         std::list<uint32_t> que_;
              ^~~~
prog.cpp:41:14: error: ‘mutex’ in namespace ‘std’ does not name a type
         std::mutex wait_mtx_;
              ^~~~~
prog.cpp:42:14: error: ‘mutex’ in namespace ‘std’ does not name a type
         std::mutex mtx_;
              ^~~~~
prog.cpp:43:14: error: ‘condition_variable’ in namespace ‘std’ does not name a type
         std::condition_variable cv_;
              ^~~~~~~~~~~~~~~~~~
prog.cpp: In member function ‘void sequential_mutex::lock(int, int)’:
prog.cpp:8:17: error: ‘unique_lock’ is not a member of ‘std’
                 std::unique_lock<std::mutex> wait_lock(wait_mtx_);
                 ^~~
prog.cpp:8:34: error: ‘mutex’ is not a member of ‘std’
                 std::unique_lock<std::mutex> wait_lock(wait_mtx_);
                                  ^~~
prog.cpp:8:56: error: ‘wait_mtx_’ was not declared in this scope
                 std::unique_lock<std::mutex> wait_lock(wait_mtx_);
                                                        ^~~~~~~~~
prog.cpp:8:65: error: ‘wait_lock’ was not declared in this scope
                 std::unique_lock<std::mutex> wait_lock(wait_mtx_);
                                                                 ^
prog.cpp:10:20: error: ‘que_’ was not declared in this scope
                 if(que_.empty() && mtx_.try_lock())
                    ^~~~
prog.cpp:10:36: error: ‘mtx_’ was not declared in this scope
                 if(que_.empty() && mtx_.try_lock())
                                    ^~~~
prog.cpp:13:27: error: ‘cmd_mod’ has not been declared
                 if(mod != cmd_mod::skip_enque)
                           ^~~~~~~
prog.cpp:14:25: error: ‘que_’ was not declared in this scope
                         que_.push_back(id);
                         ^~~~
prog.cpp:16:17: error: ‘cv_’ was not declared in this scope
                 cv_.wait(wait_lock, [this, id](){
                 ^~~
prog.cpp: In lambda function:
prog.cpp:17:38: error: ‘que_’ was not declared in this scope
                         return id == que_.front();
                                      ^~~~
prog.cpp: In member function ‘void sequential_mutex::lock(int, int)’:
prog.cpp:20:30: error: ‘que_’ was not declared in this scope
                 assert(id == que_.front());
                              ^~~~
prog.cpp:20:42: error: ‘assert’ was not declared in this scope
                 assert(id == que_.front());
                                          ^
prog.cpp:23:17: error: ‘mtx_’ was not declared in this scope
                 mtx_.lock();
                 ^~~~
prog.cpp: In member function ‘void sequential_mutex::unlock()’:
prog.cpp:28:17: error: ‘mtx_’ was not declared in this scope
                 mtx_.unlock();
                 ^~~~
prog.cpp:29:17: error: ‘cv_’ was not declared in this scope
                 cv_.notify_all();
                 ^~~
prog.cpp: In member function ‘void sequential_mutex::enque(int)’:
prog.cpp:34:17: error: ‘unique_lock’ is not a member of ‘std’
                 std::unique_lock<std::mutex> wait_lock(wait_mtx_);
                 ^~~
prog.cpp:34:34: error: ‘mutex’ is not a member of ‘std’
                 std::unique_lock<std::mutex> wait_lock(wait_mtx_);
                                  ^~~
prog.cpp:34:56: error: ‘wait_mtx_’ was not declared in this scope
                 std::unique_lock<std::mutex> wait_lock(wait_mtx_);
                                                        ^~~~~~~~~
prog.cpp:34:65: error: ‘wait_lock’ was not declared in this scope
                 std::unique_lock<std::mutex> wait_lock(wait_mtx_);
                                                                 ^
prog.cpp:36:17: error: ‘que_’ was not declared in this scope
                 que_.push_back(tid);
                 ^~~~
stdout
Standard output is empty