📄 tasks.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/tasks.c,v 1.3 2003/01/15 14:04:37 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** * Copyright 1993-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. ****************************************************************************//* * $Log: tasks.c,v $ * Revision 1.3 2003/01/15 14:04:37 josh * directory structure shifting * * Revision 1.2 2001/11/08 15:56:30 tneale * Updated for newest file layout * * Revision 1.1.1.1 2001/11/05 17:48:44 tneale * Tornado shuffle * * Revision 2.14 2001/01/19 22:23:55 paul * Update copyright. * * Revision 2.13 2000/10/16 19:21:55 paul * Restore sockets and mempool code. * * Revision 2.12 2000/03/17 00:12:48 meister * Update copyright message * * Revision 2.11 2000/03/13 21:22:12 paul * Removed some code that we are no longer working on. * * Revision 2.10 1999/02/18 04:41:41 wes * Sockets merge: Everything Else * - memory pools * - thread support * - port-specific headers * * Revision 2.9.8.1 1998/09/23 19:17:24 wes * Merge socket-branch-1 changes to socket-branch-2 * * Revision 2.9.6.1 1998/08/19 13:26:36 wes * Merge sockets-pthreads work to shared branch * * Revision 2.9.2.1 1998/07/28 18:14:59 wes * pthread hacks * * Revision 2.9 1998/07/02 06:55:41 sra * Make Snark restartable under pSOS, and other minor cleanups. * * Revision 2.8 1998/06/23 17:52:33 meister * move snarklib.h to after attache/h/glue.h if attache is defined * * Revision 2.7 1998/02/25 04:57:44 sra * Update copyrights. * * Revision 2.6 1997/03/20 06:53:17 sra * DFARS-safe copyright text. Zap! * * Revision 2.5 1997/03/19 20:19:01 sra * Put glue_intlock() calls under INSTALL_ATTACHE conditionals. This * isn't the right long-term solution, but it'll do for now. * * Revision 2.4 1997/03/19 04:47:35 sra * Get rid of some gratuitous historical dependencies on Attache. * * Revision 2.3 1997/02/25 10:58:16 sra * Update copyright notice, dust under the bed. * * Revision 2.2 1996/10/25 16:01:00 sar * Added some include files to get the configuration stuff correct. * * Revision 2.1 1996/03/22 10:05:39 sra * Update copyrights prior to Attache 3.2 release. * * Revision 2.0 1995/05/10 22:38:15 sra * Attache release 3.0. * * Revision 1.2 1995/01/06 00:52:48 sra * Update copyright notice for 2.1 release. * * Revision 1.1 1993/07/05 21:53:30 sra * Initial revision * *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*//* * Common code (all ports) for snark's tasking package. * * This is based in large part on Romkey's simtask package, with * some changes suggested by Bridgham and different modularization * to fit into snark properly. *//* * This business with glue_intlock() is a mess that should be sorted * out someday, but today I've got to get this puppy to build cleanly * without Attache, so just conditionalize the references for now. */#include <wrn/wm/common/config.h>#include <wrn/wm/common/glue.h>#if INSTALL_ATTACHE#include <wrn/wm/attache/config.h>#include <wrn/wm/attache/packet.h>#include <wrn/wm/attache/glue.h>#endif#include <wrn/wm/demo/snarklib.h>static struct task *task_head, **task_tail;void task_ini(struct task *task){ if (task) MEMSET((void *) task, 0, sizeof(*task));}void task_enq(struct task *task){#if INSTALL_ATTACHE int lock = glue_intlock(0);#endif if (task && !task->next) { *task_tail = task; task_tail = &task->next; }#if INSTALL_ATTACHE glue_intlock(lock);#endif#if INSTALL_ATTACHE_THREADS task_kick();#endif}struct task *task_deq(){#if INSTALL_ATTACHE int lock = glue_intlock(0);#endif struct task *task = task_head; if (task) { task_head = task->next; if (task_head) task->next = 0; else task_tail = &task_head; }#if INSTALL_ATTACHE glue_intlock(lock);#endif return task;}void task_add (struct task *task, char *name, void (*func)(struct task *, void *), void *cookie){ if (!task) return; task->name = name; task->func = func; task->cookie = cookie; task_enq(task);}/* * This is messy. We don't want to disable interrupts while we search * the task queue, because that could take a long time. We must disable * interrupts while we're modifying the queue. So we check for timing * screws between locating the block and disabling interrupts, and loop * if we determine that such a timing screw has occured. * * I'm not sure it's worth going to all this trouble, it might be simpler * to say that dequeuing a task just means zeroing its function pointer. */void task_delq(struct task *task){ struct task **t = &task_head;#if INSTALL_ATTACHE int lock;#endif while (*t) { if (*t != task) { t = &(*t)->next; /* Haven't found our task yet */ continue; }#if INSTALL_ATTACHE lock = glue_intlock(0);#endif if (*t != task || (!task->next && &task->next != task_tail)) { t = &task_head; /* Oops, timing screw, restart search */ } else { *t = task->next; /* No timing screw, unlink our task */ task->next = 0; t = &task->next; /* Remember that we're done searching */ }#if INSTALL_ATTACHE glue_intlock(lock);#endif }}int task_idle(){ return !task_head;}void tasks_init(void){ task_head = 0; task_tail = &task_head;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -