} sem_t;
GC_INLINE int sem_init(sem_t *sem, int pshared, int value) {
- int ret;
- if(pshared)
- ABORT("sem_init with pshared set");
+ if (pshared != 0) {
+ errno = EPERM; /* unsupported */
+ return -1;
+ }
sem->value = value;
-
- ret = pthread_mutex_init(&sem->mutex,NULL);
- if(ret < 0) return -1;
- ret = pthread_cond_init(&sem->cond,NULL);
- if(ret < 0) return -1;
+ if (pthread_mutex_init(&sem->mutex, NULL) != 0)
+ return -1;
+ if (pthread_cond_init(&sem->cond, NULL) != 0) {
+ (void)pthread_mutex_destroy(&sem->mutex);
+ return -1;
+ }
return 0;
}
GC_INLINE int sem_post(sem_t *sem) {
- if(pthread_mutex_lock(&sem->mutex) < 0)
- return -1;
+ if (pthread_mutex_lock(&sem->mutex) != 0)
+ return -1;
sem->value++;
- if(pthread_cond_signal(&sem->cond) < 0) {
- pthread_mutex_unlock(&sem->mutex);
- return -1;
+ if (pthread_cond_signal(&sem->cond) != 0) {
+ (void)pthread_mutex_unlock(&sem->mutex);
+ return -1;
}
- if(pthread_mutex_unlock(&sem->mutex) < 0)
- return -1;
- return 0;
+ return pthread_mutex_unlock(&sem->mutex) != 0 ? -1 : 0;
}
GC_INLINE int sem_wait(sem_t *sem) {
- if(pthread_mutex_lock(&sem->mutex) < 0)
- return -1;
- while(sem->value == 0) {
- pthread_cond_wait(&sem->cond,&sem->mutex);
+ if (pthread_mutex_lock(&sem->mutex) != 0)
+ return -1;
+ while (sem->value == 0) {
+ if (pthread_cond_wait(&sem->cond, &sem->mutex) != 0) {
+ (void)pthread_mutex_unlock(&sem->mutex);
+ return -1;
+ }
}
sem->value--;
- if(pthread_mutex_unlock(&sem->mutex) < 0)
- return -1;
- return 0;
+ return pthread_mutex_unlock(&sem->mutex) != 0 ? -1 : 0;
}
GC_INLINE int sem_destroy(sem_t *sem) {
- int ret;
- ret = pthread_cond_destroy(&sem->cond);
- if(ret < 0) return -1;
- ret = pthread_mutex_destroy(&sem->mutex);
- if(ret < 0) return -1;
- return 0;
+ return pthread_cond_destroy(&sem->cond) != 0
+ || pthread_mutex_destroy(&sem->mutex) != 0 ? -1 : 0;
}
#endif
# ifdef SN_TARGET_PS3
{
pthread_mutexattr_t mattr;
- pthread_mutexattr_init(&mattr);
- pthread_mutex_init(&GC_allocate_ml, &mattr);
+
+ if (0 != pthread_mutexattr_init(&mattr)) {
+ ABORT("pthread_mutexattr_init failed");
+ }
+ if (0 != pthread_mutex_init(&GC_allocate_ml, &mattr)) {
+ ABORT("pthread_mutex_init failed");
+ }
pthread_mutexattr_destroy(&mattr);
}
# endif
GC_INNER int GC_key_create_inner(tsd ** key_ptr)
{
int i;
+ int ret;
tsd * result = (tsd *)MALLOC_CLEAR(sizeof(tsd));
/* A quick alignment check, since we need atomic stores */
GC_ASSERT((word)(&invalid_tse.next) % sizeof(tse *) == 0);
if (0 == result) return ENOMEM;
- pthread_mutex_init(&(result -> lock), NULL);
+ ret = pthread_mutex_init(&result->lock, NULL);
+ if (ret != 0) return ret;
for (i = 0; i < TS_CACHE_SIZE; ++i) {
result -> cache[i] = (/* no const */ tse *)&invalid_tse;
}