Skip to content

Commit

Permalink
[librpthreads] MutexPosix: Remove m_isInit.
Browse files Browse the repository at this point in the history
pthread_mutex_init() always returns 0.

Also, we weren't handling errors properly anyway, so this didn't
really make a difference.
  • Loading branch information
GerbilSoft committed Jan 28, 2025
1 parent 4f1b6b9 commit 85a3c9d
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/librpthreads/MutexPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,14 @@ class Mutex

private:
pthread_mutex_t m_mutex;
bool m_isInit;
};

/**
* Create a mutex.
*/
inline Mutex::Mutex()
: m_isInit(false)
{
int ret = pthread_mutex_init(&m_mutex, nullptr);
assert(ret == 0);
if (ret == 0) {
m_isInit = true;
} else {
// FIXME: Do something if an error occurred here...
}
pthread_mutex_init(&m_mutex, nullptr);
}

/**
Expand All @@ -73,10 +65,7 @@ inline Mutex::Mutex()
*/
inline Mutex::~Mutex()
{
if (m_isInit) {
// TODO: Error checking.
pthread_mutex_destroy(&m_mutex);
}
pthread_mutex_destroy(&m_mutex);
}

/**
Expand All @@ -87,9 +76,6 @@ inline Mutex::~Mutex()
*/
inline int Mutex::lock(void)
{
if (!m_isInit)
return -EBADF;

// TODO: What error to return?
return pthread_mutex_lock(&m_mutex);
}
Expand All @@ -100,9 +86,6 @@ inline int Mutex::lock(void)
*/
inline int Mutex::unlock(void)
{
if (!m_isInit)
return -EBADF;

// TODO: What error to return?
return pthread_mutex_unlock(&m_mutex);
}
Expand Down

0 comments on commit 85a3c9d

Please sign in to comment.