Merge pull request #1128 from jiaooo/dev

[PThreads] add some parameter check and function definition etc.
This commit is contained in:
Bernard Xiong 2017-12-22 14:34:21 +08:00 committed by GitHub
commit 4ab7214a32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View File

@ -27,6 +27,7 @@
#include <rtthread.h> #include <rtthread.h>
#include <posix_types.h> #include <posix_types.h>
#include <sched.h>
#define PTHREAD_KEY_MAX 8 #define PTHREAD_KEY_MAX 8
@ -139,6 +140,11 @@ struct pthread_barrier
}; };
typedef struct pthread_barrier pthread_barrier_t; typedef struct pthread_barrier pthread_barrier_t;
struct sched_param
{
int sched_priority;
};
/* pthread thread interface */ /* pthread thread interface */
int pthread_attr_destroy(pthread_attr_t *attr); int pthread_attr_destroy(pthread_attr_t *attr);
int pthread_attr_init(pthread_attr_t *attr); int pthread_attr_init(pthread_attr_t *attr);
@ -146,6 +152,8 @@ int pthread_attr_setdetachstate(pthread_attr_t *attr, int state);
int pthread_attr_getdetachstate(pthread_attr_t const *attr, int *state); int pthread_attr_getdetachstate(pthread_attr_t const *attr, int *state);
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy); int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
int pthread_attr_getschedpolicy(pthread_attr_t const *attr, int *policy); int pthread_attr_getschedpolicy(pthread_attr_t const *attr, int *policy);
int pthread_attr_setschedparam(pthread_attr_t *attr,struct sched_param const *param);
int pthread_attr_getschedparam(pthread_attr_t const *attr,struct sched_param *param);
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stack_size); int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stack_size);
int pthread_attr_getstacksize(pthread_attr_t const *attr, size_t *stack_size); int pthread_attr_getstacksize(pthread_attr_t const *attr, size_t *stack_size);
int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stack_addr); int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stack_addr);
@ -156,7 +164,10 @@ int pthread_attr_setstack(pthread_attr_t *attr,
int pthread_attr_getstack(pthread_attr_t const *attr, int pthread_attr_getstack(pthread_attr_t const *attr,
void **stack_base, void **stack_base,
size_t *stack_size); size_t *stack_size);
int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guard_size);
int pthread_attr_getguardsize(pthread_attr_t const *attr, size_t *guard_size);
int pthread_attr_setscope(pthread_attr_t *attr, int scope);
int pthread_attr_getscope(pthread_attr_t const *attr);
int pthread_system_init(void); int pthread_system_init(void);
int pthread_create (pthread_t *tid, const pthread_attr_t *attr, int pthread_create (pthread_t *tid, const pthread_attr_t *attr,
void *(*start) (void *), void *arg); void *(*start) (void *), void *arg);

View File

@ -137,6 +137,9 @@ RTM_EXPORT(pthread_cond_destroy);
int pthread_cond_broadcast(pthread_cond_t *cond) int pthread_cond_broadcast(pthread_cond_t *cond)
{ {
rt_err_t result; rt_err_t result;
if (cond == RT_NULL)
return EINVAL;
if (cond->attr == -1) if (cond->attr == -1)
pthread_cond_init(cond, RT_NULL); pthread_cond_init(cond, RT_NULL);
@ -173,6 +176,8 @@ int pthread_cond_signal(pthread_cond_t *cond)
{ {
rt_err_t result; rt_err_t result;
if (cond == RT_NULL)
return EINVAL;
if (cond->attr == -1) if (cond->attr == -1)
pthread_cond_init(cond, RT_NULL); pthread_cond_init(cond, RT_NULL);

View File

@ -37,11 +37,6 @@ enum
SCHED_MAX = SCHED_RR SCHED_MAX = SCHED_RR
}; };
struct sched_param
{
int sched_priority;
};
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {