Jump to content

e6daniel

Members
  • Content Count

    2
  • Joined

  • Last visited

  1. e6daniel

    implementing a fair mutex

    Thank you soo much Philipp! You were absolutely correct that the implementation was not treating re-locks correctly. The below implemenation works in my scenarios "at least". I think it is a correct generic solution. class fair_mutex : public sc_mutex { std::queue<sc_process_handle> s_queue; public: virtual int lock() { if (m_owner == sc_get_current_process_handle()) return 0; s_queue.push(sc_get_current_process_handle()); while (s_queue.front() != sc_get_current_process_handle() || in_use()) { sc_core::wait(m_free); } m_owner = sc_get_current_process_handle(); s_queue.pop(); return 0; } };
  2. e6daniel

    implementing a fair mutex

    Hi! I am using this fair_mutex implementation in a SystemC application of mine. It is almost doing what it should albeit the mutex accidently slips through the odd user. I cannot spot the prblem :( Best Regards class fair_mutex : public sc_mutex { std::queue<sc_process_b *> s_queue; public: virtual int lock() { if (m_owner == sc_get_current_process_b()) return 0; s_queue.push(sc_get_current_process_b()); while (in_use()) { sc_core::wait(m_free); if (s_queue.front() == sc_get_current_process_b()) break; } m_owner = sc_get_current_process_b(); sc_core::wait(SC_ZERO_TIME); s_queue.pop(); return 0; } };
×