mirror of
https://github.com/apache/nuttx.git
synced 2026-05-21 21:34:07 +08:00
Add new pthread_* APIs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@134 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -76,6 +76,10 @@
|
||||
* Corrected memory leak in OS pthread join logic
|
||||
* Corrected memory leaks in examples/ostest due to failures
|
||||
to join or detach from pthreads.
|
||||
* added pthread_once(), pthread_kill(), pthread_sigmask()
|
||||
* added pthread_barrierattr_*() APIs
|
||||
* added pthread_barrier_init(), pthread_barrier_destroy(), and
|
||||
pthread_barrier_wait();
|
||||
* Started m68322
|
||||
|
||||
|
||||
|
||||
@@ -437,6 +437,10 @@ Other memory:
|
||||
* Corrected memory leak in OS pthread join logic
|
||||
* Corrected memory leaks in examples/ostest due to failures
|
||||
to join or detach from pthreads.
|
||||
* added pthread_once(), pthread_kill(), pthread_sigmask()
|
||||
* added pthread_barrierattr_*() APIs
|
||||
* added pthread_barrier_init(), pthread_barrier_destroy(), and
|
||||
pthread_barrier_wait();
|
||||
* Started m68322
|
||||
</pre></ul>
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,8 @@ Task/Scheduler
|
||||
_POSIX_CLOCKRES_MIN in limits.h
|
||||
CLK_TCK in time.h
|
||||
Definitions in sched/clock_internal.h
|
||||
- Consider implementing wait, waitpid, waitid. At present, a parent has
|
||||
no information about child tasks.
|
||||
|
||||
o Memory Managment
|
||||
- Add an option to free all memory allocated by a task when the task exits.
|
||||
@@ -45,6 +47,7 @@ o Build system
|
||||
- Something leaves garbage link 'include' in arch/*/include
|
||||
|
||||
o Applications & Tests
|
||||
- Need a test for the pthread_barrierattr_* and pthread_barrier_* APIs.
|
||||
|
||||
o C5471
|
||||
- At present, there is a failure in the examples/ostest POSIX timer
|
||||
|
||||
+71
-13
@@ -44,6 +44,7 @@
|
||||
#include <nuttx/compiler.h> /* Compiler settings */
|
||||
#include <sys/types.h> /* Needed for general types */
|
||||
#include <semaphore.h> /* Needed for sem_t */
|
||||
#include <signal.h> /* Needed for sigset_t */
|
||||
#include <time.h> /* Needed for struct timespec */
|
||||
#include <nuttx/compiler.h> /* For noreturn_function */
|
||||
|
||||
@@ -64,29 +65,43 @@
|
||||
* Definitions
|
||||
********************************************************************************/
|
||||
|
||||
#define PTHREAD_PROCESS_PRIVATE 0
|
||||
#define PTHREAD_PROCESS_SHARED 1
|
||||
/* Values for the process shared (pshared) attribute */
|
||||
|
||||
#define PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN
|
||||
#define PTHREAD_STACK_DEFAULT CONFIG_PTHREAD_STACK_DEFAULT
|
||||
#define PTHREAD_PROCESS_PRIVATE 0
|
||||
#define PTHREAD_PROCESS_SHARED 1
|
||||
|
||||
#define PTHREAD_INHERIT_SCHED 0
|
||||
#define PTHREAD_EXPLICIT_SCHED 1
|
||||
/* Valid ranges for the pthread stacksize attribute */
|
||||
|
||||
#define PTHREAD_PRIO_NONE 0
|
||||
#define PTHREAD_PRIO_INHERIT 1
|
||||
#define PTHREAD_PRIO_PROTECT 2
|
||||
#define PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN
|
||||
#define PTHREAD_STACK_DEFAULT CONFIG_PTHREAD_STACK_DEFAULT
|
||||
|
||||
#define PTHREAD_DEFAULT_PRIORITY 100
|
||||
/* Values for the pthread inheritsched attribute */
|
||||
|
||||
#define PTHREAD_INHERIT_SCHED 0
|
||||
#define PTHREAD_EXPLICIT_SCHED 1
|
||||
|
||||
#define PTHREAD_PRIO_NONE 0
|
||||
#define PTHREAD_PRIO_INHERIT 1
|
||||
#define PTHREAD_PRIO_PROTECT 2
|
||||
|
||||
#define PTHREAD_DEFAULT_PRIORITY 100
|
||||
|
||||
/* Cancellation states returned by pthread_cancelstate() */
|
||||
|
||||
#define PTHREAD_CANCEL_ENABLE (0)
|
||||
#define PTHREAD_CANCEL_DISABLE (1)
|
||||
#define PTHREAD_CANCEL_ENABLE (0)
|
||||
#define PTHREAD_CANCEL_DISABLE (1)
|
||||
|
||||
/* Thread return value when a pthread is canceled */
|
||||
|
||||
# define PTHREAD_CANCELED ((FAR void*)ERROR)
|
||||
#define PTHREAD_CANCELED ((FAR void*)ERROR)
|
||||
|
||||
/* Used to initialize a pthread_once_t */
|
||||
|
||||
#define PTHREAD_ONCE_INIT (FALSE)
|
||||
|
||||
/* This is returned by pthread_wait. It must not match any errno in errno.h */
|
||||
|
||||
#define PTHREAD_BARRIER_SERIAL_THREAD 0x1000
|
||||
|
||||
/********************************************************************************
|
||||
* Global Type Declarations
|
||||
@@ -144,6 +159,21 @@ struct pthread_mutex_s
|
||||
typedef struct pthread_mutex_s pthread_mutex_t;
|
||||
#define PTHREAD_MUTEX_INITIALIZER {0, {1, 0xffff}}
|
||||
|
||||
struct pthread_barrierattr_s
|
||||
{
|
||||
int pshared;
|
||||
};
|
||||
typedef struct pthread_barrierattr_s pthread_barrierattr_t;
|
||||
|
||||
struct pthread_barrier_s
|
||||
{
|
||||
sem_t sem;
|
||||
unsigned int count;
|
||||
};
|
||||
typedef struct pthread_barrier_s pthread_barrier_t;
|
||||
|
||||
typedef boolean pthread_once_t;
|
||||
|
||||
/* Forware references */
|
||||
|
||||
struct sched_param; /* Defined in sched.h */
|
||||
@@ -155,6 +185,7 @@ struct sched_param; /* Defined in sched.h */
|
||||
/********************************************************************************
|
||||
* Global Function Prototypes
|
||||
********************************************************************************/
|
||||
|
||||
/* Initializes a thread attributes object (attr) with default values for all of
|
||||
* the individual attributes used by a given implementation.
|
||||
*/
|
||||
@@ -280,6 +311,33 @@ EXTERN int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
|
||||
EXTERN int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
||||
const struct timespec *abstime);
|
||||
|
||||
/* Barrier attributes */
|
||||
|
||||
EXTERN int pthread_barrierattr_destroy(FAR pthread_barrierattr_t *attr);
|
||||
EXTERN int pthread_barrierattr_init(FAR pthread_barrierattr_t *attr);
|
||||
EXTERN int pthread_barrierattr_getpshared(FAR const pthread_barrierattr_t *attr,
|
||||
FAR int *pshared);
|
||||
EXTERN int pthread_barrierattr_setpshared(FAR pthread_barrierattr_t *attr,
|
||||
int pshared);
|
||||
|
||||
/* Barriers */
|
||||
|
||||
EXTERN int pthread_barrier_destroy(FAR pthread_barrier_t *barrier);
|
||||
EXTERN int pthread_barrier_init(FAR pthread_barrier_t *barrier,
|
||||
FAR const pthread_barrierattr_t *attr,
|
||||
unsigned int count);
|
||||
EXTERN int pthread_barrier_wait(FAR pthread_barrier_t *barrier);
|
||||
|
||||
/* Pthread initialization */
|
||||
|
||||
EXTERN int pthread_once(FAR pthread_once_t *once_control,
|
||||
CODE void (*init_routine)(void));
|
||||
|
||||
/* Pthread signal management APIs */
|
||||
|
||||
EXTERN int pthread_kill(pthread_t thread, int sig);
|
||||
EXTERN int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
#include <time.h> /* Needed for struct timespec */
|
||||
#include <sys/types.h> /* Needed for, e.g., sigset_t */
|
||||
#include <sys/types.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Compilations Switches
|
||||
|
||||
+5
-2
@@ -89,12 +89,15 @@ PTHREAD_SRCS = pthread_attrinit.c pthread_attrdestroy.c \
|
||||
pthread_condinit.c pthread_conddestroy.c \
|
||||
pthread_condattrinit.c pthread_condattrdestroy.c \
|
||||
pthread_condwait.c pthread_condsignal.c pthread_condbroadcast.c \
|
||||
pthread_barrierattrinit.c pthread_barrierattrdestroy.c \
|
||||
pthread_barrierattrgetpshared.c pthread_barrierattrsetpshared.c \
|
||||
pthread_barrierinit.c pthread_barrierdestroy.c pthread_barrierwait.c \
|
||||
pthread_cancel.c pthread_setcancelstate.c \
|
||||
pthread_keycreate.c pthread_setspecific.c pthread_getspecific.c pthread_keydelete.c \
|
||||
pthread_initialize.c pthread_completejoin.c pthread_findjoininfo.c \
|
||||
pthread_removejoininfo.c
|
||||
pthread_removejoininfo.c pthread_once.c
|
||||
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
|
||||
PTHREAD_SRCS += pthread_condtimedwait.c
|
||||
PTHREAD_SRCS += pthread_condtimedwait.c pthread_kill.c pthread_sigmask.c
|
||||
endif
|
||||
SEM_SRCS = sem_initialize.c sem_init.c sem_destroy.c\
|
||||
sem_open.c sem_close.c sem_unlink.c \
|
||||
|
||||
@@ -93,7 +93,6 @@ extern int clock_abstime2ticks(clockid_t clockid, const struct timespec *abstime
|
||||
{
|
||||
struct timespec currtime;
|
||||
struct timespec reltime;
|
||||
sint32 relusec;
|
||||
int ret;
|
||||
|
||||
/* Convert the timespec to clock ticks. NOTE: Here we use
|
||||
|
||||
+1
-1
@@ -243,7 +243,7 @@ extern void task_start(void);
|
||||
extern STATUS task_schedsetup(FAR _TCB *tcb, int priority,
|
||||
start_t start, main_t main);
|
||||
extern STATUS task_argsetup(FAR _TCB *tcb, const char *name,
|
||||
char *argv[]);
|
||||
const char *argv[]);
|
||||
|
||||
extern boolean sched_addreadytorun(FAR _TCB *rtrtcb);
|
||||
extern boolean sched_removereadytorun(FAR _TCB *rtrtcb);
|
||||
|
||||
+2
-2
@@ -418,10 +418,10 @@ void os_start(void)
|
||||
#ifndef CONFIG_CUSTOM_STACK
|
||||
init_taskid = task_create("init", SCHED_PRIORITY_DEFAULT,
|
||||
CONFIG_PROC_STACK_SIZE,
|
||||
(main_t)user_start, (char **)NULL);
|
||||
(main_t)user_start, (const char **)NULL);
|
||||
#else
|
||||
init_taskid = task_create("init", SCHED_PRIORITY_DEFAULT,
|
||||
(main_t)user_start, (char **)NULL);
|
||||
(main_t)user_start, (const char **)NULL);
|
||||
#endif
|
||||
ASSERT(init_taskid != ERROR);
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/********************************************************************************
|
||||
* pthread_barrierattrdestroy.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Type Declarations
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Global Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Function Prototypes
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Public Functions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Function: pthread_barrierattr_destroy
|
||||
*
|
||||
* Description:
|
||||
* The pthread_barrierattr_destroy() function will destroy a barrier attributes
|
||||
* object. A destroyed attr attributes object can be reinitialized using
|
||||
* pthread_barrierattr_init(); the results of otherwise referencing the object
|
||||
* after it has been destroyed are undefined.
|
||||
*
|
||||
* Parameters:
|
||||
* attr - barrier attributes to be destroyed.
|
||||
*
|
||||
* Return Value:
|
||||
* 0 (OK) on success or EINVAL if attr is invalid.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
int pthread_barrierattr_destroy(FAR pthread_barrierattr_t *attr)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
if (!attr)
|
||||
{
|
||||
ret = EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
attr->pshared = PTHREAD_PROCESS_PRIVATE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/********************************************************************************
|
||||
* pthread_barrierattrgetpshared.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Type Declarations
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Global Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Function Prototypes
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Public Functions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Function: pthread_barrierattr_getpshared
|
||||
*
|
||||
* Description:
|
||||
* The pthread_barrierattr_getpshared() function will obtain the value of the
|
||||
* process-shared attribute from the attributes object referenced by attr.
|
||||
*
|
||||
* Parameters:
|
||||
* attr - barrier attributes to be queried.
|
||||
* pshared - the location to stored the current value of the pshared attribute.
|
||||
*
|
||||
* Return Value:
|
||||
* 0 (OK) on success or EINVAL if either attr or pshared is invalid.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
int pthread_barrierattr_getpshared(FAR const pthread_barrierattr_t *attr, FAR int *pshared)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
if (!attr || !pshared)
|
||||
{
|
||||
ret = EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
*pshared = attr->pshared;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/********************************************************************************
|
||||
* pthread_barrierattrinit.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Type Declarations
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Global Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Function Prototypes
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Public Functions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Function: pthread_barrierattr_init
|
||||
*
|
||||
* Description:
|
||||
* The pthread_barrierattr_init() function will initialize a barrier attribute
|
||||
* object attr with the default value for all of the attributes defined by the
|
||||
* implementation.
|
||||
*
|
||||
* Parameters:
|
||||
* attr - barrier attributes to be initialized.
|
||||
*
|
||||
* Return Value:
|
||||
* 0 (OK) on success or EINVAL if attr is invalid.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
int pthread_barrierattr_init(FAR pthread_barrierattr_t *attr)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
if (!attr)
|
||||
{
|
||||
ret = EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
attr->pshared = PTHREAD_PROCESS_PRIVATE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/********************************************************************************
|
||||
* pthread_barrierattrsetpshared.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Type Declarations
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Global Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Function Prototypes
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Public Functions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Function: pthread_barrierattr_setpshared
|
||||
*
|
||||
* Description:
|
||||
* The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit a
|
||||
* barrier to be operated upon by any thread that has access to the memory where
|
||||
* the barrier is allocated. If the process-shared attribute is
|
||||
* PTHREAD_PROCESS_PRIVATE, the barrier can only be operated upon by threads
|
||||
* created within the same process as the thread that initialized the barrier.
|
||||
* If threads of different processes attempt to operate on such a barrier, the
|
||||
* behavior is undefined. The default value of the attribute is
|
||||
* PTHREAD_PROCESS_PRIVATE.
|
||||
*
|
||||
* Both constants PTHREAD_PROCESS_SHARED and PTHREAD_PROCESS_PRIVATE are defined
|
||||
* in pthread.h.
|
||||
*
|
||||
* Parameters:
|
||||
* attr - barrier attributes to be modified.
|
||||
* pshared - the new value of the pshared attribute.
|
||||
*
|
||||
* Return Value:
|
||||
* 0 (OK) on success or EINVAL if either attr is invalid or pshared is not one
|
||||
* of PTHREAD_PROCESS_SHARED or PTHREAD_PROCESS_PRIVATE.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
int pthread_barrierattr_setpshared(FAR pthread_barrierattr_t *attr, int pshared)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
if (!attr || (pshared != PTHREAD_PROCESS_SHARED && pshared != PTHREAD_PROCESS_PRIVATE))
|
||||
{
|
||||
ret = EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
attr->pshared = pshared;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/********************************************************************************
|
||||
* pthread_barriedestroy.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Type Declarations
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Global Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Function Prototypes
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Public Functions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Function: pthread_barrier_destroy
|
||||
*
|
||||
* Description:
|
||||
* The pthread_barrier_destroy() function destroys the barrier referenced by
|
||||
* 'barrier' and releases any resources used by the barrier. The effect of
|
||||
* subsequent use of the barrier is undefined until the barrier is
|
||||
* reinitialized by another call to pthread_barrier_init(). The results are
|
||||
* undefined if pthread_barrier_destroy() is called when any thread is blocked
|
||||
* on the barrier, or if this function is called with an uninitialized barrier.
|
||||
*
|
||||
* Parameters:
|
||||
* barrier - barrier to be destroyed.
|
||||
*
|
||||
* Return Value:
|
||||
* 0 (OK) on success or on of the following error numbers:
|
||||
*
|
||||
* EBUSY The implementation has detected an attempt to destroy a barrier while
|
||||
* it is in use.
|
||||
* EINVAL The value specified by barrier is invalid.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
int pthread_barrier_destroy(FAR pthread_barrier_t *barrier)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
if (!barrier)
|
||||
{
|
||||
ret = EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
sem_destroy(&barrier->sem);
|
||||
barrier->count = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/********************************************************************************
|
||||
* pthread_barrieinit.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Type Declarations
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Global Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Function Prototypes
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Public Functions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Function: pthread_barrier_init
|
||||
*
|
||||
* Description:
|
||||
* The pthread_barrier_init() function allocates any resources required to use
|
||||
* the barrier referenced by 'barrier' and initialized the barrier with the
|
||||
* attributes referenced by attr. If attr is NULL, the default barrier
|
||||
* attributes will be used. The results are undefined if pthread_barrier_init()
|
||||
* is called when any thread is blocked on the barrier. The results are
|
||||
* undefined if a barrier is used without first being initialized. The results
|
||||
* are undefined if pthread_barrier_init() is called specifying an already
|
||||
* initialized barrier.
|
||||
*
|
||||
* Parameters:
|
||||
* barrier - the barrier to be initialized
|
||||
* attr - barrier attributes to be used in the initialization.
|
||||
* count - the count to be associated with the barrier. The count argument
|
||||
* specifies the number of threads that must call pthread_barrier_wait() before
|
||||
* any of them successfully return from the call. The value specified by
|
||||
* count must be greater than zero.
|
||||
*
|
||||
* Return Value:
|
||||
* 0 (OK) on success or on of the following error numbers:
|
||||
*
|
||||
* EAGAIN The system lacks the necessary resources to initialize another barrier.
|
||||
* EINVAL The barrier reference is invalid, or the values specified by attr are
|
||||
* invalid, or the value specified by count is equal to zero.
|
||||
* ENOMEM Insufficient memory exists to initialize the barrier.
|
||||
* EBUSY The implementation has detected an attempt to reinitialize a barrier
|
||||
* while it is in use.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
int pthread_barrier_init(FAR pthread_barrier_t *barrier,
|
||||
FAR const pthread_barrierattr_t *attr, unsigned int count)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
if (!barrier || count == 0)
|
||||
{
|
||||
ret = EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
sem_init(&barrier->sem, 0, 0);
|
||||
barrier->count = count;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
/********************************************************************************
|
||||
* pthread_barrierwait.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Type Declarations
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Global Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Function Prototypes
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Public Functions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Function: pthread_barrier_wait
|
||||
*
|
||||
* Description:
|
||||
* The pthread_barrier_wait() function synchronizse participating threads at
|
||||
* the barrier referenced by 'barrier'. The calling thread is blocked until
|
||||
* the required number of threads have called pthread_barrier_wait() specifying
|
||||
* the same 'barrier'. When the required number of threads have called
|
||||
* pthread_barrier_wait() specifying the 'barrier', the constant
|
||||
* PTHREAD_BARRIER_SERIAL_THREAD will be returned to one unspecified thread
|
||||
* and zero will be returned to each of the remaining threads. At this point,
|
||||
* the barrier will be reset to the state it had as a result of the most recent
|
||||
* pthread_barrier_init() function that referenced it.
|
||||
*
|
||||
* The constant PTHREAD_BARRIER_SERIAL_THREAD is defined in pthread.h and its
|
||||
* value must be distinct from any other value returned by pthread_barrier_wait().
|
||||
*
|
||||
* The results are undefined if this function is called with an uninitialized
|
||||
* barrier.
|
||||
*
|
||||
* If a signal is delivered to a thread blocked on a barrier, upon return from
|
||||
* the signal handler the thread will resume waiting at the barrier if the barrier
|
||||
* wait has not completed; otherwise, the thread will continue as normal from
|
||||
* the completed barrier wait. Until the thread in the signal handler returns
|
||||
* from it, it is unspecified whether other threads may proceed past the barrier
|
||||
* once they have all reached it.
|
||||
*
|
||||
* A thread that has blocked on a barrier will not prevent any unblocked thread
|
||||
* that is eligible to use the same processing resources from eventually making
|
||||
* forward progress in its execution. Eligibility for processing resources will
|
||||
* be determined by the scheduling policy.
|
||||
*
|
||||
* Parameters:
|
||||
* barrier - the barrier to wait on
|
||||
*
|
||||
* Return Value:
|
||||
* 0 (OK) on success or EINVAL if the barrier is not valid.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
int pthread_barrier_wait(FAR pthread_barrier_t *barrier)
|
||||
{
|
||||
int semcount;
|
||||
int ret = OK;
|
||||
|
||||
if (!barrier)
|
||||
{
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
/* Disable pre-emption throughout the following */
|
||||
|
||||
sched_lock();
|
||||
|
||||
/* Find out how many threads are already waiting at the barrier */
|
||||
|
||||
ret = sem_getvalue(&barrier->sem, &semcount);
|
||||
if (ret != OK)
|
||||
{
|
||||
sched_unlock();
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
/* If the number of waiters would be equal to the count, then we are done */
|
||||
|
||||
if (1 - semcount >= barrier->count)
|
||||
{
|
||||
/* Free all of the waiting threads */
|
||||
|
||||
while (semcount < 0)
|
||||
{
|
||||
(void)sem_post(&barrier->sem);
|
||||
(void)sem_getvalue(&barrier->sem, &semcount);
|
||||
}
|
||||
|
||||
/* Then return PTHREAD_BARRIER_SERIAL_THREAD to the final thread */
|
||||
|
||||
sched_unlock();
|
||||
return PTHREAD_BARRIER_SERIAL_THREAD;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise, this thread must wait as well */
|
||||
|
||||
while (sem_wait(&barrier->sem) != OK)
|
||||
{
|
||||
/* If the thread is awakened by a signal, just continue to wait */
|
||||
|
||||
int errornumber = *get_errno_ptr();
|
||||
if (errornumber != EINTR)
|
||||
{
|
||||
/* If it is awakened by some other error, then there is a
|
||||
* problem
|
||||
*/
|
||||
|
||||
sched_unlock();
|
||||
return errornumber;
|
||||
}
|
||||
}
|
||||
|
||||
/* We will only get here when we are one of the N-1 threads that were
|
||||
* waiting for the final thread at the barrier. We just need to return
|
||||
* zero.
|
||||
*/
|
||||
|
||||
sched_unlock();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/************************************************************
|
||||
* pthread_kill.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
/************************************************************
|
||||
* Global Functions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Function: pthread_kill
|
||||
*
|
||||
* Description:
|
||||
* The pthread_kill() system call can be used to send any
|
||||
* signal to a thread. See kill() for further information
|
||||
* as this is just a simple wrapper around the kill()
|
||||
* function.
|
||||
*
|
||||
* Parameters:
|
||||
* thread - The id of the thread to receive the signal. Only
|
||||
* positive, non-zero values of 'thread' are supported.
|
||||
* signo - The signal number to send. If 'signo' is zero,
|
||||
* no signal is sent, but all error checking is performed.
|
||||
*
|
||||
* Return Value:
|
||||
* On success the signal was send and zero is returned.
|
||||
* On error one of the following error numbers is returned.
|
||||
*
|
||||
* EINVAL An invalid signal was specified.
|
||||
* EPERM The thread does not have permission to send the
|
||||
* signal to the target thread.
|
||||
* ESRCH No thread could be found corresponding to that
|
||||
* specified by the given thread ID
|
||||
* ENOSYS Do not support sending signals to process groups.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
int pthread_kill(pthread_t thread, int signo)
|
||||
{
|
||||
int ret;
|
||||
|
||||
*get_errno_ptr() = EINVAL;
|
||||
ret = kill((pid_t)thread, signo);
|
||||
if (ret != OK)
|
||||
{
|
||||
ret = *get_errno_ptr();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/********************************************************************************
|
||||
* pthread_once.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
/********************************************************************************
|
||||
* Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Type Declarations
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Global Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Function Prototypes
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Public Functions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Function: pthread_once
|
||||
*
|
||||
* Description:
|
||||
* The first call to pthread_once() by any thread with a given once_control,
|
||||
* will call the init_routine with no arguments. Subsequent calls to
|
||||
* pthread_once() with the same once_control will have no effect. On return
|
||||
* from pthread_once(), init_routine will have completed.
|
||||
*
|
||||
* Parameters:
|
||||
* once_control - Determines if init_routine should be called. once_control
|
||||
* should be declared and intialized as follows:
|
||||
*
|
||||
* pthread_once_t once_control = PTHREAD_ONCE_INIT;
|
||||
*
|
||||
* PTHREAD_ONCE_INIT is defined in pthread.h
|
||||
* init_routine - The initialization routine that will be called once.
|
||||
*
|
||||
* Return Value:
|
||||
* 0 (OK) on success or EINVAL if either once_control or init_routine are invalid
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
********************************************************************************/
|
||||
|
||||
int pthread_once(FAR pthread_once_t *once_control, CODE void (*init_routine)(void))
|
||||
{
|
||||
/* Sanity checks */
|
||||
|
||||
if (once_control && init_routine)
|
||||
{
|
||||
/* Prohibit pre-emption while we test and set the once_control */
|
||||
|
||||
sched_lock();
|
||||
if (!*once_control)
|
||||
{
|
||||
*once_control = TRUE;
|
||||
|
||||
/* Call the init_routine with pre-emption enabled. */
|
||||
|
||||
sched_unlock();
|
||||
init_routine();
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* The init_routine has already been called. Restore pre-emption and return */
|
||||
|
||||
sched_unlock();
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* One of the two arguments is NULL */
|
||||
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/************************************************************
|
||||
* pthread_sigmask.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Type Declarations
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Variables
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Variables
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Functions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Function: pthread_sigmask
|
||||
*
|
||||
* Description:
|
||||
* This function is a simple wrapper around sigprocmask().
|
||||
* See the sigprocmask() function description for further
|
||||
* information.
|
||||
*
|
||||
* Parameters:
|
||||
* how - How the signal mast will be changed:
|
||||
* SIG_BLOCK - The resulting set is the union of
|
||||
* the current set and the signal set
|
||||
* pointed to by 'set'.
|
||||
* SIG_UNBLOCK - The resulting set is the intersection
|
||||
* of the current set and the complement
|
||||
* of the signal set pointed to by 'set'.
|
||||
* SIG_SETMASK - The resulting set is the signal set
|
||||
* pointed to by 'set'.
|
||||
* set - Location of the new signal mask
|
||||
* oset - Location to store the old signal mask
|
||||
*
|
||||
* Return Value:
|
||||
* 0 (OK) or EINVAL if how is invalid.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset)
|
||||
{
|
||||
int ret = sigprocmask(how, set, oset);
|
||||
if (ret != OK)
|
||||
{
|
||||
ret = EINVAL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
+4
-2
@@ -64,10 +64,12 @@
|
||||
* information as zero and negative pid values. Only
|
||||
* positive, non-zero values of pid are supported by this
|
||||
* implementation.
|
||||
* signo - The signal number to send.
|
||||
* signo - The signal number to send. If signo is zero,
|
||||
* no signal is sent, but all error checking is performed.
|
||||
*
|
||||
*
|
||||
* Return Value:
|
||||
* On success (at least one signal was sent), zero is
|
||||
* On success (at least one signal was sent), zero is
|
||||
* returned. On error, -1 is returned, and errno is set
|
||||
* appropriately.
|
||||
*
|
||||
|
||||
+1
-1
@@ -235,7 +235,7 @@ STATUS task_schedsetup(FAR _TCB *tcb, int priority,
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
STATUS task_argsetup(FAR _TCB *tcb, const char *name, char *argv[])
|
||||
STATUS task_argsetup(FAR _TCB *tcb, const char *name, const char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
@@ -150,10 +150,10 @@ void weak_function timer_deleteall(pid_t pid)
|
||||
irqstate_t flags;
|
||||
|
||||
flags = irqsave();
|
||||
for (timer = g_alloctimers.head; timer; timer = next)
|
||||
for (timer = (FAR struct posix_timer_s*)g_alloctimers.head; timer; timer = next)
|
||||
{
|
||||
next = timer->flink;
|
||||
if (timer->pt_owner = pid)
|
||||
if (timer->pt_owner == pid)
|
||||
{
|
||||
timer_delete((timer_t)timer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user