📄 sem.h
字号:
// This file is part of MANTIS OS, Operating System// See http://mantis.cs.colorado.edu///// Copyright (C) 2003,2004,2005 University of Colorado, Boulder//// This program is free software; you can redistribute it and/or// modify it under the terms of the mos license (see file LICENSE)/** @file micro/include/sem.h * @brief Semphore routines for use on sensor nodes. * @author Brian Shucker * @date 02/05/2003 */#ifndef SEMAPHORE_H_#define SEMAPHORE_H_#include <inttypes.h>#include "tlist.h"/** @brief Succeeded in decrementing semaphore */#define SEM_SUCCESS 0/** @brief Failed in decrementing semaphore */#define SEM_FAIL 1/** @brief Semaphore data structure */typedef struct { /** @brief Current semaphore count */ int8_t val; /** @brief List of threads waiting on semaphore */ tlist_t q;} mos_sem_t;/** @brief Init the semaphores with beginning value. * @param s Semaphore to init * @param value Value to give the semaphore */void mos_sem_init(mos_sem_t *s, int value);/** @brief Post the semaphore. * @param s Semaphore to post */void mos_sem_post(mos_sem_t *s);/** @brief Wake up a specific thread. * @param s Semaphore to post * @param thread Thread */void mos_sem_select_post(mos_sem_t *s, uint16_t thread);/** @brief Wait on a semaphore. * @param s Semaphore */void mos_sem_wait(mos_sem_t *s);/** @brief Test the semaphore and decrement if possible, otherwise return. * @param s Semaphore * @return SEM_SUCCESS, SEM_FAIL */uint8_t mos_sem_try_wait(mos_sem_t *s);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -