void clean(pthread_mutex_t *mutex, pthread_cond_t *cond, pthread_mutex_t *mfinished, pthread_mutex_t *mbank, pthread_mutex_t *mcur_run, pthread_mutex_t *mhb, pthread_mutex_t *mnr, struct horse *horses, int listenfd) { _pthread_mutex_destroy(mcur_run); _pthread_mutex_destroy(mhb); _pthread_mutex_destroy(mnr); free(horses); }
int _pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) { pthread_rwlock_t prwlock; int ret; /* allocate rwlock object */ prwlock = (pthread_rwlock_t)malloc(sizeof(struct pthread_rwlock)); if (prwlock == NULL) return(ENOMEM); /* initialize the lock */ if ((ret = _pthread_mutex_init(&prwlock->lock, NULL)) != 0) free(prwlock); else { /* initialize the read condition signal */ ret = _pthread_cond_init(&prwlock->read_signal, NULL); if (ret != 0) { _pthread_mutex_destroy(&prwlock->lock); free(prwlock); } else { /* initialize the write condition signal */ ret = _pthread_cond_init(&prwlock->write_signal, NULL); if (ret != 0) { _pthread_cond_destroy(&prwlock->read_signal); _pthread_mutex_destroy(&prwlock->lock); free(prwlock); } else { /* success */ prwlock->state = 0; prwlock->blocked_writers = 0; *rwlock = prwlock; } } } return (ret); }
int _pthread_barrier_destroy(pthread_barrier_t *barrier) { pthread_barrier_t bar; int ret, ret2; if (barrier == NULL || *barrier == NULL) return (EINVAL); bar = *barrier; if (bar->b_waiters > 0) return (EBUSY); *barrier = NULL; ret = _pthread_mutex_destroy(&bar->b_lock); ret2 = _pthread_cond_destroy(&bar->b_cond); free(bar); return (ret ? ret : ret2); }
/* * close a directory. */ int fdclosedir(DIR *dirp) { int fd; if (__isthreaded) _pthread_mutex_lock(&dirp->dd_lock); fd = dirp->dd_fd; dirp->dd_fd = -1; dirp->dd_loc = 0; free((void *)dirp->dd_buf); _reclaim_telldir(dirp); if (__isthreaded) { _pthread_mutex_unlock(&dirp->dd_lock); _pthread_mutex_destroy(&dirp->dd_lock); } free((void *)dirp); return (fd); }
static sem_t sem_alloc(unsigned int value, semid_t semid, int system_sem) { sem_t sem; if (value > SEM_VALUE_MAX) { errno = EINVAL; return (NULL); } sem = (sem_t)malloc(sizeof(struct sem)); if (sem == NULL) { errno = ENOSPC; return (NULL); } /* * Initialize the semaphore. */ if (_pthread_mutex_init(&sem->lock, NULL) != 0) { free(sem); errno = ENOSPC; return (NULL); } if (_pthread_cond_init(&sem->gtzero, NULL) != 0) { _pthread_mutex_destroy(&sem->lock); free(sem); errno = ENOSPC; return (NULL); } sem->count = (u_int32_t)value; sem->nwaiters = 0; sem->magic = SEM_MAGIC; sem->semid = semid; sem->syssem = system_sem; return (sem); }
int _pthread_rwlock_destroy (pthread_rwlock_t *rwlock) { int ret; if (rwlock == NULL) ret = EINVAL; else { pthread_rwlock_t prwlock; prwlock = *rwlock; _pthread_mutex_destroy(&prwlock->lock); _pthread_cond_destroy(&prwlock->read_signal); _pthread_cond_destroy(&prwlock->write_signal); free(prwlock); *rwlock = NULL; ret = 0; } return (ret); }