support posix

1. posix pthread.h: pthread, pthread_barrier, pthread_cond, pthread_mutex, , pthread_rwlock, pthread_spin, etc
2. posix semaphore.h: sem_*
3. posix mqueue.h: mq_*
4. posix time.h: timer_*
5. to support posix, add tos_barrier, tos_bitmap, tos_rwlock, tos_stopwatch, change name of k_task_t from a char * pointer to a char array.
6. sample, see examples\posix
7. project, see board\TencentOS_tiny_EVB_MX_Plus\KEIL\posix
This commit is contained in:
daishengdong
2020-02-28 00:11:28 +08:00
parent 7bfc998494
commit 40f55ec57b
84 changed files with 11704 additions and 158 deletions

267
osal/posix/include/errno.h Normal file
View File

@@ -0,0 +1,267 @@
/*---------------------------------------------------------------------------- * Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_ERRNO_H_
#define _POSIX_ERRNO_H_
#define ENOERR 0
#define ENOERR_STR "No error."
#define E2BIG 1
#define E2BIG_STR "Argument list too long."
#define EACCES 2
#define EACCES_STR "Permission denied."
#define EADDRINUSE 3
#define EADDRINUSE_STR "Address in use."
#define EADDRNOTAVAIL 4
#define EADDRNOTAVAIL_STR "Address not available."
#define EAFNOSUPPORT 5
#define EAFNOSUPPORT_STR "Address family not supported."
#define EAGAIN 6
#define EAGAIN_STR "Resource unavailable, try again (may be the same value as [EWOULDBLOCK])."
#define EALREADY 7
#define EALREADY_STR "Connection already in progress."
#define EBADF 8
#define EBADF_STR "Bad file descriptor."
#define EBADMSG 9
#define EBADMSG_STR "Bad message."
#define EBUSY 10
#define EBUSY_STR "Device or resource busy."
#define ECANCELED 11
#define ECANCELED_STR "Operation canceled."
#define ECHILD 12
#define ECHILD_STR "No child processes."
#define ECONNABORTED 13
#define ECONNABORTED_STR "Connection aborted."
#define ECONNREFUSED 14
#define ECONNREFUSED_STR "Connection refused."
#define ECONNRESET 15
#define ECONNRESET_STR "Connection reset."
#define EDEADLK 16
#define EDEADLK_STR "Resource deadlock would occur."
#define EDESTADDRREQ 17
#define EDESTADDRREQ_STR "Destination address required."
#define EDOM 18
#define EDOM_STR "Mathematics argument out of domain of function."
#define EDQUOT 19
#define EDQUOT_STR "Reserved."
#define EEXIST 20
#define EEXIST_STR "File exists."
#define EFAULT 21
#define EFAULT_STR "Bad address."
#define EFBIG 22
#define EFBIG_STR "File too large."
#define EHOSTUNREACH 23
#define EHOSTUNREACH_STR "Host is unreachable."
#define EIDRM 24
#define EIDRM_STR "Identifier removed."
#define EILSEQ 25
#define EILSEQ_STR "Illegal byte sequence."
#define EINPROGRESS 26
#define EINPROGRESS_STR "Operation in progress."
#define EINTR 27
#define EINTR_STR "Interrupted function."
#define EINVAL 28
#define EINVAL_STR "Invalid argument."
#define EIO 29
#define EIO_STR "I/O error."
#define EISCONN 30
#define EISCONN_STR "Socket is connected."
#define EISDIR 31
#define EISDIR_STR "Is a directory."
#define ELOOP 32
#define ELOOP_STR "Too many levels of symbolic links."
#define EMFILE 33
#define EMFILE_STR "File descriptor value too large."
#define EMLINK 34
#define EMLINK_STR "Too many links."
#define EMSGSIZE 35
#define EMSGSIZE_STR "Message too large."
#define EMULTIHOP 36
#define EMULTIHOP_STR "Reserved."
#define ENAMETOOLONG 37
#define ENAMETOOLONG_STR "Filename too long."
#define ENETDOWN 38
#define ENETDOWN_STR "Network is down."
#define ENETRESET 39
#define ENETRESET_STR "Connection aborted by network."
#define ENETUNREACH 40
#define ENETUNREACH_STR "Network unreachable."
#define ENFILE 41
#define ENFILE_STR "Too many files open in system."
#define ENOBUFS 42
#define ENOBUFS_STR "No buffer space available."
#define ENODATA 43
#define ENODATA_STR "No message is available on the STREAM head read queue. "
#define ENODEV 44
#define ENODEV_STR "No such device."
#define ENOENT 45
#define ENOENT_STR "No such file or directory."
#define ENOEXEC 46
#define ENOEXEC_STR "Executable file format error."
#define ENOLCK 47
#define ENOLCK_STR "No locks available."
#define ENOLINK 48
#define ENOLINK_STR "Reserved."
#define ENOMEM 49
#define ENOMEM_STR "Not enough space."
#define ENOMSG 50
#define ENOMSG_STR "No message of the desired type."
#define ENOPROTOOPT 51
#define ENOPROTOOPT_STR "Protocol not available."
#define ENOSPC 52
#define ENOSPC_STR "No space left on device."
#define ENOSR 53
#define ENOSR_STR "No STREAM resources."
#define ENOSTR 54
#define ENOSTR_STR "Not a STREAM."
#define ENOSYS 55
#define ENOSYS_STR "Functionality not supported."
#define ENOTCONN 56
#define ENOTCONN_STR "The socket is not connected."
#define ENOTDIR 57
#define ENOTDIR_STR "Not a directory or a symbolic link to a directory."
#define ENOTEMPTY 58
#define ENOTEMPTY_STR "Directory not empty."
#define ENOTRECOVERABLE 59
#define ENOTRECOVERABLE_STR "State not recoverable."
#define ENOTSOCK 60
#define ENOTSOCK_STR "Not a socket."
#define ENOTSUP 61
#define ENOTSUP_STR "Not supported (may be the same value as [EOPNOTSUPP]). "
#define ENOTTY 62
#define ENOTTY_STR "Inappropriate I/O control operation."
#define ENXIO 63
#define ENXIO_STR "No such device or address."
#define EOPNOTSUPP 64
#define EOPNOTSUPP_STR "Operation not supported on socket (may be the same value as [ENOTSUP])."
#define EOVERFLOW 65
#define EOVERFLOW_STR "Value too large to be stored in data type."
#define EOWNERDEAD 66
#define EOWNERDEAD_STR "Previous owner died."
#define EPERM 67
#define EPERM_STR "Operation not permitted."
#define EPIPE 68
#define EPIPE_STR "Broken pipe."
#define EPROTO 69
#define EPROTO_STR "Protocol error."
#define EPROTONOSUPPORT 70
#define EPROTONOSUPPORT_STR "Protocol not supported."
#define EPROTOTYPE 71
#define EPROTOTYPE_STR "Protocol wrong type for socket."
#define ERANGE 72
#define ERANGE_STR "Result too large."
#define EROFS 73
#define EROFS_STR "Read-only file system."
#define ESPIPE 74
#define ESPIPE_STR "Invalid seek."
#define ESRCH 75
#define ESRCH_STR "No such process."
#define ESTALE 76
#define ESTALE_STR "Reserved."
#define ETIME 77
#define ETIME_STR "Stream ioctl() timeout."
#define ETIMEDOUT 78
#define ETIMEDOUT_STR "Connection timed out."
#define ETXTBSY 79
#define ETXTBSY_STR "Text file busy."
#define EWOULDBLOCK 80
#define EWOULDBLOCK_STR "Operation would block (may be the same value as [EAGAIN])."
#define EXDEV 81
#define EXDEV_STR "Cross-device link."
#endif /* _POSIX_ERRNO_H_ */

View File

@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_MQUEUE_H_
#define _POSIX_MQUEUE_H_
#include "tos_k.h"
#include "signal.h"
#include "time.h"
__CDECLS_BEGIN
typedef int 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 */
};
#define __NOTSUPP__
__API__ int mq_close(mqd_t mqdes);
__NOTSUPP__ int mq_getattr(mqd_t mqdes, struct mq_attr *mqstat);
__NOTSUPP__ int mq_notify(mqd_t mqdes, const struct sigevent *notification);
__API__ mqd_t mq_open(const char *name, int oflag, ...);
__API__ ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio);
__API__ int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio);
__NOTSUPP__ int mq_setattr(mqd_t mqdes, const struct mq_attr *mqstat, struct mq_attr *omqstat);
__API__ ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio, const struct timespec *abstime);
__NOTSUPP__ int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio, const struct timespec *abstime);
__NOTSUPP__ int mq_unlink(const char *name);
__CDECLS_END
#endif /* _POSIX_MQUEUE_H_ */

View File

@@ -0,0 +1,47 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_PRIVATE_MQUEUE_H_
#define _POSIX_PRIVATE_MQUEUE_H_
#include "tos_k.h"
#include "private/posix_config.h"
__CDECLS_BEGIN
#define MQUEUE_MAX (POSIX_CFG_MQUEUE_MAX)
#define MQUEUE_MSG_MAX 20
#define MQUEUE_MSG_SIZE_MAX 50
typedef struct mqueue_control_st {
mqd_t id;
k_prio_mail_q_t kprio_mail_q;
} mqueue_ctl_t;
__KNL__ int mqueue_id_add(mqd_t id, mqueue_ctl_t *mqueue_ctl);
__KNL__ mqd_t mqueue_id_alloc(void);
__KNL__ int mqueue_id_free(mqd_t id);
__KNL__ mqueue_ctl_t *mqueue_by_id(mqd_t id);
__CDECLS_END
#endif /* _POSIX_PRIVATE_TIMER_H_*/

View File

@@ -0,0 +1,48 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_CONFIG_H_
#define _POSIX_CONFIG_H_
#define POSIX_CFG_PTHREAD_THREADS_MAX 32
#define POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS 4
#define POSIX_CFG_PTHREAD_KEYS_MAX 8
#define POSIX_CFG_TIMERS_MAX 8
#define POSIX_CFG_MQUEUE_MAX 8
#define POSIX_CFG_PTHREAD_BARRIER_EN 1u
#define POSIX_CFG_PTHREAD_COND_EN 1u
#define POSIX_CFG_PTHREAD_MUTEX_EN 1u
#define POSIX_CFG_PTHREAD_RWLOCK_EN 1u
#define POSIX_CFG_PTHREAD_SPIN_EN 1u
#define POSIX_CFG_SEM_EN 1u
#define POSIX_CFG_MQUEUE_EN 1u
#define POSIX_CFG_TIMER_EN 1u
#include "private/posix_config_check.h"
#endif /* _POSIX_CONFIG_H_ */

View File

@@ -0,0 +1,61 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_CONFIG_CHECK_H_
#define _POSIX_CONFIG_CHECK_H_
#include "tos_config.h"
#include "private/posix_config_default.h"
#if (TOS_CFG_MMHEAP_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_MMHEAP_EN to use posix stuff"
#endif
#if (POSIX_CFG_PTHREAD_COND_EN > 0u) && (TOS_CFG_SEM_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_SEM_EN to use pthread_cond"
#endif
#if (POSIX_CFG_PTHREAD_COND_EN > 0u) && (TOS_CFG_MUTEX_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_MUTEX_EN to use pthread_cond"
#endif
#if (POSIX_CFG_PTHREAD_MUTEX_EN > 0u) && (TOS_CFG_MUTEX_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_MUTEX_EN to use pthread_mutex"
#endif
#if (POSIX_CFG_PTHREAD_RWLOCK_EN > 0u) && (TOS_CFG_SEM_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_SEM_EN to use pthread_rwlock"
#endif
#if (POSIX_CFG_PTHREAD_RWLOCK_EN > 0u) && (TOS_CFG_MUTEX_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_MUTEX_EN to use pthread_rwlock"
#endif
#if (POSIX_CFG_SEM_EN > 0u) && (TOS_CFG_SEM_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_SEM_EN to use posix sem"
#endif
#if (POSIX_CFG_MQUEUE_EN > 0u) && (TOS_CFG_PRIORITY_MAIL_QUEUE_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_PRIORITY_MAIL_QUEUE_EN to use posix mqueue"
#endif
#if (POSIX_CFG_TIMER_EN > 0u) && (TOS_CFG_TIMER_EN == 0u)
#error "INVALID config, Must enable TOS_CFG_TIMER_EN to use posix timer"
#endif
#endif /* _POSIX_CONFIG_CHECK_H_ */

View File

@@ -0,0 +1,74 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_CONFIG_DEFAULT_H_
#define _POSIX_CONFIG_DEFAULT_H_
#ifndef POSIX_CFG_PTHREAD_THREADS_MAX
#define POSIX_CFG_PTHREAD_THREADS_MAX 32
#endif
#ifndef POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS
#define POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS 4
#endif
#ifndef POSIX_CFG_PTHREAD_KEYS_MAX
#define POSIX_CFG_PTHREAD_KEYS_MAX 8
#endif
#ifndef POSIX_CFG_TIMERS_MAX
#define POSIX_CFG_TIMERS_MAX 8
#endif
#ifndef POSIX_CFG_MQUEUE_MAX
#define POSIX_CFG_MQUEUE_MAX 8
#endif
#ifndef POSIX_CFG_PTHREAD_BARRIER_EN
#define POSIX_CFG_PTHREAD_BARRIER_EN 1u
#endif
#ifndef POSIX_CFG_PTHREAD_COND_EN
#define POSIX_CFG_PTHREAD_COND_EN 1u
#endif
#ifndef POSIX_CFG_PTHREAD_MUTEX_EN
#define POSIX_CFG_PTHREAD_MUTEX_EN 1u
#endif
#ifndef POSIX_CFG_PTHREAD_RWLOCK_EN
#define POSIX_CFG_PTHREAD_RWLOCK_EN 1u
#endif
#ifndef POSIX_CFG_PTHREAD_SPIN_EN
#define POSIX_CFG_PTHREAD_SPIN_EN 1u
#endif
#ifndef POSIX_CFG_SEM_EN
#define POSIX_CFG_SEM_EN 1u
#endif
#ifndef POSIX_CFG_MQUEUE_EN
#define POSIX_CFG_MQUEUE_EN 1u
#endif
#ifndef POSIX_CFG_TIMER_EN
#define POSIX_CFG_TIMER_EN 1u
#endif
#endif /* _POSIX_CONFIG_DEFAULT_H_ */

