cond.c
来自「MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis」· C语言 代码 · 共 69 行
C
69 行
// 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 mos/kernel/avr/cond.c * @brief Basic condition variable support. * * THIS CODE HAS NOT BEEN TESTED * * @author Lane Phillips * @date Created: 02/18/2005 */ #include "mos.h"#include "msched.h"#include "tlist.h"#include "mutex.h"#include "cond.h"void mos_cond_init(mos_cond_t *cond){ mos_tlist_init(&cond->q);}void mos_cond_signal(mos_cond_t *cond){ // If we have a waiting thread make it ready thread_t *next; if ((next = mos_tlist_remove(&cond->q)) != NULL) { mos_thread_resume(next); }}void mos_cond_broadcast(mos_cond_t *cond){ // Wake up all waiting threads thread_t *next; while ((next = mos_tlist_remove(&cond->q)) != NULL) { mos_thread_resume(next); }}void mos_cond_wait(mos_cond_t *cond, mos_mutex_t *mt){ // Get the current thread ID thread_t *id = mos_thread_current(); // Disable interrupts so we can unlock and wait atomically handle_t int_handle = mos_disable_ints(); // Unlock the mutex mos_mutex_unlock(mt); // Put us on the list for the condition variable mos_tlist_add(&cond->q, id); // Suspend us with interrupts already disabled mos_thread_suspend_noints(int_handle); // Lock the mutex again before returning mos_mutex_lock(mt);}// Not implemented yet//int8_t mos_cond_timedwait(mos_cond_t *cond, mutex *mt,// const struct timespec *abstime)//{//}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?