⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rwlock.h

📁 MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis的0.9.5版本的源码。
💻 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/rwlock.h * @brief Basic read-write locking support. * * @author Lane Phillips * @date Created: 02/25/2005 */#ifndef RWLOCK_H_#define RWLOCK_H_#include "mos.h"#include "tlist.h"/** @brief Rwlock is locked */#define RWLOCK_LOCKED 1/** @brief Rwlock is unlocked */#define RWLOCK_OK 0/** @brief Rwlock data structure */typedef struct mos_rwlock_t {   tlist_t rq;   tlist_t wq;   uint8_t rlocked;   uint8_t wlocked;} mos_rwlock_t;/** @brief Initialize a read-write lock. * * Must init before use. * @param lock Read-write lock to init */void rwlock_init(mos_rwlock_t *lock);/** @brief Lock a read-write lock for reading. * * This lock may be shared with other threads that have called rwlock_rdlock(). * Blocks the thread if the read-write lock is already locked for writing. * @param lock Read-write lock to lock */void rwlock_rdlock(mos_rwlock_t *lock);/** @brief Lock a read-write lock for reading if it is free. * * This lock may be shared with other threads that have called rwlock_rdlock(). * Does not block. * @param lock Read-write lock to lock * @return RWLOCK_LOCKED if another thread already has a lock, else RWLOCK_OK */uint8_t rwlock_tryrdlock(mos_rwlock_t *lock);/** @brief Lock a read-write lock for writing. * * Only one thread will hold a write lock at a time. * Blocks the thread if the read-write lock is already locked for reading or writing. * @param lock Read-write lock to lock */void rwlock_wrlock(mos_rwlock_t *lock);/** @brief Lock a read-write lock for writing if it is free. * * Only one thread will hold a write lock at a time. * Does not block. * @param lock Read-write lock to lock * @return RWLOCK_LOCKED if another thread already has a lock, else RWLOCK_OK */uint8_t rwlock_trywrlock(mos_rwlock_t *lock);/** @brief Unlock a read-write lock. *  * Release both read and write locks.  Threads that are blocking on write locks * will wake up before threads blocking on read locks. * @param lock Read-write lock to unlock */void rwlock_unlock(mos_rwlock_t *lock);// Not implemented/*void rwlock_timedrdlock(mos_rwlock_t *lock,            const struct timespec *restrict);void rwlock_timedwrlock(mos_rwlock_t *lock,            const struct timespec *restrict);*/#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -