33 #ifndef SC_HOST_MUTEX_H_INCLUDED_ 34 #define SC_HOST_MUTEX_H_INCLUDED_ 36 #ifndef SC_INCLUDE_WINDOWS_H 37 # define SC_INCLUDE_WINDOWS_H // include Windows.h, if needed 42 #if !defined(WIN32) && !defined(_WIN32) // use pthread mutex 56 #if defined(WIN32) || defined(_WIN32) // use CRITICAL_SECTION on Windows 58 typedef CRITICAL_SECTION underlying_type;
60 void do_init() { InitializeCriticalSection( &m_mtx ); }
61 void do_lock() { EnterCriticalSection( &m_mtx ); }
62 bool do_trylock() {
return ( TryEnterCriticalSection( &m_mtx ) != 0 ); }
63 void do_unlock() { LeaveCriticalSection( &m_mtx ); }
64 void do_destroy() { DeleteCriticalSection( &m_mtx ); }
66 #else // use pthread mutex 69 # define SC_PTHREAD_NULL_ cma_c_null 70 # else // !defined(__hpux) 71 # define SC_PTHREAD_NULL_ NULL 74 typedef pthread_mutex_t underlying_type;
77 void do_lock() { pthread_mutex_lock( &m_mtx ); }
79 bool do_trylock() {
return ( pthread_mutex_trylock( &m_mtx ) == 0 ); }
81 bool do_trylock() {
return false; }
83 void do_unlock() { pthread_mutex_unlock( &m_mtx ); }
84 void do_destroy() { pthread_mutex_destroy( &m_mtx ); }
86 # undef SC_PTHREAD_NULL_ 88 #endif // platform-specific implementation 104 { do_lock();
return 0; }
108 {
return do_trylock() ? 0 : -1; }
113 { do_unlock();
return 0; }
116 underlying_type m_mtx;
The sc_mutex_if interface class.
The sc_mutex_if interface class.
The sc_host_mutex class, wrapping an OS mutex on the simulation host.