View File

@@ -0,0 +1,119 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_PRIVATE_PTHREAD_H_
#define _POSIX_PRIVATE_PTHREAD_H_
#include "tos_k.h"
#include "private/posix_config.h"
#include "sys/types.h"
__CDECLS_BEGIN
typedef struct pthread_control_st {
uint16_t threadstate : 4;
uint16_t cancelstate : 2;
uint16_t canceltype : 2;
uint16_t cancelpending : 1;
pthread_t id;
pthread_attr_t attr;
k_task_t ktask;
k_task_t *the_ktask;
k_sem_t joinner_sem;
void *(*start_routine)(void *); /* start routine of the pthread */
void *arg; /* argument to start routine */
void *retval; /* return value of start routine */
void *stackaddr; /* memory of address */
k_slist_t cleanup_ctl_list;
void **thread_data;
} pthread_ctl_t;
typedef struct pthread_cleanup_control_st {
void (*routine)(void *); /* function to be called */
void *arg; /* argument for the routine */
k_slist_t list;
} pthread_cleanup_ctl_t;
#define PTHREAD_KEYS_MAX (POSIX_CFG_PTHREAD_KEYS_MAX)
typedef void (*key_destructor_t)(void*);
typedef struct pthread_key_control_st {
k_bmtbl_t key_bitmap_tbl[TOS_BITMAP_SIZE(PTHREAD_KEYS_MAX)];
k_bitmap_t key_bitmap;
key_destructor_t destructors[PTHREAD_KEYS_MAX];
} pthread_key_ctl_t;
#define PTHREAD_INFO_SIZE (sizeof(pthread_ctl_t))
#define PTHREAD_STK_SIZE_MIN (K_TASK_STK_SIZE_MIN + PTHREAD_INFO_SIZE)
#define PTHREAD_DEFAULT_TIMESLICE 20
#define PTHREAD_DEFAULT_STACKSIZE (2048 + PTHREAD_INFO_SIZE)
#define PTHREAD_DEFAULT_INHERIT_SCHED PTHREAD_INHERIT_SCHED
#define PTHREAD_DEFAULT_SCHEDPOLICY SCHED_OTHER
#define PTHREAD_DEFAULT_PRIORITY (TOS_CFG_TASK_PRIO_MAX / 2)
#define PTHREAD_DEFAULT_DETACH_STATE PTHREAD_CREATE_JOINABLE
#define PTHREAD_DESTRUCTOR_ITERATIONS (POSIX_CFG_PTHREAD_DESTRUCTOR_ITERATIONS)
#define PTHREAD_THREADS_MAX (POSIX_CFG_PTHREAD_THREADS_MAX)
__KNL__
pthread_ctl_t *pthread_ctl_self(void);
__KNL__ pthread_ctl_t *pthread_ctl_by_id(pthread_t id);
__KNL__ int pthread_id_add(pthread_t id, pthread_ctl_t *info);
__KNL__ pthread_t pthread_id_alloc(void);
__KNL__ int pthread_id_free(pthread_t id);
__KNL__ void pthread_data_clear(pthread_key_t key);
__KNL__ int pthread_key_ctl_init(void);
__KNL__ pthread_key_t pthread_key_alloc(void);
__KNL__ int pthread_key_is_alloc(pthread_key_t key);
__KNL__ int pthread_key_free(pthread_key_t key);
__KNL__ int pthread_key_destructor_register(pthread_key_t key, key_destructor_t destructor);
__KNL__ key_destructor_t pthread_key_destructor_get(pthread_key_t key);
__KNL__ int pthread_ctl_reap(int pthreads_ready2reap);
__KNL__ void pthread_lock(void);
__KNL__ void pthread_unlock(void);
__KNL__ int pthread_lock_init(void);
__KNL__ int pthread_init(void);
__CDECLS_END
#endif /* _POSIX_PRIVATE_PTHREAD_PRV_H_ */

View File

@@ -0,0 +1,36 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_PRIVATE_TIME_H_
#define _POSIX_PRIVATE_TIME_H_
#include "tos_k.h"
__CDECLS_BEGIN
#define MILLISECOND_PER_SECOND 1000UL
#define MICROSECOND_PER_SECOND 1000000UL
#define NANOSECOND_PER_SECOND 1000000000UL
__KNL__ k_tick_t timespec_to_ktick(const struct timespec *tp);
__KNL__ void ktick_to_timespec(k_tick_t ktick, struct timespec *tp);
__CDECLS_END
#endif /* _POSIX_PRIVATE_TIME_H_ */

