Beispiel #1
0
static void
sem_module_init(void)
{

	_pthread_mutex_init(&sem_llock, NULL);
	_pthread_atfork(sem_prefork, sem_postfork, sem_child_postfork);
}
Beispiel #2
0
static void
sem_module_init(void)
{
	pthread_mutexattr_t ma;

	_pthread_mutexattr_init(&ma);
	_pthread_mutexattr_settype(&ma,  PTHREAD_MUTEX_RECURSIVE);
	_pthread_mutex_init(&sem_llock, &ma);
	_pthread_mutexattr_destroy(&ma);
	_pthread_atfork(sem_prefork, sem_postfork, sem_child_postfork);
}
Beispiel #3
0
static int
init_static_private(struct pthread *thread, pthread_mutex_t *mutex)
{
	int ret;

	THR_LOCK_ACQUIRE(thread, &_mutex_static_lock);

	if (*mutex == NULL)
		ret = _pthread_mutex_init(mutex, &static_mattr);
	else
		ret = 0;

	THR_LOCK_RELEASE(thread, &_mutex_static_lock);

	return (ret);
}
Beispiel #4
0
void init_sync(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) {
	// init synchronization info
	_pthread_mutex_init(mutex, NULL);
	_pthread_cond_init(cond, NULL);

	// service info
	_pthread_mutex_init(mfinished, NULL);
	_pthread_mutex_init(mbank, NULL);
	_pthread_mutex_init(mcur_run, NULL);
	_pthread_mutex_init(mhb, NULL);
	_pthread_mutex_init(mnr, NULL);
}
Beispiel #5
0
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);
}
Beispiel #6
0
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);
}
Beispiel #7
0
static void
init_private(void)
{
	struct clockinfo clockinfo;
	size_t len;
	int mib[2];

	/*
	 * Avoid reinitializing some things if they don't need to be,
	 * e.g. after a fork().
	 */
	if (init_once == 0) {
		/* Find the stack top */
		mib[0] = CTL_KERN;
		mib[1] = KERN_USRSTACK;
		len = sizeof (_usrstack);
		if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1)
			PANIC("Cannot get kern.usrstack from sysctl");
		/* Get the kernel clockrate: */
		mib[0] = CTL_KERN;
		mib[1] = KERN_CLOCKRATE;
		len = sizeof (struct clockinfo);
		if (sysctl(mib, 2, &clockinfo, &len, NULL, 0) == 0)
			_clock_res_usec = 1000000 / clockinfo.stathz;
		else
			_clock_res_usec = CLOCK_RES_USEC;

		_thr_page_size = getpagesize();
		_thr_guard_default = _thr_page_size;
		if (sizeof(void *) == 8) {
			_thr_stack_default = THR_STACK64_DEFAULT;
			_thr_stack_initial = THR_STACK64_INITIAL;
		}
		else {
			_thr_stack_default = THR_STACK32_DEFAULT;
			_thr_stack_initial = THR_STACK32_INITIAL;
		}
		_pthread_attr_default.guardsize_attr = _thr_guard_default;
		_pthread_attr_default.stacksize_attr = _thr_stack_default;
		TAILQ_INIT(&_thr_atfork_list);
		init_once = 1;	/* Don't do this again. */
	} else {
		/*
		 * Destroy the locks before creating them.  We don't
		 * know what state they are in so it is better to just
		 * recreate them.
		 */
		_lock_destroy(&_thread_signal_lock);
		_lock_destroy(&_mutex_static_lock);
		_lock_destroy(&_rwlock_static_lock);
		_lock_destroy(&_keytable_lock);
	}

	/* Initialize everything else. */
	TAILQ_INIT(&_thread_list);
	TAILQ_INIT(&_thread_gc_list);
	_pthread_mutex_init(&_thr_atfork_mutex, NULL);

	/*
	 * Initialize the lock for temporary installation of signal
	 * handlers (to support sigwait() semantics) and for the
	 * process signal mask and pending signal sets.
	 */
	if (_lock_init(&_thread_signal_lock, LCK_ADAPTIVE,
	    _kse_lock_wait, _kse_lock_wakeup, calloc) != 0)
		PANIC("Cannot initialize _thread_signal_lock");
	if (_lock_init(&_mutex_static_lock, LCK_ADAPTIVE,
	    _thr_lock_wait, _thr_lock_wakeup, calloc) != 0)
		PANIC("Cannot initialize mutex static init lock");
	if (_lock_init(&_rwlock_static_lock, LCK_ADAPTIVE,
	    _thr_lock_wait, _thr_lock_wakeup, calloc) != 0)
		PANIC("Cannot initialize rwlock static init lock");
	if (_lock_init(&_keytable_lock, LCK_ADAPTIVE,
	    _thr_lock_wait, _thr_lock_wakeup, calloc) != 0)
		PANIC("Cannot initialize thread specific keytable lock");
	_thr_spinlock_init();

	/* Clear pending signals and get the process signal mask. */
	SIGEMPTYSET(_thr_proc_sigpending);

	/* Are we in M:N mode (default) or 1:1 mode? */
#ifdef SYSTEM_SCOPE_ONLY
	_thread_scope_system = 1;
#else
	if (getenv("LIBPTHREAD_SYSTEM_SCOPE") != NULL)
		_thread_scope_system = 1;
	else if (getenv("LIBPTHREAD_PROCESS_SCOPE") != NULL)
		_thread_scope_system = -1;
#endif
	if (getenv("LIBPTHREAD_DEBUG") != NULL)
		_thr_debug_flags |= DBG_INFO_DUMP;

	/*
	 * _thread_list_lock and _kse_count are initialized
	 * by _kse_init()
	 */
}