home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-28 | 3.4 KB | 133 lines | [TEXT/CWIE] |
- // ===========================================================================
- // UDeleteTaskQueue.cp © 1995, Éric Forget. All rights reserved.
- // ===========================================================================
- //
- // ************************************************************************
- // * *
- // * Before using this code you should read the "License Agreement" *
- // * document and agree with it. *
- // * *
- // ************************************************************************
- //
- // UDeleteTaskQueue is an utility class to delete a task when it is clean
- // to do so. We need this class because certain type of task (e.g. LTimerTask)
- // do not permit to move memory at interrupt time.
- //
- // ---------------------------------------------------------------------------
- //
- // Instruction Notes:
- // -----------------
- //
- // Normally, you should not need to call it.
- //
- // ---------------------------------------------------------------------------
-
- #ifdef PowerPlant_PCH
- #include PowerPlant_PCH
- #endif
-
- #include "UDeleteTaskQueue.h"
- #include <LDynamicArray.h>
- #include "LTask.h"
-
-
- // ---------------------------------------------------------------------------
- // • Static members
- // ---------------------------------------------------------------------------
-
-
- LDynamicArray* UDeleteTaskQueue::sTaskQ = nil;
- UDeleteTaskQueue* UDeleteTaskQueue::sDeleteTaskQueue = nil;
-
-
-
- // ---------------------------------------------------------------------------
- // • UDeleteTaskQueue
- // ---------------------------------------------------------------------------
- // Default constructor
-
- UDeleteTaskQueue::UDeleteTaskQueue()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~UDeleteTaskQueue
- // ---------------------------------------------------------------------------
- // Destructor
-
- UDeleteTaskQueue::~UDeleteTaskQueue()
- {
- if(sTaskQ != nil) {
-
- LTask *theTask;
-
- for(Int32 i = sTaskQ->GetCount(); i > 0; i--) {
-
- sTaskQ->FetchItemAt(i, &theTask);
- Assert_(!theTask->IsExecuting());
-
- delete theTask;
- sTaskQ->RemoveItemsAt(1, i);
- }
-
- delete sTaskQ;
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • AddTask
- // ---------------------------------------------------------------------------
- // Add Task in the to delete queue
-
- void
- UDeleteTaskQueue::AddTask(
- LTask *inTask)
- {
- if (sTaskQ == nil) { // Create queue if it doesn't exist
-
- sTaskQ = new LList;
- }
-
- if (sDeleteTaskQueue == nil) { // Create object if it doesn't exist
-
- sDeleteTaskQueue = new UDeleteTaskQueue;
- }
-
- // Add to end of the to delete queue
- sTaskQ->InsertItemsAt(1, arrayIndex_Last, &inTask);
- sDeleteTaskQueue->StartRepeating();
- }
-
-
- // ---------------------------------------------------------------------------
- // • SpendTime
- // ---------------------------------------------------------------------------
-
- void
- UDeleteTaskQueue::SpendTime(
- const EventRecord &/*inMacEvent*/)
- {
- LTask *theTask;
-
-
- for(Int32 i = sTaskQ->GetCount(); i > 0; i--) {
-
- sTaskQ->FetchItemAt(i, &theTask);
- if(!theTask->IsExecuting()) {
-
- delete theTask;
- sTaskQ->RemoveItemsAt(1, i);
- }
- }
-
- if(sTaskQ->GetCount() == 0) {
-
- delete sTaskQ;
- sTaskQ = nil;
- delete sDeleteTaskQueue;
- sDeleteTaskQueue = nil;
- }
- }
-