View File

@@ -0,0 +1,50 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_PRIVATE_TIMER_H_
#define _POSIX_PRIVATE_TIMER_H_
#include "tos_k.h"
#include "private/posix_config.h"
#include "signal.h"
__CDECLS_BEGIN
#define TIMERS_MAX (POSIX_CFG_TIMERS_MAX)
typedef struct ptimer_control_st {
timer_t id;
k_timer_t ktimer;
void (*sigev_notify_function)(union sigval);
union sigval sigev_value;
} ptimer_ctl_t;
__KNL__ int timer_id_add(timer_t id, ptimer_ctl_t *ptimer_ctl);
__KNL__ timer_t timer_id_alloc(void);
__KNL__ int timer_id_free(timer_t id);
__KNL__ ptimer_ctl_t *timer_by_id(timer_t id);
__CDECLS_END
#endif /* _POSIX_PRIVATE_TIMER_H_*/

View File

@@ -0,0 +1,189 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_PTHREAD_H_
#define _POSIX_PTHREAD_H_
#include "tos_k.h"
#include "stddef.h"
#include "limits.h"
#include "sys/types.h"
#include "sched.h"
#include "time.h"
__CDECLS_BEGIN
extern int __pthread_canceled;
#define PTHREAD_CANCELD ((void *)(&__pthread_canceled))
/* type of mutex */
#define PTHREAD_MUTEX_NORMAL 0
#define PTHREAD_MUTEX_ERRORCHECK 1
#define PTHREAD_MUTEX_RECURSIVE 2
#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
/* state of the thread */
#define PTHREAD_STATE_DETACHED 1 /* The thread is running but detached */
#define PTHREAD_STATE_RUNNING 2 /* The thread is running and will wait to join when it exits */
#define PTHREAD_STATE_JOIN 3 /* The thread has exited and is waiting to be joined */
#define PTHREAD_STATE_EXITED 4 /* The thread has exited and is ready to be reaped */
/* cancelability state */
#define PTHREAD_CANCEL_ENABLE 1
#define PTHREAD_CANCEL_DISABLE 2
/* cancelability type */
#define PTHREAD_CANCEL_ASYNCHRONOUS 1
#define PTHREAD_CANCEL_DEFERRED 2
/* values for detachstate*/
#define PTHREAD_CREATE_JOINABLE 1
#define PTHREAD_CREATE_DETACHED 2
/* values for inheritsched */
#define PTHREAD_INHERIT_SCHED 1
#define PTHREAD_EXPLICIT_SCHED 2
#define PTHREAD_ONCE_INIT 0
#define PTHREAD_COND_INITIALIZER
#define PTHREAD_MUTEX_INITIALIZER
#define PTHREAD_RWLOCK_INITIALIZER
#define __NOTSUPP__
__NOTSUPP__ int pthread_atfork(void (*prepare)(void), void (*parent)(void), void(*child)(void));
__API__ int pthread_attr_destroy(pthread_attr_t *attr);
__API__ int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
__NOTSUPP__ int pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize);
__API__ int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched);
__API__ int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param);
__API__ int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy);
__NOTSUPP__ int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope);
__API__ int pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize);
__API__ int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);
__API__ int pthread_attr_init(pthread_attr_t *attr);
__API__ int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
__NOTSUPP__ int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
__API__ int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);
__API__ int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param);
__API__ int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
__NOTSUPP__ int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope);
__API__ int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize);
__API__ int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
__API__ int pthread_barrier_destroy(pthread_barrier_t *barrier);
__API__ int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count);
__API__ int pthread_barrier_wait(pthread_barrier_t *barrier);
__NOTSUPP__ int pthread_barrierattr_destroy(pthread_barrierattr_t *attr);
__NOTSUPP__ int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, int *pshared);
__NOTSUPP__ int pthread_barrierattr_init(pthread_barrierattr_t *attr);
__NOTSUPP__ int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int pshared);
__API__ int pthread_cancel(pthread_t thread);
__API__ int pthread_cond_broadcast(pthread_cond_t *cond);
__API__ int pthread_cond_destroy(pthread_cond_t *cond);
__API__ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
__API__ int pthread_cond_signal(pthread_cond_t *cond);
__API__ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime);
__API__ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
__NOTSUPP__ int pthread_condattr_destroy(pthread_condattr_t *attr);
__NOTSUPP__ int pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock_id);
__NOTSUPP__ int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared);
__NOTSUPP__ int pthread_condattr_init(pthread_condattr_t *attr);
__NOTSUPP__ int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id);
__NOTSUPP__ int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
__API__ int pthread_create(pthread_t *pthread, const pthread_attr_t *attr, void *(*entry)(void*), void *arg);
__API__ int pthread_detach(pthread_t thread);
__API__ int pthread_equal(pthread_t t1, pthread_t t2);
__API__ void pthread_exit(void *value_ptr);
__NOTSUPP__ int pthread_getconcurrency(void);
__NOTSUPP__ int pthread_getcpuclockid(pthread_t thread_id, clockid_t *clock_id);
__API__ int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param);
__API__ void *pthread_getspecific(pthread_key_t key);
__API__ int pthread_join(pthread_t thread, void **value_ptr);
__API__ int pthread_key_create(pthread_key_t *, void (*)(void*));
__API__ int pthread_key_delete(pthread_key_t);
__NOTSUPP__ int pthread_mutex_consistent(pthread_mutex_t *mutex);
__API__ int pthread_mutex_destroy(pthread_mutex_t *mutex);
__NOTSUPP__ int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex, int *prioceiling);
__API__ int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
__API__ int pthread_mutex_lock(pthread_mutex_t *mutex);
__NOTSUPP__ int pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int prioceiling, int *old_ceiling);
__API__ int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime);
__API__ int pthread_mutex_trylock(pthread_mutex_t *mutex);
__API__ int pthread_mutex_unlock(pthread_mutex_t *mutex);
__API__ int pthread_mutexattr_destroy(pthread_mutexattr_t *);
__NOTSUPP__ int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *mutex, int *prioceiling);
__NOTSUPP__ int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *mutex, int *protocol);
__NOTSUPP__ int pthread_mutexattr_getpshared(const pthread_mutexattr_t *mutex, int *pshared);
__NOTSUPP__ int pthread_mutexattr_getrobust(const pthread_mutexattr_t *mutex, int *robust);
__API__ int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type);
__API__ int pthread_mutexattr_init(pthread_mutexattr_t *attr);
__NOTSUPP__ int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mutex, int prioceiling);
__NOTSUPP__ int pthread_mutexattr_setprotocol(pthread_mutexattr_t *mutex, int protocol);
__NOTSUPP__ int pthread_mutexattr_setpshared(pthread_mutexattr_t *mutex, int pshared);
__NOTSUPP__ int pthread_mutexattr_setrobust(pthread_mutexattr_t *mutex, int robust);
__API__ int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
__API__ int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
__API__ int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
__API__ int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr);
__API__ int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
__API__ int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abstime);
__API__ int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime);
__API__ int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
__API__ int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
__API__ int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
__API__ int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
__NOTSUPP__ int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
__NOTSUPP__ int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared);
__NOTSUPP__ int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
__NOTSUPP__ int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared);
__API__ pthread_t pthread_self(void);
__API__ int pthread_setcancelstate(int state, int *oldstate);
__API__ int pthread_setcanceltype(int type, int *oldtype);
__NOTSUPP__ int pthread_setconcurrency(int new_level);
__API__ int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param);
__API__ int pthread_setschedprio(pthread_t, int);
__API__ int pthread_setspecific(pthread_key_t key, const void *value);
__API__ int pthread_spin_destroy(pthread_spinlock_t *lock);
__API__ int pthread_spin_init(pthread_spinlock_t *lock, int pshared);
__API__ int pthread_spin_lock(pthread_spinlock_t *lock);
__API__ int pthread_spin_trylock(pthread_spinlock_t *lock);
__API__ int pthread_spin_unlock(pthread_spinlock_t *lock);
__API__ void pthread_testcancel(void);
__API__ void pthread_cleanup_pop(int execute);
__API__ void pthread_cleanup_push(void (*routine)(void*), void *arg);
__CDECLS_END
#endif /* _POSIX_PTHREAD_H_ */

View File

@@ -0,0 +1,47 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_SCHED_H_
#define _POSIX_SCHED_H_
#include "tos_k.h"
#include "sys/types.h"
#include "time.h"
__CDECLS_BEGIN
/* Scheduling Psolicies, values for schedpolicy */
#define SCHED_FIFO 0 /* First in-first out (FIFO) scheduling policy. */
#define SCHED_RR 1 /* Round robin scheduling policy. */
#define SCHED_OTHER 2 /* Another scheduling policy. */
#define __NOTSUPP__
__API__ int sched_get_priority_max(int policy);
__API__ int sched_get_priority_min(int policy);
__API__ int sched_getparam(pid_t pid, struct sched_param *param);
__NOTSUPP__ int sched_getscheduler(pid_t pid);
__API__ int sched_rr_get_interval(pid_t pid, struct timespec *interval);
__API__ int sched_setparam(pid_t pid, const struct sched_param *param);
__NOTSUPP__ int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param);
__API__ int sched_yield(void);
__CDECLS_END
#endif /* _POSIX_SCHED_H_ */

View File

@@ -0,0 +1,45 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_SEMAPHORE_H_
#define _POSIX_SEMAPHORE_H_
#include "tos_k.h"
#include "time.h"
__CDECLS_BEGIN
typedef k_sem_t sem_t;
#define __NOTSUPP__
__NOTSUPP__ int sem_close(sem_t *sem);
__API__ int sem_destroy(sem_t *sem);
__API__ int sem_getvalue(sem_t *sem, int *sval);
__API__ int sem_init(sem_t *sem, int pshared, unsigned value);
__NOTSUPP__ sem_t *sem_open(const char *name, int oflag, ...);
__API__ int sem_post(sem_t *sem);
__API__ int sem_timedwait(sem_t *sem, const struct timespec *abstime);
__API__ int sem_trywait(sem_t *sem);
__NOTSUPP__ int sem_unlink(const char *name);
__API__ int sem_wait(sem_t *sem);
__CDECLS_END
#endif /* _POSIX_SEMAPHORE_H_ */

View File

@@ -0,0 +1,37 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_SIGNAL_H_
#define _POSIX_SIGNAL_H_
#include "sys/types.h"
union sigval {
int sival_int; /* integer signal value */
void *sival_ptr; /* pointer signal value */
};
struct sigevent {
int sigev_notify; /* notification type */
int sigev_signo; /* signal number */
union sigval sigev_value; /* signal value */
void (*sigev_notify_function)(union sigval); /* notification function */
pthread_attr_t *sigev_notify_attributes; /* notification attributes */
};
#endif /* _POSIX_SIGNAL_H_ */

View File

@@ -0,0 +1,62 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_SYS_TIME_H_
#define _POSIX_SYS_TIME_H_
#include "sys/types.h"
#include "time.h"
__CDECLS_BEGIN
struct timeval {
long tv_sec;
long tv_usec;
};
struct itimerval {
struct timeval it_interval; /* timer interval */
struct timeval it_value; /* current value */
};
#define TIMEVAL_TO_TIMESPEC(tv, ts) { \
(ts)->tv_sec = (tv)->tv_sec; \
(ts)->tv_nsec = (tv)->tv_usec * 1000; \
}
#define TIMESPEC_TO_TIMEVAL(tv, ts) { \
(tv)->tv_sec = (ts)->tv_sec; \
(tv)->tv_usec = (ts)->tv_nsec / 1000; \
}
struct timezone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of dst correction */
};
__API__ int getitimer(int which, struct itimerval *value);
__API__ int gettimeofday(struct timeval *tp, void *tzp);
__API__ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue);
#if 0
int select(int, fd_set *restrict, fd_set *restrict, fd_set *restrict, struct timeval *restrict);
#endif
__API__ int utimes(const char *path, const struct timeval [2]);
__CDECLS_END
#endif /* _POSIX_SYS_TIME_H_ */

View File

@@ -0,0 +1,131 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_SYS_TYPES_H_
#define _POSIX_SYS_TYPES_H_
#include "stddef.h"
#include "stdint.h"
typedef uint32_t blkcnt_t; /* Used for file block counts. */
typedef size_t blksize_t; /* Used for block sizes. */
typedef uint64_t clock_t; /* Used for system times in clock ticks or CLOCKS_PER_SEC; see <time.h>. */
typedef uint32_t clockid_t; /* Used for clock ID type in the clock and timer functions. */
typedef uint32_t dev_t; /* Used for device IDs. */
typedef uint32_t fsblkcnt_t; /* Used for file system block counts. */
typedef uint32_t fsfilcnt_t; /* Used for file system file counts. */
typedef uint32_t gid_t; /* Used for group IDs. */
typedef uint32_t id_t; /* Used as a general identifier; can be used to contain at least a pid_t, uid_t, or gid_t. */
typedef uint32_t ino_t; /* Used for file serial numbers. */
typedef uint32_t key_t; /* Used for XSI interprocess communication. */
typedef uint32_t mode_t; /* Used for some file attributes. */
typedef uint32_t nlink_t; /* Used for link counts. */
typedef uint32_t off_t; /* Used for file sizes. */
typedef int pid_t; /* Used for process IDs and process group IDs. */
typedef uint32_t uid_t; /* Used for user IDs. */
#if 0 /* we donnot typedef a size_t or ssize_t here, use what is supplied by stddef.h */
size_t /* Used for sizes of objects. */
ssize_t /* Used for a count of bytes or an error indication. */
#endif
typedef int ssize_t;
typedef uint32_t suseconds_t; /* Used for time in microseconds. */
typedef uint32_t time_t; /* Used for time in seconds. */
struct sched_param {
int sched_priority; /* Process or thread execution scheduling priority. */
};
/* Used to identify a thread attribute object. */
typedef struct pthread_attr_st {
uint32_t detachstate : 2;
uint32_t inheritsched : 2; /* inherit parent priority/policy? */
uint32_t schedpolicy : 2; /* pthread scheduler policy */
uint32_t stackaddr_valid : 1;
uint32_t stacksize_valid : 1;
struct sched_param schedparam;
void *stackaddr; /* address of memory to be used as stack */
size_t stacksize; /* size of the stack allocated for the pthread */
} pthread_attr_t;
/* Used to identify a barrier. */
typedef k_barrier_t pthread_barrier_t;
/* Used to define a barrier attributes object. */
typedef uint32_t pthread_barrierattr_t;
/* Used for condition variables. */
typedef k_sem_t pthread_cond_t;
/* Used to identify a condition attribute object. */
typedef int pthread_condattr_t;
/* Used for thread-specific data keys. */
typedef int pthread_key_t;
/* Used to identify a mutex attribute object. */
typedef struct pthread_mutexattr_st {
uint8_t type : 4;
uint8_t reserved : 4;
} pthread_mutexattr_t;
/* Used for mutexes. */
typedef struct pthread_mutex_st {
k_mutex_t kmutex;
pthread_mutexattr_t attr;
} pthread_mutex_t;
/* Used for dynamic package initialization. */
typedef int pthread_once_t;
/* Used for read-write locks. */
typedef k_rwlock_t pthread_rwlock_t;
/* Used for read-write lock attributes. */
typedef int pthread_rwlockattr_t;
/* Used to identify a spin lock. */
typedef struct pthread_spinlock_st {
uint8_t is_destroyed : 1;
uint8_t is_locked : 1;
} pthread_spinlock_t;
/* Used to identify a thread. */
typedef pid_t pthread_t;
/* Used for timer ID returned by timer_create(). */
typedef int timer_t;
/* Used to identify a trace stream attributes object */
typedef int trace_attr_t;
/* Used to identify a trace event type. */
typedef int trace_event_id_t;
/* Used to identify a trace event type set. */
typedef int trace_event_set_t;
/* Used to identify a trace stream. */
typedef int trace_id_t;
#endif /* _POSIX_SYS_TYPES_H_ */

87
osal/posix/include/time.h Normal file
View File

@@ -0,0 +1,87 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _POSIX_TIME_H_
#define _POSIX_TIME_H_
#include "tos_k.h"
#include "sys/types.h"
#include "signal.h"
__CDECLS_BEGIN
struct tm {
int tm_sec; /* Seconds [0,60] */
int tm_min; /* Minutes [0,59] */
int tm_hour; /* Hour [0,23] */
int tm_mday; /* Day of month [1,31] */
int tm_mon; /* Month of year [0,11] */
int tm_year; /* Years since 1900 */
int tm_wday; /* Day of week [0,6] (Sunday =0) */
int tm_yday; /* Day of year [0,365] */
};
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
struct itimerspec {
struct timespec it_interval; /* timer period */
struct timespec it_value; /* timer expiration */
};
#define CLOCK_REALTIME 0
#define __NOTSUPP__
__API__ char *asctime(const struct tm *timeptr);
__API__ char *asctime_r(const struct tm *asctime_r, char *buf);
__API__ clock_t clock(void);
__API__ int clock_getcpuclockid(pid_t pid, clockid_t *clock_id);
__API__ int clock_getres(clockid_t clock_id, struct timespec *res);
__API__ int clock_gettime(clockid_t clock_id, struct timespec *tp);
__API__ int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp);
__API__ int clock_settime(clockid_t clock_id, const struct timespec *tp);
__API__ char *ctime(const time_t *clock);
__API__ char *ctime_r(const time_t *clock, char *buf);
__API__ double difftime(time_t time1, time_t time0);
__API__ struct tm *getdate(const char *string);
__API__ struct tm *gmtime(const time_t *timer);
__API__ struct tm *gmtime_r(const time_t *timer, struct tm *result);
__API__ struct tm *localtime(const time_t *timer);
__API__ struct tm *localtime_r(const time_t *timer, struct tm *result);
__API__ time_t mktime(struct tm *timeptr);
__API__ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
__API__ size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr);
#if 0
__API__ size_t strftime_l(char *s, size_t maxsize, const char *format, const struct tm *timeptr, locale_t locale);
#endif
__API__ char *strptime(const char *buf, const char *format, struct tm *tm);
__API__ time_t time(time_t *tloc);
__API__ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid);
__API__ int timer_delete(timer_t timerid);
__NOTSUPP__ int timer_getoverrun(timer_t timerid);
__API__ int timer_gettime(timer_t timerid, struct itimerspec *value);
__API__ int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue);
__API__ void tzset(void);
__CDECLS_END
#endif /* _POSIX_TIME_H_ */

View File

@@ -0,0 +1,30 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _TOS_POSIX_H_
#define _TOS_POSIX_H_
#include "tos_k.h"
__CDECLS_BEGIN
__API__ int tos_posix_init(void);
__CDECLS_END
#endif /* _TOS_POSIX_H_ */