📄 sem.h
字号:
/** * sem.h - Semaphore Mechanism. * * Copyright (C) 2008 ZhangHu * All rights reserved. * E-MAIL: anmnmnly@gmail.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */#ifndef __SEM_H__#define __SEM_H__#include "include/types.h"#include "include/list.h"#include "include/core.h"#define SEM_BIN 0x01 /* Binary semaphore */#define SEM_NUM 0x02 /* Counting semaphore. */#define SEM_SYN_INIT 0x03 /* A temporary type, in fact, it is Binary semaphore. */#define SEM_OK 0x00 /* Operation is OK */#define SEM_FALSE 0x04 /* Operation is faild. */#define SEM_NOT_CREATE 0x05 /* Semaphore is not created. */#define SEM_FALSE_ISR 0x06 /* Lock a semaphore in interruption context. */#define SEM_ID_CONFLICT 0x07 /* ID confilct when create a new semaphore. */typedef struct semaphore { uword_t sem_id; /* Semaphore ID */ word_t sem_type; /* Semaphore type */ word_t sem_cnt; /* value */ uword_t task_cnt; /* Count all blocked task */ slist_t tcb_link; /* TCB links the locked semaphore with this member */ list_t sem_link; /* All semaphores linked by this member */ list_t task_link[MAX_PRIO]; /* Waiting queue */} sem_t;/* Initialize semaphore */void initsem(void);/* Unlock all semaphores that a task locked */void release_sem(tcb_t *ptcb);/* Creating a semaphore */sem_t *semInit(semid_t SemID, /* The ID of new semaphore */ uword_t InitCnt, /* The initial count value of new semaphore */ uword_t *err); /* Return reasons about this operation *//* Creating a synchronized semaphore */sem_t *semInitSyn(semid_t SemID, /* The ID of new semaphore */ uword_t *err); /* Return reasons about this operation *//* Creating a mutex semaphore */sem_t *semInitMutex(semid_t SemID, /* The ID of new semaphore */ uword_t *err); /* Return reasons about this operation *//* Get semaphore */void semGain(semid_t SemID, /* The ID of new semaphore */ sem_t *pSemaphore, /* Pointer to semaphore */ uword_t *err); /* Return reasons about this operation *//* Get semaphore without block */void semGainFree(semid_t SemID, /* The ID of new semaphore */ sem_t *pSemaphore, /* Pointer to semaphore */ uword_t *err); /* Return reasons about this operation *//* Unlock a semaphore */uword_t semPost(semid_t SemID, /* The ID of new semaphore */ sem_t *pSemaphore); /* Pointer to semaphore *//* Deleting a semaphore */void semDel(semid_t SemID, /* The ID of new semaphore */ sem_t *pSemaphore); /* Pointer to semaphore */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -