home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / Threads Interface / CThreadManager.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-03  |  1.6 KB  |  71 lines  |  [TEXT/KAHL]

  1. /***
  2.  * CThreadManager.c
  3.  *
  4.  *  Simple interface to the threads package.  Just for fun so we can create something
  5.  *  all in one spot...
  6.  *        Copyright © Gordon Watts 1994 (gwatts@fnal.fnal.gov)
  7.  *
  8.  ***/
  9. #include "CThreadManager.h"
  10. #include <Threads.h>
  11. #include <Exceptions.h>
  12. #include "ReminderConst.h"
  13. #include "CMainThread.h"
  14. #include "CErrorRecorder.h"
  15. #include "util.h"
  16.  
  17. /**
  18.  * CThreadManager
  19.  *
  20.  *  Make sure the thread manager is present!!
  21.  *
  22.  **/
  23. CThreadManager :: CThreadManager (void)
  24. {
  25.     unsigned long    threadVersion;
  26.     OSErr            theErr;
  27.  
  28.     /**
  29.      ** Do the gestalt thing to make sure the thread manager is present, and has
  30.      ** at least the basic capabilities.
  31.      **/
  32.     
  33.     theErr = Gestalt (gestaltThreadMgrAttr, &threadVersion);
  34.     if (theErr != noErr) {
  35.         CErrorRecorder :: gError -> Message ("\pNo thread manager present");
  36.         Failure (errNoThreadManager, 0L);
  37.     }
  38.  
  39.     /**
  40.      ** Make sure the version is present...
  41.      **/
  42.  
  43.     if ((threadVersion & (1 << gestaltThreadMgrPresent)) != 1) {
  44.         CErrorRecorder :: gError -> Message ("\pNeed later version of thread manager!");
  45.         Failure (errNoThreadManager, 0L);
  46.     }
  47.  
  48.     /**
  49.      ** Start up the main thread.  This is just to make sure the thread switcher
  50.      ** is up and working...
  51.      **/
  52.     
  53.     theMainThread = 0;
  54.     theMainThread = new CMainThread;
  55.     AssertStr (theMainThread, "\pNo main thread was allocated! :( ");
  56.     theMainThread -> Start ();
  57.  
  58. }
  59.  
  60. /**
  61.  * ~CMainThread
  62.  *
  63.  *  Kill off the main thread
  64.  *
  65.  **/
  66. CThreadManager :: ~CThreadManager (void)
  67. {
  68.     AssertStr (theMainThread, "\ptheMainThread was zero when tried to kill thread mgr!");
  69.     theMainThread -> Kill ();
  70.     delete theMainThread;
  71. }