Embedded GPLv2 license in pthreads

This commit is contained in:
yiyue.fang committed 2013-06-26 23:18:30 +08:00
1 parent 773990abdb
commit 8ab2b287b8
18 files changed
+2239 -1617

No files matched your search

File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+54 -24
View File
@@ -1,3 +1,26 @@
/*
* File : mqueue.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2012, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#ifndef __MQUEUE_H__
#define __MQUEUE_H__
@@ -6,38 +29,45 @@
struct mqdes
{
/* reference count and unlinked */
rt_uint16_t refcount;
rt_uint16_t unlinked;
/* reference count and unlinked */
rt_uint16_t refcount;
rt_uint16_t unlinked;
/* RT-Thread message queue */
rt_mq_t mq;
/* next posix mqueue */
struct mqdes* next;
/* RT-Thread message queue */
rt_mq_t mq;
/* next posix mqueue */
struct mqdes* next;
};
typedef struct mqdes* mqd_t;
struct mq_attr
{
long mq_flags; /* Message queue flags. */
long mq_maxmsg; /* Maximum number of messages. */
long mq_msgsize; /* Maximum message size. */
long mq_curmsgs; /* Number of messages currently queued. */
long mq_flags; /* Message queue flags. */
long mq_maxmsg; /* Maximum number of messages. */
long mq_msgsize; /* Maximum message size. */
long mq_curmsgs; /* Number of messages currently queued. */
};
int mq_close(mqd_t mqdes);
int mq_getattr(mqd_t mqdes, struct mq_attr *mqstat);
int mq_notify(mqd_t mqdes, const struct sigevent *notification);
mqd_t mq_open(const char *name, int oflag, ...);
ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio);
int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio);
int mq_setattr(mqd_t mqdes, const struct mq_attr *mqstat,
struct mq_attr *omqstat);
ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
unsigned *msg_prio, const struct timespec *abs_timeout);
int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio,
const struct timespec *abs_timeout);
int mq_close(mqd_t mqdes);
int mq_getattr(mqd_t mqdes, struct mq_attr *mqstat);
int mq_notify(mqd_t mqdes, const struct sigevent *notification);
mqd_t mq_open(const char *name, int oflag, ...);
ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio);
int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio);
int mq_setattr(mqd_t mqdes,
const struct mq_attr *mqstat,
struct mq_attr *omqstat);
ssize_t mq_timedreceive(mqd_t mqdes,
char *msg_ptr,
size_t msg_len,
unsigned *msg_prio,
const struct timespec *abs_timeout);
int mq_timedsend(mqd_t mqdes,
const char *msg_ptr,
size_t msg_len,
unsigned msg_prio,
const struct timespec *abs_timeout);
int mq_unlink(const char *name);
int mq_unlink(const char *name);
#endif
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+78 -39
View File
@@ -1,85 +1,124 @@
/*
* File : pthread_barrier.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-10-26 Bernard the first version
*/
#include <pthread.h>
int pthread_barrierattr_destroy(pthread_barrierattr_t *attr)
{
if (!attr) return EINVAL;
return 0;
if (!attr)
return EINVAL;
return 0;
}
RTM_EXPORT(pthread_barrierattr_destroy);
int pthread_barrierattr_init(pthread_barrierattr_t *attr)
{
if (!attr) return EINVAL;
*attr = PTHREAD_PROCESS_PRIVATE;
if (!attr)
return EINVAL;
*attr = PTHREAD_PROCESS_PRIVATE;
return 0;
return 0;
}
RTM_EXPORT(pthread_barrierattr_init);
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, int *pshared)
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr,
int *pshared)
{
if (!attr) return EINVAL;
*pshared = (int)*attr;
if (!attr)
return EINVAL;
*pshared = (int)*attr;
return 0;
return 0;
}
RTM_EXPORT(pthread_barrierattr_getpshared);
int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared)
{
if (!attr) return EINVAL;
if (pshared == PTHREAD_PROCESS_PRIVATE) attr = PTHREAD_PROCESS_PRIVATE;
if (!attr)
return EINVAL;
if (pshared == PTHREAD_PROCESS_PRIVATE)
attr = PTHREAD_PROCESS_PRIVATE;
return EINVAL;
return EINVAL;
}
RTM_EXPORT(pthread_barrierattr_setpshared);
int pthread_barrier_destroy(pthread_barrier_t *barrier)
{
rt_err_t result;
rt_err_t result;
if (!barrier) return EINVAL;
if (!barrier)
return EINVAL;
result = pthread_cond_destroy(&(barrier->cond));
result = pthread_cond_destroy(&(barrier->cond));
return result;
return result;
}
RTM_EXPORT(pthread_barrier_destroy);
int pthread_barrier_init(pthread_barrier_t *barrier,
const pthread_barrierattr_t *attr, unsigned count)
int pthread_barrier_init(pthread_barrier_t *barrier,
const pthread_barrierattr_t *attr,
unsigned count)
{
if (!barrier) return EINVAL;
if (attr &&(*attr != PTHREAD_PROCESS_PRIVATE)) return EINVAL;
if (!barrier)
return EINVAL;
if (attr && (*attr != PTHREAD_PROCESS_PRIVATE))
return EINVAL;
barrier->count = count;
pthread_cond_init(&(barrier->cond), NULL);
pthread_mutex_init(&(barrier->mutex), NULL);
barrier->count = count;
pthread_cond_init(&(barrier->cond), NULL);
pthread_mutex_init(&(barrier->mutex), NULL);
return 0;
return 0;
}
RTM_EXPORT(pthread_barrier_init);
int pthread_barrier_wait(pthread_barrier_t *barrier)
{
rt_err_t result;
if (!barrier) return EINVAL;
rt_err_t result;
if (!barrier)
return EINVAL;
result = pthread_mutex_lock(&(barrier->mutex));
if (result != 0) return EINVAL;
result = pthread_mutex_lock(&(barrier->mutex));
if (result != 0)
return EINVAL;
if (barrier->count == 0) result = EINVAL;
else
{
barrier->count -= 1;
if (barrier->count == 0) /* broadcast condition */
pthread_cond_broadcast(&(barrier->cond));
else
pthread_cond_wait(&(barrier->cond), &(barrier->mutex));
}
if (barrier->count == 0)
result = EINVAL;
else
{
barrier->count -= 1;
if (barrier->count == 0) /* broadcast condition */
pthread_cond_broadcast(&(barrier->cond));
else
pthread_cond_wait(&(barrier->cond), &(barrier->mutex));
}
pthread_mutex_unlock(&(barrier->mutex));
return result;
pthread_mutex_unlock(&(barrier->mutex));
return result;
}
RTM_EXPORT(pthread_barrier_wait);
File diff suppressed because it is too large. Load diff
+52 -28
View File
@@ -1,3 +1,27 @@
/*
* File : pthread_internal.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-10-26 Bernard the first version
*/
#ifndef __PTHREAD_INTERNAL_H__
#define __PTHREAD_INTERNAL_H__
@@ -6,56 +30,56 @@
struct _pthread_cleanup
{
void (*cleanup_func)(void* parameter);
void* parameter;
void (*cleanup_func)(void *parameter);
void *parameter;
struct _pthread_cleanup* next;
struct _pthread_cleanup *next;
};
typedef struct _pthread_cleanup _pthread_cleanup_t;
struct _pthread_key_data
{
int is_used;
void (*destructor)(void* parameter);
int is_used;
void (*destructor)(void *parameter);
};
typedef struct _pthread_key_data _pthread_key_data_t;
#define PTHREAD_MAGIC 0x70746873
#define PTHREAD_MAGIC 0x70746873
struct _pthread_data
{
rt_uint32_t magic;
pthread_attr_t attr;
rt_thread_t tid;
rt_uint32_t magic;
pthread_attr_t attr;
rt_thread_t tid;
void* (*thread_entry)(void* parameter);
void* thread_parameter;
void* (*thread_entry)(void *parameter);
void *thread_parameter;
/* return value */
void* return_value;
/* return value */
void *return_value;
/* semaphore for joinable thread */
rt_sem_t joinable_sem;
/* semaphore for joinable thread */
rt_sem_t joinable_sem;
/* cancel state and type */
rt_uint8_t cancelstate;
volatile rt_uint8_t canceltype;
volatile rt_uint8_t canceled;
/* cancel state and type */
rt_uint8_t cancelstate;
volatile rt_uint8_t canceltype;
volatile rt_uint8_t canceled;
_pthread_cleanup_t* cleanup;
void** tls; /* thread-local storage area */
_pthread_cleanup_t *cleanup;
void** tls; /* thread-local storage area */
};
typedef struct _pthread_data _pthread_data_t;
rt_inline _pthread_data_t* _pthread_get_data(pthread_t thread)
rt_inline _pthread_data_t *_pthread_get_data(pthread_t thread)
{
_pthread_data_t* ptd;
RT_ASSERT(thread != RT_NULL);
_pthread_data_t *ptd;
RT_ASSERT(thread != RT_NULL);
ptd = (_pthread_data_t*)thread->user_data;
RT_ASSERT(ptd != RT_NULL);
RT_ASSERT(ptd->magic == PTHREAD_MAGIC);
ptd = (_pthread_data_t *)thread->user_data;
RT_ASSERT(ptd != RT_NULL);
RT_ASSERT(ptd->magic == PTHREAD_MAGIC);
return ptd;
return ptd;
}
int clock_time_to_tick(const struct timespec *time);
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+54 -22
View File
@@ -1,51 +1,83 @@
/*
* File : pthread_spin.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-10-26 Bernard the first version
*/
#include <pthread.h>
int pthread_spin_init (pthread_spinlock_t *lock, int pshared)
{
if (!lock) return EINVAL;
if (!lock)
return EINVAL;
lock->lock = 0;
return 0;
lock->lock = 0;
return 0;
}
int pthread_spin_destroy (pthread_spinlock_t *lock)
{
if (!lock) return EINVAL;
if (!lock)
return EINVAL;
return 0;
return 0;
}
int pthread_spin_lock (pthread_spinlock_t *lock)
{
if (!lock) return EINVAL;
if (!lock)
return EINVAL;
while (!(lock->lock))
{
lock->lock = 1;
}
while (!(lock->lock))
{
lock->lock = 1;
}
return 0;
return 0;
}
int pthread_spin_trylock (pthread_spinlock_t *lock)
{
if (!lock) return EINVAL;
if (!lock)
return EINVAL;
if (!(lock->lock))
{
lock->lock = 1;
return 0;
}
if (!(lock->lock))
{
lock->lock = 1;
return EBUSY;
return 0;
}
return EBUSY;
}
int pthread_spin_unlock (pthread_spinlock_t *lock)
{
if (!lock) return EINVAL;
if (!(lock->lock)) return EPERM;
if (!lock)
return EINVAL;
if (!(lock->lock))
return EPERM;
lock->lock = 0;
lock->lock = 0;
return 0;
return 0;
}
+72 -43
View File
@@ -1,3 +1,27 @@
/*
* File : pthread_tls.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-10-26 Bernard the first version
*/
#include <pthread.h>
#include "pthread_internal.h"
@@ -5,82 +29,87 @@ _pthread_key_data_t _thread_keys[PTHREAD_KEY_MAX];
void pthread_key_system_init()
{
rt_memset(&_thread_keys[0], 0, sizeof(_thread_keys));
rt_memset(&_thread_keys[0], 0, sizeof(_thread_keys));
}
void *pthread_getspecific(pthread_key_t key)
{
struct _pthread_data* ptd;
struct _pthread_data* ptd;
ptd = _pthread_get_data(rt_thread_self());
RT_ASSERT(ptd != NULL);
ptd = _pthread_get_data(rt_thread_self());
RT_ASSERT(ptd != NULL);
if (ptd->tls == NULL) return NULL;
if (ptd->tls == NULL)
return NULL;
if ((key < PTHREAD_KEY_MAX) && (_thread_keys[key].is_used))
return ptd->tls[key];
if ((key < PTHREAD_KEY_MAX) && (_thread_keys[key].is_used))
return ptd->tls[key];
return NULL;
return NULL;
}
RTM_EXPORT(pthread_getspecific);
int pthread_setspecific(pthread_key_t key, const void *value)
{
struct _pthread_data* ptd;
struct _pthread_data* ptd;
ptd = _pthread_get_data(rt_thread_self());
RT_ASSERT(ptd != NULL);
ptd = _pthread_get_data(rt_thread_self());
RT_ASSERT(ptd != NULL);
/* check tls area */
if (ptd->tls == NULL)
{
ptd->tls = (void**)rt_malloc(sizeof(void*) * PTHREAD_KEY_MAX);
}
/* check tls area */
if (ptd->tls == NULL)
{
ptd->tls = (void**)rt_malloc(sizeof(void*) * PTHREAD_KEY_MAX);
}
if ((key < PTHREAD_KEY_MAX) && _thread_keys[key].is_used)
{
ptd->tls[key] = (void *)value;
return 0;
}
if ((key < PTHREAD_KEY_MAX) && _thread_keys[key].is_used)
{
ptd->tls[key] = (void *)value;
return EINVAL;
return 0;
}
return EINVAL;
}
RTM_EXPORT(pthread_setspecific);
int pthread_key_create(pthread_key_t *key, void (*destructor)(void*))
{
rt_uint32_t index;
rt_uint32_t index;
rt_enter_critical();
for (index = 0; index < PTHREAD_KEY_MAX; index ++)
{
if (_thread_keys[index].is_used == 0)
{
_thread_keys[index].is_used = 1;
_thread_keys[index].destructor = destructor;
rt_enter_critical();
for (index = 0; index < PTHREAD_KEY_MAX; index ++)
{
if (_thread_keys[index].is_used == 0)
{
_thread_keys[index].is_used = 1;
_thread_keys[index].destructor = destructor;
*key = index;
*key = index;
rt_exit_critical();
return 0;
}
}
rt_exit_critical();
rt_exit_critical();
return EAGAIN;
return 0;
}
}
rt_exit_critical();
return EAGAIN;
}
RTM_EXPORT(pthread_key_create);
int pthread_key_delete(pthread_key_t key)
{
if (key >= PTHREAD_KEY_MAX) return EINVAL;
if (key >= PTHREAD_KEY_MAX)
return EINVAL;
rt_enter_critical();
_thread_keys[key].is_used = 0;
_thread_keys[key].destructor = 0;
rt_exit_critical();
rt_enter_critical();
_thread_keys[key].is_used = 0;
_thread_keys[key].destructor = 0;
rt_exit_critical();
return 0;
return 0;
}
RTM_EXPORT(pthread_key_delete);
+33 -9
View File
@@ -1,32 +1,56 @@
/*
* File : sched.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#include <sched.h>
int sched_yield(void)
{
rt_thread_yield();
return 0;
rt_thread_yield();
return 0;
}
RTM_EXPORT(sched_yield);
int sched_get_priority_min(int policy)
{
if (policy != SCHED_FIFO && policy != SCHED_RR)
return EINVAL;
if (policy != SCHED_FIFO && policy != SCHED_RR)
return EINVAL;
return 0;
return 0;
}
RTM_EXPORT(sched_get_priority_min);
int sched_get_priority_max(int policy)
{
if (policy != SCHED_FIFO && policy != SCHED_RR)
return EINVAL;
if (policy != SCHED_FIFO && policy != SCHED_RR)
return EINVAL;
return RT_THREAD_PRIORITY_MAX - 1;
return RT_THREAD_PRIORITY_MAX - 1;
}
RTM_EXPORT(sched_get_priority_max);
int sched_setscheduler(pid_t pid, int policy)
{
return ENOTSUP;
return ENOTSUP;
}
RTM_EXPORT(sched_setscheduler);
+29 -6
View File
@@ -1,3 +1,26 @@
/*
* File : sched.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#ifndef __SCHED_H__
#define __SCHED_H__
@@ -7,16 +30,16 @@
/* Thread scheduling policies */
enum
{
SCHED_OTHER = 0,
SCHED_FIFO,
SCHED_RR,
SCHED_MIN = SCHED_OTHER,
SCHED_MAX = SCHED_RR
SCHED_OTHER = 0,
SCHED_FIFO,
SCHED_RR,
SCHED_MIN = SCHED_OTHER,
SCHED_MAX = SCHED_RR
};
struct sched_param
{
int sched_priority;
int sched_priority;
};
#ifdef __cplusplus
File diff suppressed because it is too large. Load diff
+32 -8
View File
@@ -1,3 +1,27 @@
/*
* File : semaphore.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2010-10-26 Bernard the first version
*/
#ifndef __POSIX_SEMAPHORE_H__
#define __POSIX_SEMAPHORE_H__
@@ -6,16 +30,16 @@
struct posix_sem
{
/* reference count and unlinked */
rt_uint16_t refcount;
rt_uint8_t unlinked;
rt_uint8_t unamed;
/* reference count and unlinked */
rt_uint16_t refcount;
rt_uint8_t unlinked;
rt_uint8_t unamed;
/* RT-Thread semaphore */
rt_sem_t sem;
/* RT-Thread semaphore */
rt_sem_t sem;
/* next posix semaphore */
struct posix_sem* next;
/* next posix semaphore */
struct posix_sem* next;
};
typedef struct posix_sem sem_t;