未验证 提交 8fc6d453 编写于 作者: O openharmony_ci 提交者: Gitee

!1551 posix、cmsis和kernel相关对外接口文档更新

Merge pull request !1551 from LiteOS/master
......@@ -52,7 +52,7 @@ Hi3516开源板使用FAT文件系统,不允许该操作。
### LiteOS内核已支持哪几款芯片架构<a name="section1131661465417"></a>
LiteOS-M已支持risc-v、Cortex-m3\\m4\\m7\\m33、arm9,待支持c-sky、xtensa;LiteOS-A已支持armv7-a,待支持armv8-a,请关注开源社区更新。
LiteOS-M已支持risc-v、Cortex-m3\\m4\\m7\\m33、arm9c-sky、xtensa;LiteOS-A已支持armv7-a,待支持armv8-a,请关注开源社区更新。
## 三方组件<a name="section971818231178"></a>
......
......@@ -29,12 +29,15 @@ OpenHarmony LiteOS-M内核的时间管理提供下面几种功能,接口详细
| 功能分类 | 接口名 | 描述 |
| -------- | -------- | -------- |
| 时间转换 | LOS_MS2Tick | 毫秒转换成Tick |
| LOS_Tick2MS | Tick转化为毫秒 |
| OsCpuTick2MS | Cycle数目转化为毫秒,使用2个UINT32类型的数值分别表示结果数值的高、低32位。 |
| OsCpuTick2US | Cycle数目转化为微秒,使用2个UINT32类型的数值分别表示结果数值的高、低32位。 |
| | LOS_Tick2MS | Tick转化为毫秒 |
| | OsCpuTick2MS | Cycle数目转化为毫秒,使用2个UINT32类型的数值分别表示结果数值的高、低32位。 |
| | OsCpuTick2US | Cycle数目转化为微秒,使用2个UINT32类型的数值分别表示结果数值的高、低32位。 |
| 时间统计 | LOS_SysClockGet | 获取系统时钟 |
| LOS_TickCountGet | 获取自系统启动以来的Tick数 |
| LOS_CyclePerTickGet | 获取每个Tick多少Cycle数 |
| | LOS_TickCountGet | 获取自系统启动以来的Tick数 |
| | LOS_CyclePerTickGet | 获取每个Tick多少Cycle数 |
| | LOS_CurrNanosec |获取自系统启动以来的纳秒数|
| 延时管理 | LOS_UDelay |以us为单位的忙等,但可以被优先级更高的任务抢占|
| | LOS_MDelay |以ms为单位的忙等,但可以被优先级更高的任务抢占|
## 开发流程
......
......@@ -20,88 +20,88 @@ CMSIS-RTOS v2提供下面几种功能,接口详细信息可以查看API参考
**表1** CMSIS-RTOS v2接口
| 功能分类 | 接口名 | 描述 |
| 功能分类 | 接口名 | 描述 |
| -------- | -------- | -------- |
| 内核信息与控制 | osKernelGetInfo | 获取RTOS内核信息。 |
| osKernelGetState | 获取当前的RTOS内核状态。 |
| osKernelGetSysTimerCount | 获取RTOS内核系统计时器计数。 |
| osKernelGetSysTimerFreq | 获取RTOS内核系统计时器频率。 |
| osKernelInitialize | 初始化RTOS内核。 |
| osKernelLock | 锁定RTOS内核调度程序。 |
| osKernelUnlock | 解锁RTOS内核调度程序。 |
| osKernelRestoreLock | 恢复RTOS内核调度程序锁定状态。 |
| osKernelResume | 恢复RTOS内核调度程序。(暂未实现) |
| osKernelStart | 启动RTOS内核调度程序。 |
| osKernelSuspend | 挂起RTOS内核调度程序。(暂未实现) |
| osKernelGetTickCount | 获取RTOS内核滴答计数。 |
| osKernelGetTickFreq | 获取RTOS内核滴答频率。 |
| 线程管理 | osThreadDetach | 分离线程(线程终止时可以回收线程存储)。(暂未实现) |
| osThreadEnumerate | 枚举活动线程。(暂未实现) |
| osThreadExit | 终止当前正在运行的线程的执行。 |
| osThreadGetCount | 获取活动线程的数量。 |
| osThreadGetId | 返回当前正在运行的线程的线程ID。 |
| osThreadGetName | 获取线程的名称。 |
| osThreadGetPriority | 获取线程的当前优先级。 |
| osThreadGetStackSize | 获取线程的堆栈大小。 |
| osThreadGetStackSpace | 根据执行期间的堆栈水印记录获取线程的可用堆栈空间。 |
| osThreadGetState | 获取线程的当前线程状态。 |
| osThreadJoin | 等待指定线程终止。(暂未实现) |
| osThreadNew | 创建一个线程并将其添加到活动线程中。 |
| osThreadResume | 恢复线程的执行。 |
| osThreadSetPriority | 更改线程的优先级。 |
| osThreadSuspend | 暂停执行线程。 |
| osThreadTerminate | 终止线程的执行。 |
| osThreadYield | 将控制权传递给处于就绪状态的下一个线程。 |
| 线程标志 | osThreadFlagsSet | 设置线程的指定线程标志。(暂未实现) |
| osThreadFlagsClear | 清除当前正在运行的线程的指定线程标志。(暂未实现) |
| osThreadFlagsGet | 获取当前正在运行的线程的当前线程标志。(暂未实现) |
| osThreadFlagsWait | 等待当前正在运行的线程的一个或多个线程标志发出信号。(暂未实现) |
| 事件标志 | osEventFlagsGetName | 获取事件标志对象的名称。(暂未实现) |
| osEventFlagsNew | 创建并初始化事件标志对象。 |
| osEventFlagsDelete | 删除事件标志对象。 |
| osEventFlagsSet | 设置指定的事件标志。 |
| osEventFlagsClear | 清除指定的事件标志。 |
| osEventFlagsGet | 获取当前事件标志。 |
| osEventFlagsWait | 等待一个或多个事件标志被发出信号。 |
| 通用等待函数 | osDelay | 等待超时(时间延迟)。 |
| osDelayUntil | 等到指定时间。 |
| 计时器管理 | osTimerDelete | 删除计时器。 |
| osTimerGetName | 获取计时器的名称。(暂未实现) |
| osTimerIsRunning | 检查计时器是否正在运行。 |
| osTimerNew | 创建和初始化计时器。 |
| osTimerStart | 启动或重新启动计时器。 |
| osTimerStop | 停止计时器。 |
| 互斥管理 | osMutexAcquire | 获取互斥或超时(如果已锁定)。 |
| osMutexDelete | 删除互斥对象。 |
| osMutexGetName | 获取互斥对象的名称。(暂未实现) |
| osMutexGetOwner | 获取拥有互斥对象的线程。 |
| osMutexNew | 创建并初始化Mutex对象。 |
| osMutexRelease | 释放由osMutexAcquire获取的Mutex。 |
| 信号量 | osSemaphoreAcquire | 获取信号量令牌或超时(如果没有可用的令牌)。 |
| osSemaphoreDelete | 删除一个信号量对象。 |
| osSemaphoreGetCount | 获取当前信号量令牌计数。 |
| osSemaphoreGetName | 获取信号量对象的名称。(暂未实现) |
| osSemaphoreNew | 创建并初始化一个信号量对象。 |
| osSemaphoreRelease | 释放信号量令牌,直到初始最大计数。 |
| 内存池 | osMemoryPoolAlloc | 从内存池分配一个内存块。 |
| osMemoryPoolDelete | 删除内存池对象。 |
| osMemoryPoolFree | 将分配的内存块返回到内存池。 |
| osMemoryPoolGetBlockSize | 获取内存池中的内存块大小。 |
| osMemoryPoolGetCapacity | 获取内存池中最大的内存块数。 |
| osMemoryPoolGetCount | 获取内存池中使用的内存块数。 |
| osMemoryPoolGetName | 获取内存池对象的名称。 |
| osMemoryPoolGetSpace | 获取内存池中可用的内存块数。 |
| osMemoryPoolNew | 创建并初始化一个内存池对象。 |
| 消息队列 | osMessageQueueDelete | 删除消息队列对象。 |
| osMessageQueueGet | 从队列获取消息,或者如果队列为空,则从超时获取消息。 |
| osMessageQueueGetCapacity | 获取消息队列中的最大消息数。 |
| osMessageQueueGetCount | 获取消息队列中排队的消息数。 |
| osMessageQueueGetMsgSize | 获取内存池中的最大消息大小。 |
| osMessageQueueGetName | 获取消息队列对象的名称。(暂未实现) |
| osMessageQueueGetSpace | 获取消息队列中消息的可用插槽数。 |
| osMessageQueueNew | 创建和初始化消息队列对象。 |
| osMessageQueuePut | 如果队列已满,则将消息放入队列或超时。 |
| osMessageQueueReset | 将消息队列重置为初始空状态。(暂未实现) |
| 内核信息与控制 | osKernelGetInfo | 获取RTOS内核信息。 |
| | osKernelGetState | 获取当前的RTOS内核状态。 |
| | osKernelGetSysTimerCount | 获取RTOS内核系统计时器计数。 |
| | osKernelGetSysTimerFreq | 获取RTOS内核系统计时器频率。 |
| | osKernelInitialize | 初始化RTOS内核。 |
| | osKernelLock | 锁定RTOS内核调度程序。 |
| | osKernelUnlock | 解锁RTOS内核调度程序。 |
| | osKernelRestoreLock | 恢复RTOS内核调度程序锁定状态。 |
| | osKernelResume | 恢复RTOS内核调度程序。(暂未实现) |
| | osKernelStart | 启动RTOS内核调度程序。 |
| | osKernelSuspend | 挂起RTOS内核调度程序。(暂未实现) |
| | osKernelGetTickCount | 获取RTOS内核滴答计数。 |
| | osKernelGetTickFreq | 获取RTOS内核滴答频率。 |
| 线程管理 | osThreadDetach | 分离线程(线程终止时可以回收线程存储)。 |
| | osThreadEnumerate | 枚举活动线程。(暂未实现) |
| | osThreadExit | 终止当前正在运行的线程的执行。 |
| | osThreadGetCount | 获取活动线程的数量。 |
| | osThreadGetId | 返回当前正在运行的线程的线程ID。 |
| | osThreadGetName | 获取线程的名称。 |
| | osThreadGetPriority | 获取线程的当前优先级。 |
| | osThreadGetStackSize | 获取线程的堆栈大小。 |
| | osThreadGetStackSpace | 根据执行期间的堆栈水印记录获取线程的可用堆栈空间。 |
| | osThreadGetState | 获取线程的当前线程状态。 |
| | osThreadJoin | 等待指定线程终止。 |
| | osThreadNew | 创建一个线程并将其添加到活动线程中。 |
| | osThreadResume | 恢复线程的执行。 |
| | osThreadSetPriority | 更改线程的优先级。 |
| | osThreadSuspend | 暂停执行线程。 |
| | osThreadTerminate | 终止线程的执行。 |
| | osThreadYield | 将控制权传递给处于就绪状态的下一个线程。 |
| 线程标志 | osThreadFlagsSet | 设置线程的指定线程标志。 |
| | osThreadFlagsClear | 清除当前正在运行的线程的指定线程标志。 |
| | osThreadFlagsGet | 获取当前正在运行的线程的当前线程标志。 |
| | osThreadFlagsWait | 等待当前正在运行的线程的一个或多个线程标志发出信号。 |
| 事件标志 | osEventFlagsGetName | 获取事件标志对象的名称。(暂未实现) |
| | osEventFlagsNew | 创建并初始化事件标志对象。 |
| | osEventFlagsDelete | 删除事件标志对象。 |
| | osEventFlagsSet | 设置指定的事件标志。 |
| | osEventFlagsClear | 清除指定的事件标志。 |
| | osEventFlagsGet | 获取当前事件标志。 |
| | osEventFlagsWait | 等待一个或多个事件标志被发出信号。 |
| 通用等待函数 | osDelay | 等待超时(时间延迟)。 |
| | osDelayUntil | 等到指定时间。 |
| 计时器管理 | osTimerDelete | 删除计时器。 |
| | osTimerGetName | 获取计时器的名称。(暂未实现) |
| | osTimerIsRunning | 检查计时器是否正在运行。 |
| | osTimerNew | 创建和初始化计时器。 |
| | osTimerStart | 启动或重新启动计时器。 |
| | osTimerStop | 停止计时器。 |
| 互斥管理 | osMutexAcquire | 获取互斥或超时(如果已锁定)。 |
| | osMutexDelete | 删除互斥对象。 |
| | osMutexGetName | 获取互斥对象的名称。(暂未实现) |
| | osMutexGetOwner | 获取拥有互斥对象的线程。 |
| | osMutexNew | 创建并初始化Mutex对象。 |
| | osMutexRelease | 释放由osMutexAcquire获取的Mutex。 |
| 信号量 | osSemaphoreAcquire | 获取信号量令牌或超时(如果没有可用的令牌)。 |
| | osSemaphoreDelete | 删除一个信号量对象。 |
| | osSemaphoreGetCount | 获取当前信号量令牌计数。 |
| | osSemaphoreGetName | 获取信号量对象的名称。(暂未实现) |
| | osSemaphoreNew | 创建并初始化一个信号量对象。 |
| | osSemaphoreRelease | 释放信号量令牌,直到初始最大计数。 |
| 内存池 | osMemoryPoolAlloc | 从内存池分配一个内存块。 |
| | osMemoryPoolDelete | 删除内存池对象。 |
| | osMemoryPoolFree | 将分配的内存块返回到内存池。 |
| | osMemoryPoolGetBlockSize | 获取内存池中的内存块大小。 |
| | osMemoryPoolGetCapacity | 获取内存池中最大的内存块数。 |
| | osMemoryPoolGetCount | 获取内存池中使用的内存块数。 |
| | osMemoryPoolGetName | 获取内存池对象的名称。 |
| | osMemoryPoolGetSpace | 获取内存池中可用的内存块数。 |
| | osMemoryPoolNew | 创建并初始化一个内存池对象。 |
| 消息队列 | osMessageQueueDelete | 删除消息队列对象。 |
| | osMessageQueueGet | 从队列获取消息,或者如果队列为空,则从超时获取消息。 |
| | osMessageQueueGetCapacity | 获取消息队列中的最大消息数。 |
| | osMessageQueueGetCount | 获取消息队列中排队的消息数。 |
| | osMessageQueueGetMsgSize | 获取内存池中的最大消息大小。 |
| | osMessageQueueGetName | 获取消息队列对象的名称。(暂未实现) |
| | osMessageQueueGetSpace | 获取消息队列中消息的可用插槽数。 |
| | osMessageQueueNew | 创建和初始化消息队列对象。 |
| | osMessageQueuePut | 如果队列已满,则将消息放入队列或超时。 |
| | osMessageQueueReset | 将消息队列重置为初始空状态。(暂未实现) |
### 开发流程
......
......@@ -18,219 +18,236 @@ OpenHarmony内核使用**musl libc**库以及自研接口,支持部分标准PO
**表1** POSIX接口说明
| 类别 | 需要包含的头文件 | 接口名 | 描述 |
| 类别 | 需要包含的头文件 | 接口名 | 描述 |
| -------- | -------- | -------- | -------- |
| process | \#include&nbsp;&lt;stdlib.h&gt; | void&nbsp;abort(void); | 中止线程执行 |
| \#include&nbsp;&lt;assert.h&gt; | void&nbsp;assert(scalar&nbsp;expression); | 断言为假终止线程 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_cond_destroy(pthread_cond_t&nbsp;\*cond); | 销毁条件变量 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_cond_init(pthread_cond_t&nbsp;\*restrict&nbsp;cond,&nbsp;const&nbsp;pthread_condattr_t&nbsp;\*restrict&nbsp;attr); | 初始化条件变量 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_cond_timedwait(pthread_cond_t&nbsp;\*restrict&nbsp;cond,&nbsp;pthread_mutex_t&nbsp;\*restrict&nbsp;mutex,&nbsp;const&nbsp;struct&nbsp;timespec&nbsp;\*restrict&nbsp;abstime); | 等待条件 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_condattr_init(pthread_condattr_t&nbsp;\*attr); | 初始化条件变量属性对象 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_mutex_unlock(pthread_mutex_t&nbsp;\*mutex); | 解锁互斥锁 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_create(pthread_t&nbsp;\*thread,&nbsp;const&nbsp;pthread_attr_t&nbsp;\*attr,&nbsp;void&nbsp;\*(\*start_routine)(void&nbsp;\*),&nbsp;void&nbsp;\*arg); | 创建一个新的线程 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_join(pthread_t&nbsp;thread,&nbsp;void&nbsp;\*\*retval); | 等待指定的线程结束 |
| \#include&nbsp;&lt;pthread.h&gt; | pthread_t&nbsp;pthread_self(void); | 获取当前线程的ID |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_getschedparam(pthread_t&nbsp;thread,&nbsp;int&nbsp;\*policy,&nbsp;struct&nbsp;sched_param&nbsp;\*param); | 获取线程的调度策略和参数 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_setschedparam(pthread_t&nbsp;thread,&nbsp;int&nbsp;policy,&nbsp;const&nbsp;struct&nbsp;sched_param&nbsp;\*param); | 设置线程的调度策略和参数 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_mutex_init(pthread_mutex_t&nbsp;\*__restrict&nbsp;m,&nbsp;const&nbsp;pthread_mutexattr_t&nbsp;\*__restrict&nbsp;a); | 初始化互斥锁 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_mutex_lock(pthread_mutex_t&nbsp;\*m); | 互斥锁加锁操作 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_mutex_trylock(pthread_mutex_t&nbsp;\*m); | 互斥锁尝试加锁操作 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_mutex_destroy(pthread_mutex_t&nbsp;\*m); | 销毁互斥锁 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_attr_init(pthread_attr_t&nbsp;\*attr); | 初始化线程属性对象 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_attr_destroy(pthread_attr_t&nbsp;\*attr); | 销毁线程属性对象 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_attr_getstacksize(const&nbsp;pthread_attr_t&nbsp;\*attr,&nbsp;size_t&nbsp;\*stacksize); | 获取线程属性对象的堆栈大小 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_attr_setstacksize(pthread_attr_t&nbsp;\*attr,&nbsp;size_t&nbsp;stacksize); | 设置线程属性对象的堆栈大小 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_attr_getschedparam(const&nbsp;pthread_attr_t&nbsp;\*attr,&nbsp;struct&nbsp;sched_param&nbsp;\*param); | 获取线程属性对象的调度参数属性 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_attr_setschedparam(pthread_attr_t&nbsp;\*attr,&nbsp;const&nbsp;struct&nbsp;sched_param&nbsp;\*param); | 设置线程属性对象的调度参数属性 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_getname_np(pthread_t&nbsp;pthread,&nbsp;char&nbsp;\*name,&nbsp;size_t&nbsp;len); | 获取线程名称 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_setname_np(pthread_t&nbsp;pthread,&nbsp;const&nbsp;char&nbsp;\*name); | 设置线程名称 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_cond_broadcast(pthread_cond_t&nbsp;\*c); | 解除若干已被等待条件阻塞的线程 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_cond_signal(pthread_cond_t&nbsp;\*c); | 解除被阻塞的线程 |
| \#include&nbsp;&lt;pthread.h&gt; | int&nbsp;pthread_cond_wait(pthread_cond_t&nbsp;\*__restrict&nbsp;c,&nbsp;pthread_mutex_t&nbsp;\*__restrict&nbsp;m); | 等待条件 |
| fs | \#include&nbsp;&lt;libgen.h&gt; | char&nbsp;\*dirname(char&nbsp;\*path); | 获取目录名 |
| \#include&nbsp;&lt;dirent.h&gt; | struct&nbsp;dirent&nbsp;\*readdir(DIR&nbsp;\*dirp); | 读目录 |
| \#include&nbsp;&lt;sys/stat.h&gt; | int&nbsp;stat(const&nbsp;char&nbsp;\*restrict&nbsp;path,&nbsp;struct&nbsp;stat&nbsp;\*restrict&nbsp;buf); | 获取文件信息 |
| \#include&nbsp;&lt;unistd.h&gt; | int&nbsp;unlink(const&nbsp;char&nbsp;\*pathname); | 删除文件 |
| \#include&nbsp;&lt;fcntl.h | int&nbsp;open(const&nbsp;char&nbsp;\*path,&nbsp;int&nbsp;oflags,&nbsp;...); | 用于打开文件,如文件不存在,创建文件并打开 |
| \#include&nbsp;&lt;nistd.h&gt; | int&nbsp;close(int&nbsp;fd); | 关闭文件 |
| \#include&nbsp;&lt;stdio.h&gt; | int&nbsp;rename(const&nbsp;char&nbsp;\*oldpath,&nbsp;const&nbsp;char&nbsp;\*newpath); | 重命名指定的文件 |
| \#include&nbsp;&lt;dirent.h&gt; | DIR&nbsp;&nbsp;\*opendir(const&nbsp;char&nbsp;\*dirname); | 打开指定目录 |
| \#include&nbsp;&lt;dirent.h&gt; | int&nbsp;closedir(DIR&nbsp;\*dir); | 关闭指定目录 |
| \#include&nbsp;&lt;sys/mount.h&gt; | int&nbsp;mount(const&nbsp;char&nbsp;\*source,&nbsp;const&nbsp;char&nbsp;\*target,&nbsp;const&nbsp;char&nbsp;\*filesystemtype,&nbsp;unsigned&nbsp;long&nbsp;mountflags,&nbsp;const&nbsp;void&nbsp;\*data); | 挂载文件系统 |
| \#include&nbsp;&lt;sys/mount.h&gt; | int&nbsp;umount(const&nbsp;char&nbsp;\*target); | 卸载文件系统 |
| \#include&nbsp;&lt;sys/mount.h&gt; | int&nbsp;umount2(const&nbsp;char&nbsp;\*target,&nbsp;int&nbsp;flag); | 卸载文件系统 |
| \#include&nbsp;&lt;sys/stat.h&gt; | int&nbsp;fsync(int&nbsp;fd); | 将与指定文件描述符关联的文件同步到存储设备 |
| \#include&nbsp;&lt;sys/stat.h&gt; | int&nbsp;mkdir(const&nbsp;char&nbsp;\*pathname,&nbsp;mode_t&nbsp;mode); | 创建目录 |
| \#include&nbsp;&lt;unistd.h&gt; | int&nbsp;rmdir(const&nbsp;char&nbsp;\*path); | 删除目录 |
| \#include&nbsp;&lt;sys/stat.h&gt; | int&nbsp;fstat(int&nbsp;fd,&nbsp;struct&nbsp;stat&nbsp;\*buf); | 获取文件状态信息 |
| \#include&nbsp;&lt;sys/statfs.h&gt; | int&nbsp;statfs(const&nbsp;char&nbsp;\*path,&nbsp;struct&nbsp;statfs&nbsp;\*buf); | 获取指定路径下文件的文件系统信息 |
| time | \#include&nbsp;&lt;sys/time.h&gt; | int&nbsp;gettimeofday(struct&nbsp;timeval&nbsp;\*tv,&nbsp;struct&nbsp;timezone&nbsp;\*tz); | 获取时间。当前暂无时区概念,tz返回为空 |
| \#include&nbsp;&lt;time.h&gt; | struct&nbsp;tm&nbsp;\*gmtime(const&nbsp;time_t&nbsp;\*timep); | 将日期和时间转换为细分时间或ASCII |
| \#include&nbsp;&lt;time.h&gt; | struct&nbsp;tm&nbsp;\*localtime(const&nbsp;time_t&nbsp;\*timep); | 获取时间 |
| \#include&nbsp;&lt;time.h&gt; | struct&nbsp;tm&nbsp;\*localtime_r(const&nbsp;time_t&nbsp;\*timep,&nbsp;struct&nbsp;tm&nbsp;\*result); | 获取时间 |
| \#include&nbsp;&lt;time.h&gt; | time_t&nbsp;mktime(struct&nbsp;tm&nbsp;\*tm); | 将日期和时间转换为细分时间或ASCII |
| \#include&nbsp;&lt;time.h&gt; | size_t&nbsp;strftime(char&nbsp;\*s,&nbsp;size_t&nbsp;max,&nbsp;const&nbsp;char&nbsp;\*format,const&nbsp;struct&nbsp;tm&nbsp;\*tm); | 格式化日期和时间字符串 |
| \#include&nbsp;&lt;time.h&gt; | time_t&nbsp;time(time_t&nbsp;\*tloc); | 获得日历时间 |
| \#include&nbsp;&lt;sys/times.h&gt; | clock_t&nbsp;times(struct&nbsp;tms&nbsp;\*buf); | 获取线程时间 |
| \#include&nbsp;&lt;unistd.h&gt; | int&nbsp;usleep(useconds_t&nbsp;usec); | 休眠(微秒单位) |
| \#include&nbsp;&lt;time.h&gt; | int&nbsp;nanosleep(const&nbsp;struct&nbsp;timespec&nbsp;\*tspec1,&nbsp;struct&nbsp;timespec&nbsp;\*tspec2); | 暂停当前线程直到指定的时间到达 |
| \#include&nbsp;&lt;time.h&gt; | int&nbsp;clock_gettime(clockid_t&nbsp;id,&nbsp;struct&nbsp;timespec&nbsp;\*tspec); | 获取时钟的时间 |
| \#include&nbsp;&lt;time.h&gt; | int&nbsp;timer_create(clockid_t&nbsp;id,&nbsp;struct&nbsp;sigevent&nbsp;\*__restrict&nbsp;evp,&nbsp;timer_t&nbsp;\*__restrict&nbsp;t); | 为线程创建计时器 |
| \#include&nbsp;&lt;time.h&gt; | int&nbsp;timer_delete(timer_t&nbsp;t); | 为线程删除计时器 |
| \#include&nbsp;&lt;time.h&gt; | int&nbsp;timer_settime(timer_t&nbsp;t,&nbsp;int&nbsp;flags,&nbsp;const&nbsp;struct&nbsp;itimerspec&nbsp;\*__restrict&nbsp;val,&nbsp;struct&nbsp;itimerspec&nbsp;\*__restrict&nbsp;old); | 为线程设置计时器 |
| \#include&nbsp;&lt;time.h&gt; | time_t&nbsp;time&nbsp;(time_t&nbsp;\*t); | 获取时间 |
| \#include&nbsp;&lt;time.h&gt; | char&nbsp;\*strptime(const&nbsp;char&nbsp;\*s,&nbsp;const&nbsp;char&nbsp;\*format,&nbsp;struct&nbsp;tm&nbsp;\*tm); | 将时间的字符串表示形式转换为时间tm结构 |
| util | \#include&nbsp;&lt;stdlib.h&gt; | int&nbsp;atoi(const&nbsp;char&nbsp;\*nptr); | 字符串转换整型(int) |
| \#include&nbsp;&lt;stdlib.h&gt; | long&nbsp;atol(const&nbsp;char&nbsp;\*nptr); | 字符串转换整型(long) |
| \#include&nbsp;&lt;stdlib.h&gt; | long&nbsp;long&nbsp;atoll(const&nbsp;char&nbsp;\*nptr); | 字符串转换整型(long&nbsp;long) |
| \#include&nbsp;&lt;ctype.h&gt; | int&nbsp;isalnum(int&nbsp;c); | 检查字母数字字符 |
| \#include&nbsp;&lt;ctype.h&gt; | int&nbsp;isascii(int&nbsp;c); | 检查ASCII |
| \#include&nbsp;&lt;ctype.h&gt; | int&nbsp;isdigit(int&nbsp;c); | 检查数字字符 |
| \#include&nbsp;&lt;ctype.h&gt; | int&nbsp;islower(int&nbsp;c); | 检查小写字符 |
| \#include&nbsp;&lt;ctype.h&gt; | int&nbsp;isprint(int&nbsp;c); | 检查任何可打印字符,包括空格 |
| \#include&nbsp;&lt;ctype.h&gt; | int&nbsp;isspace(int&nbsp;c); | 检查空格字符 |
| \#include&nbsp;&lt;ctype.h&gt; | int&nbsp;isupper(int&nbsp;c); | 检查所传的字符是否是大写字母 |
| \#include&nbsp;&lt;ctype.h&gt; | int&nbsp;isxdigit(int&nbsp;c); | 判断字符是否为十六进制数 |
| \#include&nbsp;&lt;stdlib.h&gt; | long&nbsp;int&nbsp;random&nbsp;(void); | 生成伪随机数 |
| \#include&nbsp;&lt;stdlib.h&gt; | void&nbsp;srandom(unsigned&nbsp;int&nbsp;seed); | 初始化随机数生成器 |
| \#include&nbsp;&lt;ctype.h&gt; | int&nbsp;tolower(int&nbsp;c); | 字母转换成小写 |
| \#include&nbsp;&lt;ctype.h&gt; | int&nbsp;toupper(int&nbsp;c); | 字母转换成大写 |
| \#include&nbsp;&lt;stdarg.h&gt; | type&nbsp;va_arg(va_list&nbsp;ap,&nbsp;type); | 获取可变参数的当前参数,返回指定类型并将指针指向下一参数 |
| \#include&nbsp;&lt;stdarg.h&gt; | void&nbsp;va_copy(va_list&nbsp;dest,&nbsp;va_list&nbsp;src); | 复制参数 |
| \#include&nbsp;&lt;stdarg.h&gt; | void&nbsp;va_end(va_list&nbsp;ap); | 清空va_list可变参数列表 |
| \#include&nbsp;&lt;stdarg.h&gt; | void&nbsp;va_start(va_list&nbsp;ap,&nbsp;last); | 定义变长参数列表的起始位置 |
| \#include&nbsp;&lt;string.h&gt; | char&nbsp;\*strchr(const&nbsp;char&nbsp;\*s,&nbsp;int&nbsp;c); | 在字符串中定位字符 |
| \#include&nbsp;&lt;string.h&gt; | int&nbsp;strcmp(const&nbsp;char&nbsp;\*s1,&nbsp;const&nbsp;char&nbsp;\*s2); | 比较字符串 |
| \#include&nbsp;&lt;string.h&gt; | size_t&nbsp;strcspn(const&nbsp;char&nbsp;\*s,&nbsp;const&nbsp;char&nbsp;\*reject); | 获取前缀子串的长度 |
| \#include&nbsp;&lt;string.h&gt; | char&nbsp;\*strdup(const&nbsp;char&nbsp;\*s); | 字符串拷贝到新建的位置处 |
| \#include&nbsp;&lt;string.h&gt; | size_t&nbsp;strlen(const&nbsp;char&nbsp;\*s); | 计算字符串长度 |
| \#include&nbsp;&lt;strings.h&gt; | int&nbsp;strncasecmp(const&nbsp;char&nbsp;\*s1,&nbsp;const&nbsp;char&nbsp;\*s2,&nbsp;size_t&nbsp;n); | 比较固定长度字符串(忽略大小写) |
| \#include&nbsp;&lt;strings.h&gt; | int&nbsp;strcasecmp(const&nbsp;char&nbsp;\*s1,&nbsp;const&nbsp;char&nbsp;\*s2); | 比较字符串(忽略大小写) |
| \#include&nbsp;&lt;string.h&gt; | int&nbsp;strncmp(const&nbsp;char&nbsp;\*s1,&nbsp;const&nbsp;char&nbsp;\*s2,&nbsp;size_t&nbsp;n); | 比较字符串(指定长度) |
| \#include&nbsp;&lt;string.h&gt; | char&nbsp;\*strrchr(const&nbsp;char&nbsp;\*s,&nbsp;int&nbsp;c); | 在字符串中定位字符 |
| \#include&nbsp;&lt;string.h&gt; | char&nbsp;\*strstr(const&nbsp;char&nbsp;\*haystack,&nbsp;const&nbsp;char&nbsp;\*needle); | 寻找指定的子串 |
| \#include&nbsp;&lt;stdlib.h&gt; | long&nbsp;int&nbsp;strtol(const&nbsp;char&nbsp;\*nptr,&nbsp;char&nbsp;\*\*endptr,&nbsp;int&nbsp;base); | 将字符串转换为long型整数 |
| \#include&nbsp;&lt;stdlib.h&gt; | unsigned&nbsp;long&nbsp;int&nbsp;strtoul(const&nbsp;char&nbsp;\*nptr,&nbsp;char&nbsp;\*\*endptr,&nbsp;int&nbsp;base); | 将字符串转换为unsigned&nbsp;long型整数 |
| \#include&nbsp;&lt;stdlib.h&gt; | unsigned&nbsp;long&nbsp;long&nbsp;int&nbsp;strtoull(const&nbsp;char&nbsp;\*nptr,&nbsp;char&nbsp;\*\*endptr,int&nbsp;base); | 将字符串转换为unsigned&nbsp;long&nbsp;long型整数 |
| \#include&nbsp;&lt;regex.h&gt; | int&nbsp;regcomp(regex_t&nbsp;\*preg,&nbsp;const&nbsp;char&nbsp;\*regex,&nbsp;int&nbsp;cflags); | 编译正则表达式 |
| \#include&nbsp;&lt;regex.h&gt; | int&nbsp;regexec(const&nbsp;regex_t&nbsp;\*preg,&nbsp;const&nbsp;char&nbsp;\*string,&nbsp;size_t&nbsp;nmatch,regmatch_t&nbsp;pmatch[],&nbsp;int&nbsp;eflags); | 匹配正则表达式 |
| \#include&nbsp;&lt;regex.h&gt; | void&nbsp;regfree(regex_t&nbsp;\*preg); | 释放正则表达式 |
| \#include&nbsp;&lt;string.h&gt; | char&nbsp;\*strerror(int&nbsp;errnum); | 返回描述错误号的字符串 |
| math | \#include&nbsp;&lt;stdlib.h&gt; | int&nbsp;abs(int&nbsp;i); | 取绝对值 |
| \#include&nbsp;&lt;math.h&gt; | double&nbsp;log(double&nbsp;x); | 自然对数函数 |
| \#include&nbsp;&lt;math.h&gt; | double&nbsp;pow(double&nbsp;x,&nbsp;double&nbsp;y); | 求x的指数y次幂 |
| \#include&nbsp;&lt;math.h&gt; | double&nbsp;round(double&nbsp;x); | 从零开始,舍入到最接近的整数 |
| \#include&nbsp;&lt;math.h&gt; | double&nbsp;sqrt(double&nbsp;x); | 平方根 |
| IO | \#include&nbsp;&lt;stdio.h&gt; | void&nbsp;clearerr(FILE&nbsp;\*stream); | 清除流的文件结尾和错误指示 |
| \#include&nbsp;&lt;stdio.h&gt; | int&nbsp;fclose(FILE&nbsp;\*stream); | 关闭文件流 |
| \#include&nbsp;&lt;stdio.h&gt; | FILE&nbsp;\*fdopen(int&nbsp;fd,&nbsp;const&nbsp;char&nbsp;\*mode); | 通过文件描述符打开文件流 |
| \#include&nbsp;&lt;stdio.h&gt; | int&nbsp;feof(FILE&nbsp;\*stream); | 检测返回文件末尾指示位 |
| \#include&nbsp;&lt;stdio.h&gt; | int&nbsp;fflush(FILE&nbsp;\*stream); | 刷新流 |
| \#include&nbsp;&lt;stdio.h&gt; | char&nbsp;\*fgets(char&nbsp;\*s,&nbsp;int&nbsp;size,&nbsp;FILE&nbsp;\*stream); | 读取流的下一行 |
| \#include&nbsp;&lt;stdio.h&gt; | int&nbsp;fileno(FILE&nbsp;\*stream); | 返回流的文件描述符 |
| \#include&nbsp;&lt;stdio.h&gt; | FILE&nbsp;\*fopen(const&nbsp;char&nbsp;\*path,&nbsp;const&nbsp;char&nbsp;\*mode); | 打开流 |
| \#include&nbsp;&lt;stdio.h&gt; | int&nbsp;fputs(const&nbsp;char&nbsp;\*s,&nbsp;FILE&nbsp;\*stream); | 向指定流写入一行 |
| \#include&nbsp;&lt;stdio.h&gt; | size_t&nbsp;fread(void&nbsp;\*ptr,&nbsp;size_t&nbsp;size,&nbsp;size_t&nbsp;nmemb,&nbsp;FILE&nbsp;\*stream); | 读一个流 |
| \#include&nbsp;&lt;stdio.h&gt; | int&nbsp;fseek(FILE&nbsp;\*stream,&nbsp;long&nbsp;offset,&nbsp;int&nbsp;whence); | 设置流指针的位置 |
| \#include&nbsp;&lt;stdio.h&gt; | long&nbsp;ftell(FILE&nbsp;\*stream); | 获取流指针的位置 |
| \#include&nbsp;&lt;stdio.h&gt; | size_t&nbsp;fwrite(const&nbsp;void&nbsp;\*ptr,&nbsp;size_t&nbsp;size,&nbsp;size_t&nbsp;nmemb,FILE&nbsp;\*stream); | 向流写入 |
| \#include&nbsp;&lt;stdio.h&gt; | void&nbsp;perror(const&nbsp;char&nbsp;\*s); | 打印系统错误信息 |
| \#include&nbsp;&lt;stdio.h&gt; | void&nbsp;rewind(FILE&nbsp;\*stream); | 重新定位流 |
| \#include&nbsp;&lt;unistd.h&gt; | ssize_t&nbsp;write(int&nbsp;fd,&nbsp;const&nbsp;void&nbsp;\*buf,&nbsp;size_t&nbsp;size); | 写文件内容 |
| \#include&nbsp;&lt;unistd.h&gt; | ssize_t&nbsp;read(int&nbsp;fd,&nbsp;void&nbsp;\*buf,&nbsp;size_t&nbsp;size); | 读文件内容 |
| net | \#include&nbsp;&lt;sys/socket.h&gt; | void&nbsp;freeaddrinfo(struct&nbsp;addrinfo&nbsp;\*res); | 释放调用getaddrinfo所分配的动态内存 |
| \#include&nbsp;&lt;sys/socket.h&gt; | int&nbsp;getaddrinfo(const&nbsp;char&nbsp;\*restrict&nbsp;nodename,const&nbsp;char&nbsp;\*restrict&nbsp;servname,const&nbsp;struct&nbsp;addrinfo&nbsp;\*restrict&nbsp;hints,struct&nbsp;addrinfo&nbsp;\*\*restrict&nbsp;res); | 网络地址和服务转换 |
| \#include&nbsp;&lt;sys/socket.h&gt; | int&nbsp;getnameinfo(const&nbsp;struct&nbsp;sockaddr&nbsp;\*restrict&nbsp;sa,&nbsp;socklen_t&nbsp;salen,char&nbsp;\*restrict&nbsp;node,&nbsp;socklen_t&nbsp;nodelen,&nbsp;char&nbsp;\*restrict&nbsp;service,socklen_t&nbsp;servicelen,&nbsp;int&nbsp;flags); | 以协议无关的方式进行地址到名称的转换 |
| \#include&nbsp;&lt;net/if.h&gt; | unsigned&nbsp;int&nbsp;if_nametoindex(const&nbsp;char&nbsp;\*ifname); | 通过网络接口名得到索引 |
| \#include&nbsp;&lt;arpa/inet.h&gt; | in_addr_t&nbsp;inet_addr(const&nbsp;char&nbsp;\*cp); | 网络主机地址点分十进制形式转换位二进制形式 |
| \#include&nbsp;&lt;arpa/inet.h&gt; | char&nbsp;\*inet_ntoa(struct&nbsp;in_addr&nbsp;in); | 网络主机地址二进制形式转换位点分十进制形式 |
| \#include&nbsp;&lt;arpa/inet.h&gt; | const&nbsp;char&nbsp;\*inet_ntop(int&nbsp;af,&nbsp;const&nbsp;void&nbsp;\*src,char&nbsp;\*dst,&nbsp;socklen_t&nbsp;size); | 网络地址转换 |
| \#include&nbsp;&lt;arpa/inet.h&gt; | int&nbsp;inet_pton(int&nbsp;af,&nbsp;const&nbsp;char&nbsp;\*src,&nbsp;void&nbsp;\*dst); | 网络地址转换 |
| \#include&nbsp;&lt;sys/socket.h&gt; | int&nbsp;listen(int&nbsp;sockfd,&nbsp;int&nbsp;backlog); | 监听套接字 |
| \#include&nbsp;&lt;sys/socket.h&gt; | ssize_t&nbsp;recvmsg(int&nbsp;sockfd,&nbsp;struct&nbsp;msghdr&nbsp;\*msg,&nbsp;int&nbsp;flags); | 从套接字接收消息.只支持iov大小为1的场景,且不支持ancillary消息 |
| \#include&nbsp;&lt;sys/socket.h&gt; | ssize_t&nbsp;send(int&nbsp;sockfd,&nbsp;const&nbsp;void&nbsp;\*buf,&nbsp;size_t&nbsp;len,&nbsp;int&nbsp;flags); | 从socket发送消息 |
| \#include&nbsp;&lt;sys/socket.h&gt; | ssize_t&nbsp;sendmsg(int&nbsp;sockfd,&nbsp;const&nbsp;struct&nbsp;msghdr&nbsp;\*msg,&nbsp;int&nbsp;flags); | 从socket发送消息。不支持ancillary消息 |
| \#include&nbsp;&lt;sys/socket.h&gt; | ssize_t&nbsp;sendto(int&nbsp;sockfd,&nbsp;const&nbsp;void&nbsp;\*buf,&nbsp;size_t&nbsp;len,&nbsp;int&nbsp;flags,const&nbsp;struct&nbsp;sockaddr&nbsp;\*dest_addr,&nbsp;socklen_t&nbsp;addrlen); | 从socket发送消息 |
| \#include&nbsp;&lt;sys/socket.h&gt; | int&nbsp;setsockopt(int&nbsp;sockfd,&nbsp;int&nbsp;level,&nbsp;int&nbsp;optname,const&nbsp;void&nbsp;\*optval,&nbsp;socklen_t&nbsp;optlen); | 设置与套接字关联的选项 |
| mem | \#include&nbsp;&lt;string.h&gt; | int&nbsp;memcmp(const&nbsp;void&nbsp;\*s1,&nbsp;const&nbsp;void&nbsp;\*s2,&nbsp;size_t&nbsp;n); | 内存比较 |
| \#include&nbsp;&lt;string.h&gt; | void&nbsp;\*memcpy(void&nbsp;\*dest,&nbsp;const&nbsp;void&nbsp;\*src,&nbsp;size_t&nbsp;n); | 内存拷贝 |
| \#include&nbsp;&lt;string.h&gt; | void&nbsp;\*memset(void&nbsp;\*s,&nbsp;int&nbsp;c,&nbsp;size_t&nbsp;n); | 内存初始化 |
| \#include&nbsp;&lt;stdlib.h&gt; | void&nbsp;\*realloc(void&nbsp;\*ptr,&nbsp;size_t&nbsp;size); | 重分配内存 |
| \#include&nbsp;&lt;stdlib.h&gt; | void&nbsp;\*malloc(size_t&nbsp;size); | 动态分配内存块大小 |
| \#include&nbsp;&lt;stdlib.h&gt; | void&nbsp;free(void&nbsp;\*ptr); | 释放ptr所指向的内存空间 |
| IPC | \#include&nbsp;&lt;semaphore.h&gt; | int&nbsp;sem_timedwait(sem_t&nbsp;\*sem,&nbsp;const&nbsp;struct&nbsp;timespec&nbsp;\*abs_timeout); | 计时锁定信号量 |
| \#include&nbsp;&lt;semaphore.h&gt; | int&nbsp;sem_destroy(sem_t&nbsp;\*sem); | 销毁指定的无名信号量 |
| \#include&nbsp;&lt;semaphore.h&gt; | int&nbsp;sem_init(sem_t&nbsp;\*sem,&nbsp;int&nbsp;pshared,&nbsp;unsigned&nbsp;int&nbsp;value); | 创建并初始化一个无名信号量 |
| \#include&nbsp;&lt;semaphore.h&gt; | int&nbsp;sem_post(sem_t&nbsp;\*sem); | 增加信号量计数 |
| \#include&nbsp;&lt;semaphore.h&gt; | int&nbsp;sem_wait(sem_t&nbsp;\*sem); | 获取信号量 |
| \#include&nbsp;&lt;mqueue.h&gt; | mqd_t&nbsp;mq_open(const&nbsp;char&nbsp;\*mqName,&nbsp;int&nbsp;openFlag,&nbsp;...); | 此API用于打开一个具有指定名称的已有消息队列或创建一个新的消息队列 |
| \#include&nbsp;&lt;mqueue.h&gt; | int&nbsp;mq_close(mqd_t&nbsp;personal); | 此API用于关闭具有指定描述符的消息队列 |
| \#include&nbsp;&lt;mqueue.h&gt; | int&nbsp;mq_unlink(const&nbsp;char&nbsp;\*mqName); | 此API用于删除具有指定名称的消息队列 |
| \#include&nbsp;&lt;mqueue.h&gt; | int&nbsp;mq_send(mqd_t&nbsp;personal,&nbsp;const&nbsp;char&nbsp;\*msg,&nbsp;size_t&nbsp;msgLen,&nbsp;unsigned&nbsp;int&nbsp;msgPrio); | 此API用于将具有指定内容和长度的消息放入具有指定描述符的消息队列中 |
| \#include&nbsp;&lt;mqueue.h&gt; | ssize_t&nbsp;mq_receive(mqd_t&nbsp;personal,&nbsp;char&nbsp;\*msg,&nbsp;size_t&nbsp;msgLen,&nbsp;unsigned&nbsp;int&nbsp;\*msgPrio); | 此API用于从具有指定描述符的消息队列中删除最老的消息,并将其放入msg_ptr所指向的缓冲区中 |
| \#include&nbsp;&lt;mqueue.h&gt; | int&nbsp;mq_timedsend(mqd_t&nbsp;personal,&nbsp;const&nbsp;char&nbsp;\*msg,&nbsp;size_t&nbsp;msgLen,&nbsp;unsigned&nbsp;int&nbsp;msgPrio,&nbsp;const&nbsp;struct&nbsp;timespec&nbsp;\*absTimeout) | 此API用于在预定时间将具有指定内容和长度的消息放入具有描述符的消息队列中 |
| \#include&nbsp;&lt;mqueue.h&gt; | ssize_t&nbsp;mq_timedreceive(mqd_t&nbsp;personal,&nbsp;char&nbsp;\*msg,&nbsp;size_t&nbsp;msgLen,&nbsp;unsigned&nbsp;int&nbsp;\*msgPrio,&nbsp;const&nbsp;struct&nbsp;timespec&nbsp;\*absTimeout); | 此API用于从具有指定描述符的消息队列消息中获取具有指定消息内容和长度的消息 |
| \#include&nbsp;&lt;mqueue.h&gt; | int&nbsp;mq_setattr(mqd_t&nbsp;mqdes,&nbsp;const&nbsp;struct&nbsp;mq_attr&nbsp;\*__restrict&nbsp;newattr,&nbsp;struct&nbsp;mq_attr&nbsp;\*__restrict&nbsp;oldattr); | 设置描述符指定的消息队列属性 |
| version | \#include&nbsp;&lt;libc.h&gt; | const&nbsp;char&nbsp;\*libc_get_version_string(void); | 获取libc版本字符串 |
| \#include&nbsp;&lt;libc.h&gt; | int&nbsp;libc_get_version(void); | 获取libc版本号 |
| process | #include <stdlib.h> | void abort(void); | 中止线程执行 |
| | #include <assert.h> | void assert(scalar expression); | 断言为假终止线程 |
| | #include <pthread.h> | int pthread_cond_destroy(pthread_cond_t *cond); | 销毁条件变量 |
| | #include <pthread.h> | int pthread_cond_init(pthread_cond_t *restrict cond, const pthread_condattr_t *restrict attr); | 初始化条件变量 |
| | #include <pthread.h> | int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *shared); | 获取条件变量属性,目前只支持获取PTHREAD_PROCESS_PRIVATE条件变量属性 |
| | #include <pthread.h> | int pthread_condattr_setpshared(pthread_condattr_t *attr, int shared); | 设置条件变量属性 |
| | #include <pthread.h> | int pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock); | 获取线程时钟 |
| | #include <pthread.h> | int pthread_condattr_destroy(pthread_condattr_t *attr); | 删除存储并使属性对象无效 |
| | #include <pthread.h> | int pthread_cond_timedwait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime); | 等待条件 |
| | #include <pthread.h> | int pthread_condattr_init(pthread_condattr_t *attr); | 初始化条件变量属性对象 |
| | #include <pthread.h> | int pthread_mutex_unlock(pthread_mutex_t *mutex); | 解锁互斥锁 |
| | #include <pthread.h> | int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); | 创建一个新的线程 |
| | #include <pthread.h> | int pthread_join(pthread_t thread, void **retval); | 等待指定的线程结束 |
| | #include <pthread.h> | pthread_t pthread_self(void); | 获取当前线程的ID |
| | #include <pthread.h> | int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param); | 获取线程的调度策略和参数 |
| | #include <pthread.h> | int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param); | 设置线程的调度策略和参数 |
| | #include <pthread.h> | int pthread_setschedprio(pthread_t thread, int prio); | 设置线程优先级 |
| | #include <pthread.h> | int pthread_once(pthread_once_t *onceControl, void (*initRoutine)(void)); | 一次性操作任务 |
| | #include <pthread.h> | int pthread_setcancelstate(int state, int *oldState); | 线程cancel功能开关 |
| | #include <pthread.h> | int pthread_setcanceltype(int type, int *oldType); | 设置线程cancel类型 |
| | #include <pthread.h> | int pthread_cancel(pthread_t thread); | 取消线程,目前仅支持先设置PTHREAD_CANCEL_ASYNCHRONOUS状态,再调用pthread_cancel取消线程 |
| | #include <pthread.h> | void pthread_testcancel(void); | cancel线程 |
| | #include <pthread.h> | int pthread_equal(pthread_t thread1, pthread_t thread2); | 判断是否为同一线程 |
| | #include <pthread.h> | int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *outType); | 获取互斥锁的类型属性 |
| | #include <pthread.h> | int pthread_mutex_init(pthread_mutex_t *__restrict m, const pthread_mutexattr_t *__restrict a); | 初始化互斥锁 |
| | #include <pthread.h> | int pthread_mutex_lock(pthread_mutex_t *m); | 互斥锁加锁操作 |
| | #include <pthread.h> | int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *absTimeout); | 申请互斥锁(只在设定时间内阻塞) |
| | #include <pthread.h> | int pthread_mutex_trylock(pthread_mutex_t *m); | 互斥锁尝试加锁操作 |
| | #include <pthread.h> | int pthread_mutex_destroy(pthread_mutex_t *m); | 销毁互斥锁 |
| | #include <pthread.h> | int pthread_attr_init(pthread_attr_t *attr); | 初始化线程属性对象 |
| | #include <pthread.h> | int pthread_attr_destroy(pthread_attr_t *attr); | 销毁线程属性对象 |
| | #include <pthread.h> | int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize); | 获取线程属性对象的堆栈大小 |
| | #include <pthread.h> | int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); | 设置线程属性对象的堆栈大小 |
| | #include <pthread.h> | int pthread_attr_setstack(pthread_attr_t *attr, void *stackAddr, size_t stackSize); | 设置线程属性对象的堆栈属性(暂未实现) |
| | #include <pthread.h> | int pthread_attr_getstack(const pthread_attr_t *attr, void **stackAddr, size_t *stackSize); | 获取线程属性对象的堆栈(暂未实现) |
| | #include <pthread.h> | int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param); | 获取线程属性对象的调度参数属性 |
| | #include <pthread.h> | int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param); | 设置线程属性对象的调度参数属性 |
| | #include <pthread.h> | int pthread_getname_np(pthread_t pthread, char *name, size_t len); | 获取线程名称 |
| | #include <pthread.h> | int pthread_setname_np(pthread_t pthread, const char *name); | 设置线程名称 |
| | #include <pthread.h> | int pthread_cond_broadcast(pthread_cond_t *c); | 解除若干已被等待条件阻塞的线程 |
| | #include <pthread.h> | int pthread_cond_signal(pthread_cond_t *c); | 解除被阻塞的线程 |
| | #include <pthread.h> | int pthread_cond_wait(pthread_cond_t *__restrict c, pthread_mutex_t *__restrict m); | 等待条件 |
| fs | #include <libgen.h> | char *dirname(char *path); | 获取目录名 |
| | #include <dirent.h> | struct dirent *readdir(DIR *dirp); | 读目录 |
| | #include <sys/stat.h> | int stat(const char *restrict path, struct stat *restrict buf); | 获取文件信息 |
| | #include <unistd.h> | int unlink(const char *pathname); | 删除文件 |
| | #include <fcntl.h | int open(const char *path, int oflags, ...); | 用于打开文件,如文件不存在,创建文件并打开 |
| | #include <nistd.h> | int close(int fd); | 关闭文件 |
| | #include <stdio.h> | int rename(const char *oldpath, const char *newpath); | 重命名指定的文件 |
| | #include <dirent.h> | DIR *opendir(const char *dirname); | 打开指定目录 |
| | #include <dirent.h> | int closedir(DIR *dir); | 关闭指定目录 |
| | #include <sys/mount.h> | int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data); | 挂载文件系统 |
| | #include <sys/mount.h> | int umount(const char *target); | 卸载文件系统 |
| | #include <sys/mount.h> | int umount2(const char *target, int flag); | 卸载文件系统 |
| | #include <sys/stat.h> | int fsync(int fd); | 将与指定文件描述符关联的文件同步到存储设备 |
| | #include <sys/stat.h> | int mkdir(const char *pathname, mode_t mode); | 创建目录 |
| | #include <unistd.h> | int rmdir(const char *path); | 删除目录 |
| | #include <sys/stat.h> | int fstat(int fd, struct stat *buf); | 获取文件状态信息 |
| | #include <sys/statfs.h> | int statfs(const char *path, struct statfs *buf); | 获取指定路径下文件的文件系统信息 |
| time | #include <sys/time.h> | int gettimeofday(struct timeval *tv, struct timezone *tz); | 获取时间。当前暂无时区概念,tz返回为空 |
| | #include <time.h> | struct tm *gmtime(const time_t *timep); | 将日期和时间转换为细分时间或ASCII |
| | #include <time.h> | struct tm *localtime(const time_t *timep); | 获取时间 |
| | #include <time.h> | struct tm *localtime_r(const time_t *timep, struct tm *result); | 获取时间 |
| | #include <time.h> | time_t mktime(struct tm *tm); | 将日期和时间转换为细分时间或ASCII |
| | #include <time.h> | size_t strftime(char *s, size_t max, const char *format,const struct tm *tm); | 格式化日期和时间字符串 |
| | #include <time.h> | time_t time(time_t *tloc); | 获得日历时间 |
| | #include <sys/times.h> | clock_t times(struct tms *buf); | 获取线程时间 |
| | #include <sys/times.h> | int timer_getoverrun(timer_t timerID); | 获取定时器超时次数 |
| | #include <unistd.h> | int usleep(useconds_t usec); | 休眠(微秒单位) |
| | #include <time.h> | int nanosleep(const struct timespec *tspec1, struct timespec *tspec2); | 暂停当前线程直到指定的时间到达 |
| | #include <time.h> | int clock_gettime(clockid_t id, struct timespec *tspec); | 获取时钟的时间 |
| | #include <time.h> | int timer_create(clockid_t id, struct sigevent *__restrict evp, timer_t *__restrict t); | 为线程创建计时器 |
| | #include <time.h> | int timer_delete(timer_t t); | 为线程删除计时器 |
| | #include <time.h> | int timer_settime(timer_t t, int flags, const struct itimerspec *__restrict val, struct itimerspec *__restrict old); | 为线程设置计时器 |
| | #include <time.h> | time_t time (time_t *t); | 获取时间 |
| | #include <time.h> | char *strptime(const char *s, const char *format, struct tm *tm); | 将时间的字符串表示形式转换为时间tm结构 |
| util | #include <stdlib.h> | int atoi(const char *nptr); | 字符串转换整型(int) |
| | #include <stdlib.h> | long atol(const char *nptr); | 字符串转换整型(long) |
| | #include <stdlib.h> | long long atoll(const char *nptr); | 字符串转换整型(long long) |
| | #include <ctype.h> | int isalnum(int c); | 检查字母数字字符 |
| | #include <ctype.h> | int isascii(int c); | 检查ASCII |
| | #include <ctype.h> | int isdigit(int c); | 检查数字字符 |
| | #include <ctype.h> | int islower(int c); | 检查小写字符 |
| | #include <ctype.h> | int isprint(int c); | 检查任何可打印字符,包括空格 |
| | #include <ctype.h> | int isspace(int c); | 检查空格字符 |
| | #include <ctype.h> | int isupper(int c); | 检查所传的字符是否是大写字母 |
| | #include <ctype.h> | int isxdigit(int c); | 判断字符是否为十六进制数 |
| | #include <stdlib.h> | long int random (void); | 生成伪随机数 |
| | #include <stdlib.h> | void srandom(unsigned int seed); | 初始化随机数生成器 |
| | #include <ctype.h> | int tolower(int c); | 字母转换成小写 |
| | #include <ctype.h> | int toupper(int c); | 字母转换成大写 |
| | #include <stdarg.h> | type va_arg(va_list ap, type); | 获取可变参数的当前参数,返回指定类型并将指针指向下一参数 |
| | #include <stdarg.h> | void va_copy(va_list dest, va_list src); | 复制参数 |
| | #include <stdarg.h> | void va_end(va_list ap); | 清空va_list可变参数列表 |
| | #include <stdarg.h> | void va_start(va_list ap, last); | 定义变长参数列表的起始位置 |
| | #include <string.h> | char *strchr(const char *s, int c); | 在字符串中定位字符 |
| | #include <string.h> | int strcmp(const char *s1, const char *s2); | 比较字符串 |
| | #include <string.h> | size_t strcspn(const char *s, const char *reject); | 获取前缀子串的长度 |
| | #include <string.h> | char *strdup(const char *s); | 字符串拷贝到新建的位置处 |
| | #include <string.h> | size_t strlen(const char *s); | 计算字符串长度 |
| | #include <strings.h> | int strncasecmp(const char *s1, const char *s2, size_t n); | 比较固定长度字符串(忽略大小写) |
| | #include <strings.h> | int strcasecmp(const char *s1, const char *s2); | 比较字符串(忽略大小写) |
| | #include <string.h> | int strncmp(const char *s1, const char *s2, size_t n); | 比较字符串(指定长度) |
| | #include <string.h> | char *strrchr(const char *s, int c); | 在字符串中定位字符 |
| | #include <string.h> | char *strstr(const char *haystack, const char *needle); | 寻找指定的子串 |
| | #include <stdlib.h> | long int strtol(const char *nptr, char **endptr, int base); | 将字符串转换为long型整数 |
| | #include <stdlib.h> | unsigned long int strtoul(const char *nptr, char **endptr, int base); | 将字符串转换为unsigned long型整数 |
| | #include <stdlib.h> | unsigned long long int strtoull(const char *nptr, char **endptr,int base); | 将字符串转换为unsigned long long型整数 |
| | #include <regex.h> | int regcomp(regex_t *preg, const char *regex, int cflags); | 编译正则表达式 |
| | #include <regex.h> | int regexec(const regex_t *preg, const char *string, size_t nmatch,regmatch_t pmatch[], int eflags); | 匹配正则表达式 |
| | #include <regex.h> | void regfree(regex_t *preg); | 释放正则表达式 |
| | #include <string.h> | char *strerror(int errnum); | 返回描述错误号的字符串 |
| math | #include <stdlib.h> | int abs(int i); | 取绝对值 |
| | #include <math.h> | double log(double x); | 自然对数函数 |
| | #include <math.h> | double pow(double x, double y); | 求x的指数y次幂 |
| | #include <math.h> | double round(double x); | 从零开始,舍入到最接近的整数 |
| | #include <math.h> | double sqrt(double x); | 平方根 |
| IO | #include <stdio.h> | void clearerr(FILE *stream); | 清除流的文件结尾和错误指示 |
| | #include <stdio.h> | int fclose(FILE *stream); | 关闭文件流 |
| | #include <stdio.h> | FILE *fdopen(int fd, const char *mode); | 通过文件描述符打开文件流 |
| | #include <stdio.h> | int feof(FILE *stream); | 检测返回文件末尾指示位 |
| | #include <stdio.h> | int fflush(FILE *stream); | 刷新流 |
| | #include <stdio.h> | char *fgets(char *s, int size, FILE *stream); | 读取流的下一行 |
| | #include <stdio.h> | int fileno(FILE *stream); | 返回流的文件描述符 |
| | #include <stdio.h> | FILE *fopen(const char *path, const char *mode); | 打开流 |
| | #include <stdio.h> | int fputs(const char *s, FILE *stream); | 向指定流写入一行 |
| | #include <stdio.h> | size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); | 读一个流 |
| | #include <stdio.h> | int fseek(FILE *stream, long offset, int whence); | 设置流指针的位置 |
| | #include <stdio.h> | long ftell(FILE *stream); | 获取流指针的位置 |
| | #include <stdio.h> | size_t fwrite(const void *ptr, size_t size, size_t nmemb,FILE *stream); | 向流写入 |
| | #include <stdio.h> | void perror(const char *s); | 打印系统错误信息 |
| | #include <stdio.h> | void rewind(FILE *stream); | 重新定位流 |
| | #include <unistd.h> | ssize_t write(int fd, const void *buf, size_t size); | 写文件内容 |
| | #include <unistd.h> | ssize_t read(int fd, void *buf, size_t size); | 读文件内容 |
| net | #include <sys/socket.h> | void freeaddrinfo(struct addrinfo *res); | 释放调用getaddrinfo所分配的动态内存 |
| | #include <sys/socket.h> | int getaddrinfo(const char *restrict nodename,const char *restrict servname,const struct addrinfo *restrict hints,struct addrinfo **restrict res); | 网络地址和服务转换 |
| | #include <sys/socket.h> | int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,char *restrict node, socklen_t nodelen, char *restrict service,socklen_t servicelen, int flags); | 以协议无关的方式进行地址到名称的转换 |
| | #include <net/if.h> | unsigned int if_nametoindex(const char *ifname); | 通过网络接口名得到索引 |
| | #include <arpa/inet.h> | in_addr_t inet_addr(const char *cp); | 网络主机地址点分十进制形式转换位二进制形式 |
| | #include <arpa/inet.h> | char *inet_ntoa(struct in_addr in); | 网络主机地址二进制形式转换位点分十进制形式 |
| | #include <arpa/inet.h> | const char *inet_ntop(int af, const void *src,char *dst, socklen_t size); | 网络地址转换 |
| | #include <arpa/inet.h> | int inet_pton(int af, const char *src, void *dst); | 网络地址转换 |
| | #include <sys/socket.h> | int listen(int sockfd, int backlog); | 监听套接字 |
| | #include <sys/socket.h> | ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags); | 从套接字接收消息.只支持iov大小为1的场景,且不支持ancillary消息 |
| | #include <sys/socket.h> | ssize_t send(int sockfd, const void *buf, size_t len, int flags); | 从socket发送消息 |
| | #include <sys/socket.h> | ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags); | 从socket发送消息。不支持ancillary消息 |
| | #include <sys/socket.h> | ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,const struct sockaddr *dest_addr, socklen_t addrlen); | 从socket发送消息 |
| | #include <sys/socket.h> | int setsockopt(int sockfd, int level, int optname,const void *optval, socklen_t optlen); | 设置与套接字关联的选项 |
| mem | #include <string.h> | int memcmp(const void *s1, const void *s2, size_t n); | 内存比较 |
| | #include <string.h> | void *memcpy(void *dest, const void *src, size_t n); | 内存拷贝 |
| | #include <string.h> | void *memset(void *s, int c, size_t n); | 内存初始化 |
| | #include <stdlib.h> | void *realloc(void *ptr, size_t size); | 重分配内存 |
| | #include <stdlib.h> | void *malloc(size_t size); | 动态分配内存块大小 |
| | #include <stdlib.h> | void free(void *ptr); | 释放ptr所指向的内存空间 |
| IPC | #include <semaphore.h> | int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout); | 计时锁定信号量 |
| | #include <semaphore.h> | int sem_destroy(sem_t *sem); | 销毁指定的无名信号量 |
| | #include <semaphore.h> | int sem_trywait(sem_t *sem); | 尝试申请一个信号量 |
| | #include <semaphore.h> | int sem_init(sem_t *sem, int pshared, unsigned int value); | 创建并初始化一个无名信号量 |
| | #include <semaphore.h> | int sem_post(sem_t *sem); | 增加信号量计数 |
| | #include <semaphore.h> | int sem_wait(sem_t *sem); | 获取信号量 |
| | #include <mqueue.h> | mqd_t mq_open(const char *mqName, int openFlag, ...); | 此API用于打开一个具有指定名称的已有消息队列或创建一个新的消息队列 |
| | #include <mqueue.h> | int mq_close(mqd_t personal); | 此API用于关闭具有指定描述符的消息队列 |
| | #include <mqueue.h> | int mq_unlink(const char *mqName); | 此API用于删除具有指定名称的消息队列 |
| | #include <mqueue.h> | int mq_send(mqd_t personal, const char *msg, size_t msgLen, unsigned int msgPrio); | 此API用于将具有指定内容和长度的消息放入具有指定描述符的消息队列中 |
| | #include <mqueue.h> | ssize_t mq_receive(mqd_t personal, char *msg, size_t msgLen, unsigned int *msgPrio); | 此API用于从具有指定描述符的消息队列中删除最老的消息,并将其放入msg_ptr所指向的缓冲区中 |
| | #include <mqueue.h> | int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int msgPrio, const struct timespec *absTimeout) | 此API用于在预定时间将具有指定内容和长度的消息放入具有描述符的消息队列中 |
| | #include <mqueue.h> | ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *msgPrio, const struct timespec *absTimeout); | 此API用于从具有指定描述符的消息队列消息中获取具有指定消息内容和长度的消息 |
| | #include <mqueue.h> | int mq_setattr(mqd_t mqdes, const struct mq_attr *__restrict newattr, struct mq_attr *__restrict oldattr); | 设置描述符指定的消息队列属性 |
| | version | #include <libc.h> | const char *libc_get_version_string(void); |
| | #include <libc.h> | int libc_get_version(void); | 获取libc版本号 |
### 注意事项
常用错误码对照表:
| C&nbsp;Name | Value | Description | 含义 |
| C Name | Value | Description | 含义 |
| -------- | -------- | -------- | -------- |
| ENOERR | 0 | Success | 成功 |
| EPERM | 1 | Operation&nbsp;not&nbsp;permitted | 操作不允许 |
| ENOENT | 2 | No&nbsp;such&nbsp;file&nbsp;or&nbsp;directory | 没有这样的文件或目录 |
| ESRCH | 3 | No&nbsp;such&nbsp;process | 没有这样的进程(暂不支持) |
| EINTR | 4 | Interrupted&nbsp;system&nbsp;call | 系统调用被中断 |
| EIO | 5 | I/O&nbsp;error | I/O错误 |
| ENXIO | 6 | No&nbsp;such&nbsp;device&nbsp;or&nbsp;address | 没有这样的设备或地址 |
| E2BIG | 7 | Arg&nbsp;list&nbsp;too&nbsp;long | 参数列表太长 |
| ENOEXEC | 8 | Exec&nbsp;format&nbsp;error | 执行格式错误 |
| EBADF | 9 | Bad&nbsp;file&nbsp;number | 坏的文件描述符 |
| ECHILD | 10 | No&nbsp;child&nbsp;processes | 没有子进程(暂不支持) |
| EAGAIN | 11 | Try&nbsp;again | 资源暂时不可用 |
| ENOMEM | 12 | Out&nbsp;of&nbsp;memory | 内存溢出 |
| EACCES | 13 | Permission&nbsp;denied | 拒绝许可 |
| EFAULT | 14 | Bad&nbsp;address | 错误的地址 |
| ENOTBLK | 15 | Block&nbsp;device&nbsp;required | 块设备请求 |
| EBUSY | 16 | Device&nbsp;or&nbsp;resource&nbsp;busy | 设备或资源忙 |
| EEXIST | 17 | File&nbsp;exists | 文件存在 |
| EXDEV | 18 | Cross-device&nbsp;link | 无效的交叉链接 |
| ENODEV | 19 | No&nbsp;such&nbsp;device | 设备不存在 |
| ENOTDIR | 20 | Not&nbsp;a&nbsp;directory | 不是一个目录 |
| EISDIR | 21 | Is&nbsp;a&nbsp;directory | 是一个目录 |
| EINVAL | 22 | Invalid&nbsp;argument | 无效的参数 |
| ENFILE\* | 23 | File&nbsp;table&nbsp;overflow | 打开太多的文件系统 |
| EMFILE | 24 | Too&nbsp;many&nbsp;open&nbsp;files | 打开的文件过多 |
| EFBIG | 27 | File&nbsp;too&nbsp;large | 文件太大 |
| ENOSPC | 28 | No&nbsp;space&nbsp;left&nbsp;on&nbsp;device | 设备上没有空间 |
| ESPIPE | 29 | Illegal&nbsp;seek | 非法移位 |
| EROFS | 30 | Read-only&nbsp;file&nbsp;system | 只读文件系统 |
| EMLINK | 31 | Too&nbsp;many&nbsp;links | 太多的链接 |
| EDOM | 33 | Math&nbsp;argument&nbsp;out&nbsp;of&nbsp;domain | 数值结果超出范围 |
| ERANGE | 34 | Math&nbsp;result&nbsp;not&nbsp;representable | 数值结果不具代表性 |
| EDEADLK | 35 | Resource&nbsp;deadlock&nbsp;would&nbsp;occur | 资源死锁错误 |
| ENAMETOOLONG | 36 | Filename&nbsp;too&nbsp;long | 文件名太长 |
| ENOLCK | 37 | No&nbsp;record&nbsp;locks&nbsp;available | 没有可用锁 |
| ENOSYS | 38 | Function&nbsp;not&nbsp;implemented | 功能没有实现 |
| ENOTEMPTY | 39 | Directory&nbsp;not&nbsp;empty | 目录不空 |
| ELOOP | 40 | Too&nbsp;many&nbsp;symbolic&nbsp;links&nbsp;encountered | 符号链接层次太多 |
| ENOMSG | 42 | No&nbsp;message&nbsp;of&nbsp;desired&nbsp;type | 没有期望类型的消息 |
| EIDRM | 43 | Identifier&nbsp;removed | 标识符删除 |
| ELNRNG | 48 | Link&nbsp;number&nbsp;out&nbsp;of&nbsp;range | 链接数超出范围 |
| EBADR | 53 | Invalid&nbsp;request&nbsp;descriptor | 请求描述符无效 |
| EBADRQC | 56 | Invalid&nbsp;request&nbsp;code | 无效的请求代码 |
| ENOSTR | 60 | Device&nbsp;not&nbsp;a&nbsp;stream | 设备不是字符流 |
| ENODATA | 61 | No&nbsp;data&nbsp;available | 无可用数据 |
| ETIME | 62 | Timer&nbsp;expired | 计时器过期 |
| EPROTO | 71 | Protocol&nbsp;error | 协议错误 |
| EBADMSG | 74 | Not&nbsp;a&nbsp;data&nbsp;message | 非数据消息 |
| EOVERFLOW | 75 | Value&nbsp;too&nbsp;large&nbsp;for&nbsp;defined&nbsp;data&nbsp;type | 值太大,对于定义数据类型 |
| EMSGSIZE | 90 | Message&nbsp;too&nbsp;long | 消息太长 |
| ENOERR | 0 | Success | 成功 |
| EPERM | 1 | Operation not permitted | 操作不允许 |
| ENOENT | 2 | No such file or directory | 没有这样的文件或目录 |
| ESRCH | 3 | No such process | 没有这样的进程(暂不支持) |
| EINTR | 4 | Interrupted system call | 系统调用被中断 |
| EIO | 5 | I/O error | I/O错误 |
| ENXIO | 6 | No such device or address | 没有这样的设备或地址 |
| E2BIG | 7 | Arg list too long | 参数列表太长 |
| ENOEXEC | 8 | Exec format error | 执行格式错误 |
| EBADF | 9 | Bad file number | 坏的文件描述符 |
| ECHILD | 10 | No child processes | 没有子进程(暂不支持) |
| EAGAIN | 11 | Try again | 资源暂时不可用 |
| ENOMEM | 12 | Out of memory | 内存溢出 |
| EACCES | 13 | Permission denied | 拒绝许可 |
| EFAULT | 14 | Bad address | 错误的地址 |
| ENOTBLK | 15 | Block device required | 块设备请求 |
| EBUSY | 16 | Device or resource busy | 设备或资源忙 |
| EEXIST | 17 | File exists | 文件存在 |
| EXDEV | 18 | Cross-device link | 无效的交叉链接 |
| ENODEV | 19 | No such device | 设备不存在 |
| ENOTDIR | 20 | Not a directory | 不是一个目录 |
| EISDIR | 21 | Is a directory | 是一个目录 |
| EINVAL | 22 | Invalid argument | 无效的参数 |
| ENFILE* | 23 | File table overflow | 打开太多的文件系统 |
| EMFILE | 24 | Too many open files | 打开的文件过多 |
| EFBIG | 27 | File too large | 文件太大 |
| ENOSPC | 28 | No space left on device | 设备上没有空间 |
| ESPIPE | 29 | Illegal seek | 非法移位 |
| EROFS | 30 | Read-only file system | 只读文件系统 |
| EMLINK | 31 | Too many links | 太多的链接 |
| EDOM | 33 | Math argument out of domain | 数值结果超出范围 |
| ERANGE | 34 | Math result not representable | 数值结果不具代表性 |
| EDEADLK | 35 | Resource deadlock would occur | 资源死锁错误 |
| ENAMETOOLONG | 36 | Filename too long | 文件名太长 |
| ENOLCK | 37 | No record locks available | 没有可用锁 |
| ENOSYS | 38 | Function not implemented | 功能没有实现 |
| ENOTEMPTY | 39 | Directory not empty | 目录不空 |
| ELOOP | 40 | Too many symbolic links encountered | 符号链接层次太多 |
| ENOMSG | 42 | No message of desired type | 没有期望类型的消息 |
| EIDRM | 43 | Identifier removed | 标识符删除 |
| ELNRNG | 48 | Link number out of range | 链接数超出范围 |
| EBADR | 53 | Invalid request descriptor | 请求描述符无效 |
| EBADRQC | 56 | Invalid request code | 无效的请求代码 |
| ENOSTR | 60 | Device not a stream | 设备不是字符流 |
| ENODATA | 61 | No data available | 无可用数据 |
| ETIME | 62 | Timer expired | 计时器过期 |
| EPROTO | 71 | Protocol error | 协议错误 |
| EBADMSG | 74 | Not a data message | 非数据消息 |
| EOVERFLOW | 75 | Value too large for defined data type | 值太大,对于定义数据类型 |
| EMSGSIZE | 90 | Message too long | 消息太长 |
### 编程实例
......
......@@ -42,22 +42,25 @@ OpenHarmony LiteOS-M内核的中断模块提供下面几种功能,接口详细
**表1** 中断模块接口
| 功能分类 | 接口名 | 描述 |
| 功能分类 | 接口名 | 描述 |
| -------- | -------- | -------- |
| 创建、删除中断 | HalHwiCreate | 中断创建,注册中断号、中断触发模式、中断优先级、中断处理程序。中断被触发时,会调用该中断处理程序。 |
| HalHwiDelete | 根据指定的中断号,删除中断。 |
| 打开、关闭中断 | LOS_IntUnLock | 开中断,使能当前处理器所有中断响应。 |
| LOS_IntLock | 关中断,关闭当前处理器所有中断响应。 |
| LOS_IntRestore | 恢复到使用LOS_IntLock、LOS_IntUnLock操作之前的中断状态。 |
| 创建、删除中断 | LOS_HwiCreate | 中断创建,注册中断号、中断触发模式、中断优先级、中断处理程序。中断被触发时,会调用该中断处理程序。 |
| | LOS_HwiDelete | 根据指定的中断号,删除中断。 |
| 打开、关闭中断 | LOS_IntUnLock | 开中断,使能当前处理器所有中断响应。 |
| | LOS_IntLock | 关中断,关闭当前处理器所有中断响应。 |
| | LOS_IntRestore | 恢复到使用LOS_IntLock、LOS_IntUnLock操作之前的中断状态。 |
| 使能和屏蔽指定中断 | LOS_HwiDisable | 中断屏蔽。(通过设置寄存器,禁止CPU响应该中断) |
| | LOS_HwiEnable | 中断使能。(通过设置寄存器,允许CPU响应该中断) |
| 设置中断优先级 | LOS_HwiSetPriority | 设置中断优先级。 |
| 触发中断 | LOS_HwiTrigger | 触发中断。(通过写中断控制器的相关寄存器模拟外部中断) |
| 清除中断寄存器状态 | LOS_HwiClear | 清除中断号对应的中断寄存器的状态位,此接口依赖中断控制器版本,非必需。 |
## 开发流程
1. 调用中断创建接口HalHwiCreate创建中断。
2. 调用TestHwiTrigger接口触发指定中断(该接口在测试套中定义,通过写中断控制器的相关寄存器模拟外部中断,一般的外设设备,不需要执行这一步)。
3. 调用HalHwiDelete接口删除指定中断,此接口根据实际情况使用,判断是否需要删除中断。
1. 调用中断创建接口LOS_HwiCreate创建中断。
2. 调用中断触发接口LOS_HwiTrigger触发中断。
3. 调用LOS_HwiDelete接口删除指定中断,此接口根据实际情况使用,判断是否需要删除中断。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
......@@ -101,7 +104,7 @@ static UINT32 Example_Interrupt(VOID)
HWI_ARG_T arg = 0;
/*创建中断*/
ret = HalHwiCreate(HWI_NUM_TEST, hwiPrio, mode, (HWI_PROC_FUNC)HwiUsrIrq, arg);
ret = LOS_HwiCreate(HWI_NUM_TEST, hwiPrio, mode, (HWI_PROC_FUNC)HwiUsrIrq, arg);
if(ret == LOS_OK){
printf("Hwi create success!\n");
} else {
......@@ -109,11 +112,17 @@ static UINT32 Example_Interrupt(VOID)
return LOS_NOK;
}
/* 延时50个Ticks, 当有硬件中断发生时,会调用函数HwiUsrIrq*/
LOS_TaskDelay(50);
/*触发中断*/
ret = LOS_HwiTrigger(HWI_NUM_TEST);
if(ret == LOS_OK){
printf("Hwi trigger success!\n");
} else {
printf("Hwi trigger failed!\n");
return LOS_NOK;
}
/*删除中断*/
ret = HalHwiDelete(HWI_NUM_TEST);
ret = LOS_HwiDelete(HWI_NUM_TEST);
if(ret == LOS_OK){
printf("Hwi delete success!\n");
} else {
......@@ -132,5 +141,7 @@ static UINT32 Example_Interrupt(VOID)
```
Hwi create success!
in the func HwiUsrIrq
Hwi trigger success!
Hwi delete success!
```
......@@ -109,32 +109,34 @@ OpenHarmony LiteOS-M内核的任务管理模块提供下面几种功能,接口
**表1** 任务管理模块接口
| 功能分类 | 接口名 | 描述 |
| 功能分类 | 接口名 | 描述 |
| -------- | -------- | -------- |
| 创建和删除任务 | LOS_TaskCreateOnly | 创建任务,并使该任务进入suspend状态,不对该任务进行调度。如果需要调度,可以调用LOS_TaskResume使该任务进入ready状态。 |
| LOS_TaskCreate | 创建任务,并使该任务进入ready状态,如果就绪队列中没有更高优先级的任务,则运行该任务。 |
| LOS_TaskDelete | 删除指定的任务。 |
| 控制任务状态 | LOS_TaskResume | 恢复挂起的任务,使该任务进入ready状态。 |
| LOS_TaskSuspend | 挂起指定的任务,然后切换任务。 |
| LOS_TaskJoin | 挂起当前任务,等待指定任务运行结束并回收其任务控制块资源 |
| LOS_TaskDelay | 任务延时等待,释放CPU,等待时间到期后该任务会重新进入ready状态。传入参数为Tick数目。 |
| LOS_Msleep | 传入参数为毫秒数,转换为Tick数目,调用LOS_TaskDelay。 |
| LOS_TaskYield | 当前任务时间片设置为0,释放CPU,触发调度运行就绪任务队列中优先级最高的任务。 |
| 控制任务调度 | LOS_TaskLock | 锁任务调度,但任务仍可被中断打断。 |
| LOS_TaskUnlock | 解锁任务调度。 |
| LOS_Schedule | 触发任务调度。 |
| 控制任务优先级 | LOS_CurTaskPriSet | 设置当前任务的优先级。 |
| LOS_TaskPriSet | 设置指定任务的优先级。 |
| LOS_TaskPriGet | 获取指定任务的优先级。 |
| 获取任务信息 | LOS_CurTaskIDGet | 获取当前任务的ID。 |
| LOS_NextTaskIDGet | 获取任务就绪队列中优先级最高的任务的ID。 |
| LOS_NewTaskIDGet | 等同LOS_NextTaskIDGet。 |
| LOS_CurTaskNameGet | 获取当前任务的名称。 |
| LOS_TaskNameGet | 获取指定任务的名称。 |
| LOS_TaskStatusGet | 获取指定任务的状态。 |
| LOS_TaskInfoGet | 获取指定任务的信息,包括任务状态、优先级、任务栈大小、栈顶指针SP、任务入口函数、已使用的任务栈大小等。 |
| LOS_TaskIsRunning | 获取任务模块是否已经开始调度运行。 |
| 任务信息维测 | LOS_TaskSwitchInfoGet | 获取任务切换信息,需要开启宏LOSCFG_BASE_CORE_EXC_TSK_SWITCH。 |
| 创建和删除任务 | LOS_TaskCreateOnly | 创建任务,并使该任务进入suspend状态,不对该任务进行调度。如果需要调度,可以调用LOS_TaskResume使该任务进入ready状态。 |
| | LOS_TaskCreate | 创建任务,并使该任务进入ready状态,如果就绪队列中没有更高优先级的任务,则运行该任务。 |
| | LOS_TaskDelete | 删除指定的任务。 |
| 控制任务状态 | LOS_TaskResume | 恢复挂起的任务,使该任务进入ready状态。 |
| | LOS_TaskSuspend | 挂起指定的任务,然后切换任务。 |
| | LOS_TaskJoin | 挂起当前任务,等待指定任务运行结束并回收其任务控制块资源。 |
| | LOS_TaskDetach | 修改任务的joinable属性为detach属性,detach属性的任务运行结束会自动回收任务控制块资源。 |
| | LOS_TaskDelay | 任务延时等待,释放CPU,等待时间到期后该任务会重新进入ready状态。传入参数为Tick数目。 |
| | LOS_Msleep | 传入参数为毫秒数,转换为Tick数目,调用LOS_TaskDelay。 |
| | LOS_TaskYield | 当前任务时间片设置为0,释放CPU,触发调度运行就绪任务队列中优先级最高的任务。 |
| 控制任务调度 | LOS_TaskLock | 锁任务调度,但任务仍可被中断打断。 |
| | LOS_TaskUnlock | 解锁任务调度。 |
| | LOS_Schedule | 触发任务调度。 |
| 控制任务优先级 | LOS_CurTaskPriSet | 设置当前任务的优先级。 |
| | LOS_TaskPriSet | 设置指定任务的优先级。 |
| | LOS_TaskPriGet | 获取指定任务的优先级。 |
| 获取任务信息 | LOS_CurTaskIDGet | 获取当前任务的ID。 |
| | LOS_NextTaskIDGet | 获取任务就绪队列中优先级最高的任务的ID。 |
| | LOS_NewTaskIDGet | 等同LOS_NextTaskIDGet。 |
| | LOS_CurTaskNameGet | 获取当前任务的名称。 |
| | LOS_TaskNameGet | 获取指定任务的名称。 |
| | LOS_TaskStatusGet | 获取指定任务的状态。 |
| | LOS_TaskInfoGet | 获取指定任务的信息,包括任务状态、优先级、任务栈大小、栈顶指针SP、任务入口函数、已使用的任务栈大小等。 |
| | LOS_TaskIsRunning | 获取任务模块是否已经开始调度运行。 |
| 任务信息维测 | LOS_TaskSwitchInfoGet | 获取任务切换信息,需要开启宏LOSCFG_BASE_CORE_EXC_TSK_SWITCH。 |
| 回收任务栈资源 | LOS_TaskResRecycle | 回收所有待回收的任务栈资源。 |
## 开发流程
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册