Exemplo n.º 1
0
/**
 * Set the clock selection attribute of a condition variable attributes object.
 *
 * This service set the @a clock attribute of the condition variable attributes
 * object @a attr.
 *
 * See pthread_cond_timedwait() documentation for a description of the effect
 * of this attribute on a condition variable.
 *
 * @param attr an initialized condition variable attributes object,
 *
 * @param clk_id value of the @a clock attribute, may be @a CLOCK_REALTIME or @a
 * CLOCK_MONOTONIC.
 *
 * @return 0 on success,
 * @return an error number if:
 * - EINVAL, the condition variable attributes object @a attr is invalid;
 * - EINVAL, the value of @a clk_id is invalid for the @a clock attribute.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_condattr_setclock.html">
 * Specification.</a>
 *
 */
int pthread_condattr_setclock(pthread_condattr_t * attr, clockid_t clk_id)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_COND_ATTR_MAGIC, pthread_condattr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	switch (clk_id) {
	default:

		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;

	case CLOCK_REALTIME:
	case CLOCK_MONOTONIC:
		break;
	}

	attr->clock = clk_id;
	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 2
0
/**
 * Set schedpolicy attribute.
 *
 * This service set to @a policy the value of the @a policy attribute in the
 * attribute object @a attr.
 *
 * Threads created with the attribute object @a attr use the value of this
 * attribute as scheduling policy if the @a inheritsched attribute is set to
 * PTHREAD_EXPLICIT_SCHED. The value of this attribute is one of SCHED_FIFO,
 * SCHED_RR or SCHED_OTHER.
 *
 * @param attr attribute object;
 *
 * @param policy value of the @a policy attribute.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr or @a policy is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_setschedpolicy.html">
 * Specification.</a>
 * 
 */
int pthread_attr_setschedpolicy(pthread_attr_t * attr, int policy)
{
	spl_t s;

	switch (policy) {
	default:

		return EINVAL;

	case SCHED_OTHER:
	case SCHED_FIFO:
	case SCHED_RR:

		break;
	}

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	attr->policy = policy;
	if (policy == SCHED_OTHER) {
		if (attr->schedparam.sched_priority != 0)
			attr->schedparam.sched_priority = 0;
	} else if (attr->schedparam.sched_priority == 0)
		attr->schedparam.sched_priority = PSE51_MIN_PRIORITY;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 3
0
/**
 * Set the process-shared attribute of a mutex attributes object.
 *
 * This service set the @a pshared attribute of the mutex attributes object @a
 * attr.
 *
 * @param attr an initialized mutex attributes object.
 *
 * @param pshared value of the @a pshared attribute, may be one of:
 * - PTHREAD_PROCESS_PRIVATE, meaning that a mutex created with the attributes
 *   object @a attr will only be accessible by threads within the same process
 *   as the thread that initialized the mutex;
 * - PTHREAD_PROCESS_SHARED, meaning that a mutex created with the attributes
 *   object @a attr will be accessible by any thread that has access to the
 *   memory where the mutex is allocated.
 *
 * @return 0 on success,
 * @return an error status if:
 * - EINVAL, the mutex attributes object @a attr is invalid;
 * - EINVAL, the value of @a pshared is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_mutexattr_setpshared.html">
 * Specification.</a>
 *
 */
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
{
	spl_t s;

	if (!attr)
		return EINVAL;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr,PSE51_MUTEX_ATTR_MAGIC,pthread_mutexattr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	switch (pshared) {
	default:
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;

	case PTHREAD_PROCESS_PRIVATE:
	case PTHREAD_PROCESS_SHARED:
		break;
	}

	attr->pshared = pshared;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 4
0
/**
 * Set schedparam attribute.
 *
 * This service set to @a par, the value of the @a schedparam attribute in the
 * attribute object @a attr.
 *
 * The only member of the @b sched_param structure used by this implementation
 * is @a sched_priority. Threads created with @a attr will use the value of this
 * attribute as a scheduling priority if the attribute @a inheritsched is set to
 * PTHREAD_EXPLICIT_SCHED. Valid priorities range from 1 to 99.
 *
 *
 * @param attr attribute object;
 *
 * @param par value of the @a schedparam attribute.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr or @a par is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_setschedparam.html">
 * Specification.</a>
 * 
 */
int pthread_attr_setschedparam(pthread_attr_t * attr,
			       const struct sched_param *par)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	if ((attr->policy != SCHED_OTHER &&
	     (par->sched_priority < PSE51_MIN_PRIORITY
	      || par->sched_priority > PSE51_MAX_PRIORITY))
	    || (attr->policy == SCHED_OTHER && par->sched_priority != 0)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	attr->schedparam = *par;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 5
0
/**
 * Set the mutex type attribute of a mutex attributes object.
 *
 * This service set the @a type attribute of the mutex attributes object
 * @a attr.
 *
 * See pthread_mutex_lock() and pthread_mutex_unlock() documentations for a
 * description of the values of the @a type attribute and their effect on a
 * mutex.
 *
 * The @a PTHREAD_MUTEX_DEFAULT default @a type is the same as @a
 * PTHREAD_MUTEX_NORMAL. Note that using a Xenomai POSIX skin recursive mutex
 * with a Xenomai POSIX skin condition variable is safe (see pthread_cond_wait()
 * documentation).
 *
 * @param attr an initialized mutex attributes object,
 *
 * @param type value of the @a type attribute.
 *
 * @return 0 on success,
 * @return an error number if:
 * - EINVAL, the mutex attributes object @a attr is invalid;
 * - EINVAL, the value of @a type is invalid for the @a type attribute.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_mutexattr_settype.html">
 * Specification.</a>
 *
 */
int pthread_mutexattr_settype(pthread_mutexattr_t * attr, int type)
{
	spl_t s;

	if (!attr)
		return EINVAL;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr,PSE51_MUTEX_ATTR_MAGIC,pthread_mutexattr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	switch (type) {
	default:

		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;

	case PTHREAD_MUTEX_NORMAL:
	case PTHREAD_MUTEX_RECURSIVE:
	case PTHREAD_MUTEX_ERRORCHECK:
		break;
	}

	attr->type = type;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 6
0
/**
 * Set name attribute.
 *
 * This service set to @a name, the value of the @a name attribute in the
 * attribute object @a attr.
 *
 * The @a name attribute is the name under which a thread created with the
 * attribute object @a attr will appear under /proc/xenomai/sched.
 *
 * If @a name is @a NULL, a unique default name will be used.
 *
 * This service is a non-portable extension of the POSIX interface.
 *
 * @param attr attribute object;
 *
 * @param name value of the @a name attribute.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr is invalid;
 * - ENOMEM, insufficient memory exists in the system heap to duplicate the name
 *   string, increase CONFIG_XENO_OPT_SYS_HEAPSZ.
 *
 * @par Valid contexts:
 * - kernel module initialization or cleanup routine;
 * - Xenomai kernel-space thread.
 */
int pthread_attr_setname_np(pthread_attr_t * attr, const char *name)
{
	char *old_name, *new_name;
	spl_t s;

	if (name) {
		new_name = xnmalloc(strlen(name) + 1);
		if (!new_name)
			return ENOMEM;

		strcpy(new_name, name);
	} else
		new_name = NULL;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		if (name)
			xnfree(new_name);
		return EINVAL;
	}

	old_name = attr->name;
	attr->name = new_name;
	xnlock_put_irqrestore(&nklock, s);

	if (old_name)
		xnfree(old_name);

	return 0;
}
Exemplo n.º 7
0
/**
 * Set inheritsched attribute.
 *
 * This service set to @a inheritsched the value of the @a inheritsched
 * attribute in the attribute object @a attr.
 *
 * Threads created with this attribute set to PTHREAD_INHERIT_SCHED will use the
 * same scheduling policy and priority as the thread calling
 * pthread_create(). Threads created with this attribute set to
 * PTHREAD_EXPLICIT_SCHED will use the value of the @a schedpolicy attribute as
 * scheduling policy, and the value of the @a schedparam attribute as scheduling
 * priority.
 *
 * @param attr attribute object;
 *
 * @param inheritsched value of the @a inheritsched attribute,
 * PTHREAD_INHERIT_SCHED or PTHREAD_EXPLICIT_SCHED.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr or @a inheritsched is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_setinheritsched.html">
 * Specification.</a>
 * 
 */
int pthread_attr_setinheritsched(pthread_attr_t * attr, int inheritsched)
{
	spl_t s;

	switch (inheritsched) {
	default:
		return EINVAL;

	case PTHREAD_INHERIT_SCHED:
	case PTHREAD_EXPLICIT_SCHED:
		break;
	}

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	attr->inheritsched = inheritsched;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 8
0
/**
 * Get inheritsched attribute.
 *
 * This service returns at the address @a inheritsched the value of the @a
 * inheritsched attribute in the attribute object @a attr.
 *
 * Threads created with this attribute set to PTHREAD_INHERIT_SCHED will use
 * the same scheduling policy and priority as the thread calling
 * pthread_create(). Threads created with this attribute set to
 * PTHREAD_EXPLICIT_SCHED will use the value of the @a schedpolicy attribute as
 * scheduling policy, and the value of the @a schedparam  attribute as scheduling
 * priority.
 *
 * @param attr attribute object;
 *
 * @param inheritsched address where the value of the @a inheritsched attribute
 * will be stored on success.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_getinheritsched.html">
 * Specification.</a>
 * 
 */
int pthread_attr_getinheritsched(const pthread_attr_t * attr, int *inheritsched)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	*inheritsched = attr->inheritsched;

	return 0;
}
Exemplo n.º 9
0
/**
 * Destroy a mutex attributes object.
 *
 * This service destroys the mutex attributes object @a attr. The object becomes
 * invalid for all mutex services (they all return EINVAL) except
 * pthread_mutexattr_init().
 *
 * @param attr the initialized mutex attributes object to be destroyed.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, the mutex attributes object @a attr is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_mutexattr_destroy.html">
 * Specification.</a>
 *
 */
int pthread_mutexattr_destroy(pthread_mutexattr_t * attr)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr,PSE51_MUTEX_ATTR_MAGIC,pthread_mutexattr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	pse51_mark_deleted(attr);
	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 10
0
/**
 * Get stacksize attribute.
 *
 * This service stores, at the address @a stacksize, the value of the @a
 * stacksize attribute in the attribute object @a attr.
 *
 * The @a stacksize attribute is used as the stack size of the threads created
 * using the attribute object @a attr.
 *
 * @param attr attribute object;
 *
 * @param stacksize address where the value of the @a stacksize attribute will
 * be stored on success.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_getstacksize.html">
 * Specification.</a>
 *
 */
int pthread_attr_getstacksize(const pthread_attr_t * attr, size_t * stacksize)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	*stacksize = attr->stacksize;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 11
0
/**
 * Get detachstate attribute.
 *
 * This service returns, at the address @a detachstate, the value of the
 * @a detachstate attribute in the thread attribute object @a attr.
 *
 * Valid values of this attribute are PTHREAD_CREATE_JOINABLE and
 * PTHREAD_CREATE_DETACHED. A detached thread is a thread which control block is
 * automatically reclaimed when it terminates. The control block of a joinable
 * thread, on the other hand, is only reclaimed when joined with the service
 * pthread_join().
 *
 * A thread that was created joinable may be detached after creation by using
 * the pthread_detach() service.
 *
 * @param attr attribute object
 *
 * @param detachstate address where the value of the detachstate attribute will
 * be stored on success.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr is invalid;
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_getdetachstate.html">
 * Specification.</a>
 * 
 */
int pthread_attr_getdetachstate(const pthread_attr_t * attr, int *detachstate)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	*detachstate = attr->detachstate;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 12
0
/**
 * Get the clock selection attribute from a condition variable attributes
 * object.
 *
 * This service stores, at the address @a clk_id, the value of the @a clock
 * attribute in the condition variable attributes object @a attr.
 *
 * See pthread_cond_timedwait() documentation for a description of the effect of
 * this attribute on a condition variable. The clock ID returned is @a
 * CLOCK_REALTIME or @a CLOCK_MONOTONIC.
 *
 * @param attr an initialized condition variable attributes object,
 *
 * @param clk_id address where the @a clock attribute value will be stored on
 * success.
 *
 * @return 0 on success,
 * @return an error number if:
 * - EINVAL, the attribute object @a attr is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_condattr_getclock.html">
 * Specification.</a>
 *
 */
int pthread_condattr_getclock(const pthread_condattr_t * attr,
			      clockid_t * clk_id)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_COND_ATTR_MAGIC, pthread_condattr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	*clk_id = attr->clock;
	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 13
0
/**
 * Set the processor affinity attribute.
 *
 * This service sets to @a mask, the value of the @a affinity attribute in the
 * attribute object @a attr.
 *
 * The @a affinity attributes is a bitmask where bits set indicate processor
 * where a thread created with the attribute @a attr may run. The least
 * significant bit corresponds to the first logical processor.
 *
 * This service is a non-portable extension of the POSIX interface.
 *
 * @param attr attribute object;
 *
 * @param mask address where the value of the @a affinity attribute will be
 * stored on success.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr is invalid.
 *
 * @par Valid contexts:
 * - kernel module initialization or cleanup routine;
 * - Xenomai kernel-space thread.
 */
int pthread_attr_setaffinity_np(pthread_attr_t * attr, xnarch_cpumask_t mask)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	attr->affinity = mask;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 14
0
/**
 * Get schedpolicy attribute.
 *
 * This service stores, at the address @a policy, the value of the @a policy
 * attribute in the attribute object @a attr.
 *
 * Threads created with the attribute object @a attr use the value of this
 * attribute as scheduling policy if the @a inheritsched attribute is set to
 * PTHREAD_EXPLICIT_SCHED. The value of this attribute is one of SCHED_FIFO,
 * SCHED_RR or SCHED_OTHER.
 *
 * @param attr attribute object;
 *
 * @param policy address where the value of the @a policy attribute in the
 * attribute object @a attr will be stored on success.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_getschedpolicy.html">
 * Specification.</a>
 * 
 */
int pthread_attr_getschedpolicy(const pthread_attr_t * attr, int *policy)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	*policy = attr->policy;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 15
0
/**
 * Set the floating point attribute.
 *
 * This service set to @a fp, the value of the @a fp attribute in the attribute
 * object @a attr.
 *
 * The @a fp attribute is a boolean attribute indicating whether a thread
 * created with the attribute @a attr may use floating-point hardware.
 *
 * This service is a non-portable extension of the POSIX interface.
 *
 * @param attr attribute object;
 *
 * @param fp value of the @a fp attribute.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr is invalid.
 *
 * @par Valid contexts:
 * - kernel module initialization or cleanup routine;
 * - Xenomai kernel-space thread.
 */
int pthread_attr_setfp_np(pthread_attr_t * attr, int fp)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	attr->fp = fp;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 16
0
/**
 * Get name attribute.
 *
 * This service stores, at the address @a name, the value of the @a name
 * attribute in the attribute object @a attr.
 *
 * The @a name attribute is the name under which a thread created with the
 * attribute object @a attr will appear under /proc/xenomai/sched. 
 *
 * The name returned by this function is only valid until the name is changed
 * with pthread_attr_setname_np() or the @a attr object is destroyed with
 * pthread_attr_destroy().
 *
 * If @a name is @a NULL, a unique default name will be used.
 *
 * This service is a non-portable extension of the POSIX interface.
 *
 * @param attr attribute object;
 *
 * @param name address where the value of the @a name attribute will be stored
 * on success.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr is invalid.
 *
 * @par Valid contexts:
 * - kernel module initialization or cleanup routine;
 * - Xenomai kernel-space thread.
 */
int pthread_attr_getname_np(const pthread_attr_t * attr, const char **name)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	*name = attr->name;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 17
0
/**
 * Get contention scope attribute.
 *
 * This service stores, at the address @a scope, the value of the @a scope
 * attribute in the attribute object @a attr.
 *
 * The @a scope attribute represents the scheduling contention scope of threads
 * created with the attribute object @a attr. This implementation only supports
 * the value PTHREAD_SCOPE_SYSTEM.
 *
 * @param attr attribute object;
 *
 * @param scope address where the value of the @a scope attribute will be stored
 * on sucess.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_getscope.html">
 * Specification.</a>
 * 
 */
int pthread_attr_getscope(const pthread_attr_t * attr, int *scope)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	*scope = PTHREAD_SCOPE_SYSTEM;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 18
0
/**
 * Set contention scope attribute.
 *
 * This service set to @a scope the value of the @a scope attribute in the
 * attribute object @a attr.
 *
 * The @a scope attribute represents the scheduling contention scope of threads
 * created with the attribute object @a attr. This implementation only supports
 * the value PTHREAD_SCOPE_SYSTEM.
 *
 * @param attr attribute object;
 *
 * @param scope value of the @a scope attribute.
 *
 * @return 0 on success;
 * @return an error number if:
 * - ENOTSUP, @a scope is an unsupported value of the scope attribute.
 * - EINVAL, @a attr is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_setscope.html">
 * Specification.</a>
 * 
 */
int pthread_attr_setscope(pthread_attr_t * attr, int scope)
{
	spl_t s;

	if (scope != PTHREAD_SCOPE_SYSTEM)
		return ENOTSUP;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 19
0
/**
 * Get schedparam attribute.
 *
 * This service stores, at the address @a par, the value of the @a schedparam
 * attribute in the attribute object @a attr.
 *
 * The only member of the @b sched_param structure used by this implementation
 * is @a sched_priority. Threads created with @a attr will use the value of this
 * attribute as a scheduling priority if the attribute @a inheritsched is set to
 * PTHREAD_EXPLICIT_SCHED. Valid priorities range from 1 to 99.
 *
 * @param attr attribute object;
 *
 * @param par address where the value of the @a schedparam attribute will be
 * stored on success.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_getschedparam.html">
 * Specification.</a>
 * 
 */
int pthread_attr_getschedparam(const pthread_attr_t * attr,
			       struct sched_param *par)
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	*par = attr->schedparam;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 20
0
/**
 * Set stacksize attribute.
 *
 * This service set to @a stacksize, the value of the @a stacksize attribute in
 * the attribute object @a attr.
 *
 * The @a stacksize attribute is used as the stack size of the threads created
 * using the attribute object @a attr.
 *
 * The minimum value for this attribute is PTHREAD_STACK_MIN.
 *
 * @param attr attribute object;
 *
 * @param stacksize value of the @a stacksize attribute.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, @a attr or @a stacksize is invalid.
 * 
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_setstacksize.html">
 * Specification.</a>
 * 
 */
int pthread_attr_setstacksize(pthread_attr_t * attr, size_t stacksize)
{
	spl_t s;

	if (stacksize < PTHREAD_STACK_MIN)
		return EINVAL;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	attr->stacksize = stacksize;
	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 21
0
/**
 * Get the mutex type attribute from a mutex attributes object.
 *
 * This service stores, at the address @a type, the value of the @a type
 * attribute in the mutex attributes object @a attr.
 *
 * See pthread_mutex_lock() and pthread_mutex_unlock() documentations for a
 * description of the values of the @a type attribute and their effect on a
 * mutex.
 *
 * @param attr an initialized mutex attributes object,
 *
 * @param type address where the @a type attribute value will be stored on
 * success.
 *
 * @return 0 on sucess,
 * @return an error number if:
 * - EINVAL, the @a type address is invalid;
 * - EINVAL, the mutex attributes object @a attr is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_mutexattr_gettype.html">
 * Specification.</a>
 *
 */
int pthread_mutexattr_gettype(const pthread_mutexattr_t * attr, int *type)
{
	spl_t s;

	if (!type || !attr)
		return EINVAL;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr,PSE51_MUTEX_ATTR_MAGIC,pthread_mutexattr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	*type = attr->type;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 22
0
/**
 * Get the process-shared attribute of a mutex attributes object.
 *
 * This service stores, at the address @a pshared, the value of the @a pshared
 * attribute in the mutex attributes object @a attr.
 *
 * The @a pashared attribute may only be one of @a PTHREAD_PROCESS_PRIVATE or
 * @a PTHREAD_PROCESS_SHARED. See pthread_mutexattr_setpshared() for the meaning
 * of these two constants.
 *
 * @param attr an initialized mutex attributes object;
 *
 * @param pshared address where the value of the @a pshared attribute will be
 * stored on success.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, the @a pshared address is invalid;
 * - EINVAL, the mutex attributes object @a attr is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_mutexattr_getpshared.html">
 * Specification.</a>
 *
 */
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared)
{
	spl_t s;

	if (!pshared || !attr)
		return EINVAL;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr,PSE51_MUTEX_ATTR_MAGIC,pthread_mutexattr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	*pshared = attr->pshared;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 23
0
/**
 * Set detachstate attribute.
 *
 * This service sets to @a detachstate the value of the @a detachstate attribute
 * in the attribute object @a attr. 
 *
 * Valid values of this attribute are PTHREAD_CREATE_JOINABLE and
 * PTHREAD_CREATE_DETACHED. A detached thread is a thread which control block is
 * automatically reclaimed when it terminates. The control block of a joinable
 * thread, on the other hand, is only reclaimed when joined with the service
 * pthread_join().
 *
 * A thread that was created joinable may be detached after creation by using
 * the pthread_detach() service.
 *
 * @param attr attribute object;
 *
 * @param detachstate value of the detachstate attribute.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, the attribute object @a attr is invalid
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_setdetachstate.html">
 * Specification.</a>
 * 
 */
int pthread_attr_setdetachstate(pthread_attr_t * attr, int detachstate)
{
	spl_t s;

	if (detachstate != PTHREAD_CREATE_JOINABLE
	    && detachstate != PTHREAD_CREATE_DETACHED)
		return EINVAL;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	attr->detachstate = detachstate;
	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 24
0
/**
 * Destroy a thread attributes object.
 *
 * This service invalidates the attribute object pointed to by @a attr. The
 * object becomes invalid for all services (they all return EINVAL) except
 * pthread_attr_init().
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_attr_destroy.html">
 * Specification.</a>
 * 
 */
int pthread_attr_destroy(pthread_attr_t * attr)
{
	char *name;
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr, PSE51_THREAD_ATTR_MAGIC, pthread_attr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	name = attr->name;
	pse51_mark_deleted(attr);
	xnlock_put_irqrestore(&nklock, s);

	if (name)
		xnfree(name);

	return 0;
}
Exemplo n.º 25
0
/**
 * Execute an initialization routine.
 *
 * This service may be used by libraries which need an initialization function
 * to be called only once.
 *
 * The function @a init_routine will only be called, with no argument, the first
 * time this service is called specifying the address @a once.
 *
 * @return 0 on success;
 * @return an error number if:
 * - EINVAL, the object pointed to by @a once is invalid (it must have been
 *   initialized with PTHREAD_ONCE_INIT).
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_once.html">
 * Specification.</a>
 *
 */
int pthread_once(pthread_once_t * once, void (*init_routine) (void))
{
	spl_t s;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(once, PSE51_ONCE_MAGIC, pthread_once_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	if (!once->routine_called) {
		init_routine();
		/* If the calling thread is canceled while executing init_routine,
		   routine_called will not be set to 1. */
		once->routine_called = 1;
	}

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}
Exemplo n.º 26
0
/**
 * Set the protocol attribute of a mutex attributes object.
 *
 * This service set the @a type attribute of the mutex attributes object
 * @a attr.
 *
 * @param attr an initialized mutex attributes object,
 *
 * @param proto value of the @a protocol attribute, may be one of:
 * - PTHREAD_PRIO_NONE, meaning that a mutex created with the attributes object
 *   @a attr will not follow any priority protocol;
 * - PTHREAD_PRIO_INHERIT, meaning that a mutex created with the attributes
 *   object @a attr, will follow the priority inheritance protocol.
 *
 * The value PTHREAD_PRIO_PROTECT (priority ceiling protocol) is unsupported.
 *
 * @return 0 on success,
 * @return an error number if:
 * - EINVAL, the mutex attributes object @a attr is invalid;
 * - ENOTSUP, the value of @a proto is unsupported;
 * - EINVAL, the value of @a proto is invalid.
 *
 * @see
 * <a href="http://www.opengroup.org/onlinepubs/000095399/functions/pthread_mutexattr_setprotocol.html">
 * Specification.</a>
 *
 */
int pthread_mutexattr_setprotocol(pthread_mutexattr_t * attr, int proto)
{
	spl_t s;

	if (!attr)
		return EINVAL;

	xnlock_get_irqsave(&nklock, s);

	if (!pse51_obj_active(attr,PSE51_MUTEX_ATTR_MAGIC,pthread_mutexattr_t)) {
		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;
	}

	switch (proto) {
	default:

		xnlock_put_irqrestore(&nklock, s);
		return EINVAL;

	case PTHREAD_PRIO_PROTECT:

		xnlock_put_irqrestore(&nklock, s);
		return ENOTSUP;

	case PTHREAD_PRIO_NONE:
	case PTHREAD_PRIO_INHERIT:
		break;
	}

	attr->protocol = proto;

	xnlock_put_irqrestore(&nklock, s);

	return 0;
}