📄 taskmanager.sm
字号:
// -*- tab-width: 4; -*-//// The contents of this file are subject to the Mozilla Public// License Version 1.1 (the "License"); you may not use this file// except in compliance with the License. You may obtain a copy of// the License at http://www.mozilla.org/MPL/// // Software distributed under the License is distributed on an "AS// IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or// implied. See the License for the specific language governing// rights and limitations under the License.// // The Original Code is State Machine Compiler (SMC).// // The Initial Developer of the Original Code is Charles W. Rapp.// Portions created by Charles W. Rapp are// Copyright (C) 2000 - 2003 Charles W. Rapp.// All Rights Reserved.// // Contributor(s): //// TaskManager --//// The task manager is responsible for executing tasks. This// state machine tracks whether the manager has any tasks to run// and how long a task is executed.//// RCS ID// $Id: taskManager.sm,v 1.5 2005/05/28 18:02:56 cwrapp Exp $//// CHANGE LOG// $Log: taskManager.sm,v $// Revision 1.5 2005/05/28 18:02:56 cwrapp// Updated Tcl examples, removed EX6.//// Revision 1.0 2003/12/14 20:35:26 charlesr// Initial revision//// Since this task manager does not have any tasks to// run, it is in the idle state.%start MainMap::Idle%class TaskManager%map MainMap%%// Wait here for some work to do.IdleEntry{ sendMessage(4 "Idle. Looking for a task to run."); checkTaskQueue();}{ // Start the highest priority task running and start the slice // timer. RunTask RunningTask { startTask(); } // There is now a task a run. TaskCreated RunningTask { startTask(); } TaskUnblocked RunningTask { startTask(); } Shutdown IdleShutdown { sendMessage(0 "Shutdown started."); setTimer("ShutdownTimeout" 2000); } // It is possible for the task to complete before it // receives the suspend request. When this happens, handle // this in the same manner as above. TaskDone [[$ctxt getRunnableTaskCount] > 0] RunningTask { startTask(); } TaskDone Idle { stopTimer("ReplyTimeout"); }}// A task has been started and is running.RunningTaskEntry{ setTimer("SliceTimeout" 3000);}Exit{ stopTimer("SliceTimeout");}{ // The time slice is up. Suspend the task. SliceTimeout SuspendingTask { suspendTask(); } // The task has been blocked. Find another task to run. TaskBlocked Idle {} // The task has been deleted. Find another task to run. TaskDeleted Idle {} // The task has completed its work. Find another task to run. TaskDone Idle {}}// Wait here for the task to suspend.SuspendingTaskEntry{ setTimer("ReplyTimeout" 500);}Exit{ stopTimer("ReplyTimeout");}{ TaskSuspended Idle {} // Wait only so long for the task to reply. ReplyTimeout Idle {} // Just in case a task completes exactly at the same time // as the run slice ends. TaskDone Idle {}}// Wait here while the tasks report in.ShuttingDown{ // A task is reporting it has stopped. When all tasks are // stopped, exit this application. TaskStopped [[$ctxt getRunningTask] == "" && [$ctxt getRunnableTaskCount] == 0 && [$ctxt getBlockedTaskCount] == 0] ShutdownComplete { stopTimer("ShutdownTimeout"); sendMessage(0 "Shutdown completed."); exitApplication(0); } // Another task has stopped but there are more. TaskStopped nil {} // Timed out waiting for the tasks to die. Clean up and // exit anyway. ShutdownTimeout ShutdownComplete { sendMessage(0 "Timed out waiting for tasks to stop. Forcibly deleting tasks and exiting."); deleteAllTasks(); exitApplication(1); } // Since we are shutting down, ignore task suspended // messages. TaskSuspended nil {} // If another shutdown is seen, ignore it. Shutdown nil {}}// The system was idle when the shutdown request occurred.// Wait for the shutdown timeout, then exit.IdleShutdown{ ShutdownTimeout ShutdownComplete { sendMessage(0 "Shutdown completed."); exitApplication(0); }}ShutdownComplete{ // Once this state is reached, don't do anything. Shutdown nil {} Default nil {}}Default{ // Tell all tasks to stop. Wait for them to reply but only // so long. If they fail to reply, kill 'em anyway. Shutdown ShuttingDown { sendMessage(0 "Shutdown started. Stopping all tasks."); stopAllTimers(); stopAllTasks(); setTimer("ShutdownTimeout" 5000); } // Ignore these events if already running a task. TaskCreated nil {} TaskUnblocked nil {} // Ignore timeouts when unexpected. SliceTimeout nil {} ReplyTimeout nil {}}%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -