zoukankan      html  css  js  c++  java
  • lwIP(Light Weight IP)协议

    • 信号量

      信号量结构体:struct sys_semt

        struct _sys_sem {
        void *sem;
        };

            err_t sys_sem_new(sys_sem_t *sem, u8_t count)                 新建信号量

    err_t sys_sem_new(sys_sem_t *sem, u8_t count)                         //err_t为signed char类型,sys_sem_t为struct sys_semt类型
    {
      HANDLE new_sem = NULL;

    LWIP_ASSERT("sem != NULL", sem != NULL);                      

    new_sem = CreateSemaphore(0, count, 100000, 0);            //创建一个信号量,创建出错返回0

    LWIP_ASSERT("Error creating semaphore", new_sem != NULL);

    if(new_sem != NULL)

    {

    if (SYS_INITIALIZED()) {

        SYS_ARCH_LOCKED(SYS_STATS_INC_USED(sem));

    } else {

         SYS_STATS_INC_USED(sem);

    }
    #if LWIP_STATS && SYS_STATS

    LWIP_ASSERT("sys_sem_new() counter overflow", lwip_stats.sys.sem.used != 0);

    #endif /* LWIP_STATS && SYS_STATS*/

    sem->sem = new_sem;

    return ERR_OK;

           }

          /* failed to allocate memory... */

    if (SYS_INITIALIZED()) {

       SYS_ARCH_LOCKED(SYS_STATS_INC(sem.err));

    } else {

       SYS_STATS_INC(sem.err);

    }
    sem->sem = NULL;
    return ERR_MEM;

    }

          

            void sys_sem_signal(sys_sem_t *sem)                                  发送信号量

            u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) 等待信号量

            void sys_sem_free(sys_sem_t *sem)                                        删除信号量

    void sys_sem_free(sys_sem_t *sem)

    {

    /* parameter check */

    LWIP_ASSERT("sem != NULL", sem != NULL);

    LWIP_ASSERT("sem->sem != NULL", sem->sem != NULL);

    LWIP_ASSERT("sem->sem != INVALID_HANDLE_VALUE", sem->sem != INVALID_HANDLE_VALUE);

    CloseHandle(sem->sem);

    SYS_ARCH_LOCKED(SYS_STATS_DEC(sem.used));

    #if LWIP_STATS && SYS_STATS

    LWIP_ASSERT("sys_sem_free() closed more than created", lwip_stats.sys.sem.used != (u16_t)-1);

    #endif /* LWIP_STATS && SYS_STATS */

    sem->sem = NULL;

    }

            int sys_sem_valid(sys_sem_t *sem)                                        查询是否可用

            void sys_sem_set_invalid(sys_sem_t *sem)                            设置为失效

       

        void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg)//设置一个超时事件

        void sys_untimeout(sys_timeout_handler h, void *arg)//删除一个超时事件

    • 互斥锁

      

      err_t sys_mutex_new(sys_mutex_t *mutex)                  新建锁

            void sys_mutex_lock(sys_mutex_t *mutex)                  获取锁

            void sys_mutex_unlock(sys_mutex_t *mutex)             释放锁

            void sys_mutex_free(sys_mutex_t *mutex)                   删除锁

            int sys_mutex_valid(sys_mutex_t *mutex)                    查询锁是否可用

            void sys_mutex_set_invalid(sys_mutex_t *mutex)        设置锁为失效

    • 创建线程

      sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio) 

  • 相关阅读:
    OC中ARC forbids explicit message send of release错误
    OC中内存管理(转)
    [题解]数学期望_luogu_P1850_换教室
    [题解](单调队列)luogu_P2216_BZOJ_1047 理想的正方形
    [题解]luogu_AT1224_JOIOJI
    [题解]区间dp_luogu_P3147 262144
    [筆記]歐拉路
    [題解/狀壓dp]POJ_2411_Mondriaan's dream
    [題解]luogu_P1854 花店櫥窗佈置
    [題解]luogu_P1052 過河
  • 原文地址:https://www.cnblogs.com/jony7/p/9985002.html
Copyright © 2011-2022 走看看