📄 mutex.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/mutex.h * @brief Basic mutex support. * * @author Jeff Rose * @date Created: 01/20/2003 */#ifndef MUTEX_H_#define MUTEX_H_#include "msched.h"#include "tlist.h"/** @brief Mutex is locked */#define MUTEX_LOCKED 1/** @brief Mutex is unlocked */#define MUTEX_OK 0/** @brief Mutex data structure */typedef struct mos_thread_s { /** @brief Pointer to thread this mutex belongs to */ struct thread_s *owner; /** @brief Thead list queue waiting on this mutex */ tlist_t q;} mos_mutex_t;/** @brief Init a mutex data structure. * * Must init before use. * @param mt Mutex to init */void mos_mutex_init(mos_mutex_t *mt);/** @brief Lock a mutex. * * Blocks the thread if the mutex is already locked. * @param mt Mutex to lock */void mos_mutex_lock(mos_mutex_t *mt);/** @brief Unlock a mutex so another thread can enter the protected area of code. * @param mt Mutex to unlock */void mos_mutex_unlock(mos_mutex_t *mt);/** @brief Take the lock if its free. * @param mt Current mutex (locked/unlocked) * @return MUTEX_LOCKED if another thread already has a lock, else MUTEX_OK */int8_t mos_mutex_try_lock(mos_mutex_t *mt);#define mos_fast_mutex_lock() mos_disable_ints()#define mos_fast_mutex_unlock(handle) mos_enable_ints(handle)#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -