|
@@ -16,14 +16,13 @@
|
|
|
|
|
|
#include <rtthread.h>
|
|
#include <rtthread.h>
|
|
#include <errno.h>
|
|
#include <errno.h>
|
|
-
|
|
|
|
-#include "pthread_attr.h"
|
|
|
|
-#include "pthread_mutex.h"
|
|
|
|
|
|
+#include <sys/types.h>
|
|
|
|
|
|
typedef rt_thread_t pthread_t;
|
|
typedef rt_thread_t pthread_t;
|
|
-
|
|
|
|
typedef long pthread_condattr_t;
|
|
typedef long pthread_condattr_t;
|
|
typedef long pthread_rwlockattr_t;
|
|
typedef long pthread_rwlockattr_t;
|
|
|
|
+typedef long pthread_mutexattr_t;
|
|
|
|
+typedef long pthread_barrierattr_t;
|
|
|
|
|
|
typedef int pthread_key_t;
|
|
typedef int pthread_key_t;
|
|
typedef int pthread_once_t;
|
|
typedef int pthread_once_t;
|
|
@@ -74,7 +73,62 @@ enum {
|
|
struct sched_param {
|
|
struct sched_param {
|
|
int sched_priority;
|
|
int sched_priority;
|
|
};
|
|
};
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+struct pthread_attr
|
|
|
|
+{
|
|
|
|
+ void* stack_base;
|
|
|
|
+ rt_uint16_t stack_size; /* stack size of thread */
|
|
|
|
+
|
|
|
|
+ rt_uint8_t priority; /* priority of thread */
|
|
|
|
+ rt_uint8_t detachstate; /* detach state */
|
|
|
|
+ rt_uint8_t policy; /* scheduler policy */
|
|
|
|
+ rt_uint8_t inheritsched; /* Inherit parent prio/policy */
|
|
|
|
+};
|
|
|
|
+typedef struct pthread_attr pthread_attr_t;
|
|
|
|
+
|
|
|
|
+struct pthread_mutex
|
|
|
|
+{
|
|
|
|
+ pthread_mutexattr_t attr;
|
|
|
|
+ struct rt_mutex lock;
|
|
|
|
+};
|
|
|
|
+typedef struct pthread_mutex pthread_mutex_t;
|
|
|
|
+
|
|
|
|
+struct pthread_cond
|
|
|
|
+{
|
|
|
|
+ pthread_condattr_t attr;
|
|
|
|
+ struct rt_semaphore sem;
|
|
|
|
+};
|
|
|
|
+typedef struct pthread_cond pthread_cond_t;
|
|
|
|
+
|
|
|
|
+struct pthread_rwlock
|
|
|
|
+{
|
|
|
|
+ pthread_rwlockattr_t attr;
|
|
|
|
+
|
|
|
|
+ pthread_mutex_t rw_mutex; /* basic lock on this struct */
|
|
|
|
+ pthread_cond_t rw_condreaders; /* for reader threads waiting */
|
|
|
|
+ pthread_cond_t rw_condwriters; /* for writer threads waiting */
|
|
|
|
+
|
|
|
|
+ int rw_nwaitreaders; /* the number waiting */
|
|
|
|
+ int rw_nwaitwriters; /* the number waiting */
|
|
|
|
+ int rw_refcount;
|
|
|
|
+};
|
|
|
|
+typedef struct pthread_rwlock pthread_rwlock_t;
|
|
|
|
+
|
|
|
|
+/* spinlock implementation, (ADVANCED REALTIME THREADS)*/
|
|
|
|
+struct pthread_spinlock
|
|
|
|
+{
|
|
|
|
+ int lock;
|
|
|
|
+};
|
|
|
|
+typedef struct pthread_spinlock pthread_spinlock_t;
|
|
|
|
+
|
|
|
|
+struct pthread_barrier
|
|
|
|
+{
|
|
|
|
+ int count;
|
|
|
|
+ pthread_cond_t cond;
|
|
|
|
+ pthread_mutex_t mutex;
|
|
|
|
+};
|
|
|
|
+typedef struct pthread_barrier pthread_barrier_t;
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Scheduling policies required by IEEE Std 1003.1-2001
|
|
* Scheduling policies required by IEEE Std 1003.1-2001
|
|
*/
|
|
*/
|
|
@@ -82,6 +136,10 @@ struct sched_param {
|
|
#define SCHED_FIFO 1
|
|
#define SCHED_FIFO 1
|
|
#define SCHED_RR 2
|
|
#define SCHED_RR 2
|
|
|
|
|
|
|
|
+/* pthread thread interface */
|
|
|
|
+int pthread_attr_destroy(pthread_attr_t *attr);
|
|
|
|
+int pthread_attr_init(pthread_attr_t *attr);
|
|
|
|
+
|
|
int pthread_init (void);
|
|
int pthread_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);
|
|
@@ -100,17 +158,94 @@ rt_inline pthread_t pthread_self (void)
|
|
}
|
|
}
|
|
|
|
|
|
void pthread_exit (void *value_ptr);
|
|
void pthread_exit (void *value_ptr);
|
|
-
|
|
|
|
int pthread_once(pthread_once_t * once_control, void (*init_routine) (void));
|
|
int pthread_once(pthread_once_t * once_control, void (*init_routine) (void));
|
|
|
|
|
|
|
|
+/* pthread cleanup */
|
|
|
|
+void pthread_cleanup_pop(int execute);
|
|
|
|
+void pthread_cleanup_push(void (*routine)(void*), void *arg);
|
|
|
|
+
|
|
/* pthread cancel */
|
|
/* pthread cancel */
|
|
int pthread_cancel(pthread_t thread);
|
|
int pthread_cancel(pthread_t thread);
|
|
void pthread_testcancel(void);
|
|
void pthread_testcancel(void);
|
|
-
|
|
|
|
int pthread_setcancelstate(int state, int *oldstate);
|
|
int pthread_setcancelstate(int state, int *oldstate);
|
|
int pthread_setcanceltype(int type, int *oldtype);
|
|
int pthread_setcanceltype(int type, int *oldtype);
|
|
|
|
|
|
int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void));
|
|
int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void));
|
|
|
|
+int pthread_kill(pthread_t thread, int sig);
|
|
|
|
+
|
|
|
|
+/* pthread mutex interface */
|
|
|
|
+int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
|
|
|
|
+int pthread_mutex_destroy(pthread_mutex_t *mutex);
|
|
|
|
+int pthread_mutex_lock(pthread_mutex_t *mutex);
|
|
|
|
+int pthread_mutex_unlock(pthread_mutex_t *mutex);
|
|
|
|
+int pthread_mutex_trylock(pthread_mutex_t *mutex);
|
|
|
|
+
|
|
|
|
+int pthread_mutexattr_init(pthread_mutexattr_t *attr);
|
|
|
|
+int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
|
|
|
|
+int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type);
|
|
|
|
+int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
|
|
|
|
+int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);
|
|
|
|
+int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared);
|
|
|
|
+
|
|
|
|
+/* pthread condition interface */
|
|
|
|
+int pthread_condattr_destroy(pthread_condattr_t *attr);
|
|
|
|
+int pthread_condattr_init(pthread_condattr_t *attr);
|
|
|
|
+
|
|
|
|
+/* ADVANCED REALTIME feature in IEEE Std 1003.1, 2004 Edition */
|
|
|
|
+int pthread_condattr_getclock(const pthread_condattr_t *attr,
|
|
|
|
+ clockid_t *clock_id);
|
|
|
|
+int pthread_condattr_setclock(pthread_condattr_t *attr,
|
|
|
|
+ clockid_t clock_id);
|
|
|
|
+
|
|
|
|
+int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
|
|
|
|
+int pthread_cond_destroy(pthread_cond_t *cond);
|
|
|
|
+int pthread_cond_broadcast(pthread_cond_t *cond);
|
|
|
|
+int pthread_cond_signal(pthread_cond_t *cond);
|
|
|
|
+
|
|
|
|
+int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
|
|
|
|
+int pthread_cond_timedwait(pthread_cond_t *cond,
|
|
|
|
+ pthread_mutex_t * mutex,
|
|
|
|
+ const struct timespec *abstime);
|
|
|
|
+
|
|
|
|
+/* pthread rwlock interface */
|
|
|
|
+int pthread_rwlockattr_init (pthread_rwlockattr_t *attr);
|
|
|
|
+int pthread_rwlockattr_destroy (pthread_rwlockattr_t *attr);
|
|
|
|
+int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *attr, int *pshared);
|
|
|
|
+int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *attr, int pshared);
|
|
|
|
+
|
|
|
|
+int pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr);
|
|
|
|
+int pthread_rwlock_destroy (pthread_rwlock_t *rwlock);
|
|
|
|
+
|
|
|
|
+int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock);
|
|
|
|
+int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock);
|
|
|
|
+
|
|
|
|
+int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock, const struct timespec *abstime);
|
|
|
|
+int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock, const struct timespec *abstime);
|
|
|
|
+
|
|
|
|
+int pthread_rwlock_unlock (pthread_rwlock_t *rwlock);
|
|
|
|
+
|
|
|
|
+int pthread_rwlock_wrlock (pthread_rwlock_t *rwlock);
|
|
|
|
+int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock);
|
|
|
|
+
|
|
|
|
+/* pthread spinlock interface */
|
|
|
|
+int pthread_spin_init (pthread_spinlock_t *lock, int pshared);
|
|
|
|
+int pthread_spin_destroy (pthread_spinlock_t *lock);
|
|
|
|
+
|
|
|
|
+int pthread_spin_lock (pthread_spinlock_t * lock);
|
|
|
|
+int pthread_spin_trylock (pthread_spinlock_t * lock);
|
|
|
|
+int pthread_spin_unlock (pthread_spinlock_t * lock);
|
|
|
|
+
|
|
|
|
+/* pthread barrier interface */
|
|
|
|
+int pthread_barrierattr_destroy(pthread_barrierattr_t *attr);
|
|
|
|
+int pthread_barrierattr_init(pthread_barrierattr_t *attr);
|
|
|
|
+int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, int *pshared);
|
|
|
|
+int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared);
|
|
|
|
+
|
|
|
|
+int pthread_barrier_destroy(pthread_barrier_t *barrier);
|
|
|
|
+int pthread_barrier_init(pthread_barrier_t *barrier,
|
|
|
|
+ const pthread_barrierattr_t *attr, unsigned count);
|
|
|
|
+
|
|
|
|
+int pthread_barrier_wait(pthread_barrier_t *barrier);
|
|
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|