Simplify some error checking
This commit is contained in:
+1
-7
@@ -447,17 +447,11 @@ void almtx_destroy(almtx_t *mtx)
|
||||
|
||||
int almtx_timedlock(almtx_t *mtx, const struct timespec *ts)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if(!mtx || !ts)
|
||||
return althrd_error;
|
||||
|
||||
ret = pthread_mutex_timedlock(mtx, ts);
|
||||
int ret = pthread_mutex_timedlock(mtx, ts);
|
||||
switch(ret)
|
||||
{
|
||||
case 0: return althrd_success;
|
||||
case ETIMEDOUT: return althrd_timedout;
|
||||
case EAGAIN:
|
||||
case EBUSY: return althrd_busy;
|
||||
}
|
||||
return althrd_error;
|
||||
|
||||
@@ -153,20 +153,13 @@ inline int althrd_sleep(const struct timespec *ts, struct timespec *rem)
|
||||
|
||||
inline int almtx_lock(almtx_t *mtx)
|
||||
{
|
||||
int ret = EINVAL;
|
||||
if(mtx != NULL)
|
||||
ret = pthread_mutex_lock(mtx);
|
||||
switch(ret)
|
||||
{
|
||||
case 0: return althrd_success;
|
||||
case EAGAIN: return althrd_busy;
|
||||
}
|
||||
return althrd_error;
|
||||
if(pthread_mutex_lock(mtx) != 0)
|
||||
return althrd_error;
|
||||
return althrd_success;
|
||||
}
|
||||
|
||||
inline int almtx_unlock(almtx_t *mtx)
|
||||
{
|
||||
if(!mtx) return althrd_error;
|
||||
if(pthread_mutex_unlock(mtx) != 0)
|
||||
return althrd_error;
|
||||
return althrd_success;
|
||||
@@ -174,13 +167,10 @@ inline int almtx_unlock(almtx_t *mtx)
|
||||
|
||||
inline int almtx_trylock(almtx_t *mtx)
|
||||
{
|
||||
int ret = EINVAL;
|
||||
if(mtx != NULL)
|
||||
ret = pthread_mutex_trylock(mtx);
|
||||
int ret = pthread_mutex_trylock(mtx);
|
||||
switch(ret)
|
||||
{
|
||||
case 0: return althrd_success;
|
||||
case EAGAIN:
|
||||
case EBUSY: return althrd_busy;
|
||||
}
|
||||
return althrd_error;
|
||||
|
||||
Reference in New Issue
Block a user