home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / lsEstuff / thread.e < prev    next >
Encoding:
Text File  |  1999-10-15  |  1.6 KB  |  84 lines

  1. OPT MODULE
  2.  
  3. MODULE 'dos/dos'
  4. MODULE 'dos/dostags'
  5. MODULE 'geta4'
  6. MODULE 'utility/tagitem'
  7.  
  8. ENUM THREAD_INITING=1, THREAD_RUNNING, THREAD_EXITING, THREAD_DEAD
  9.  
  10. EXPORT OBJECT thread
  11.    PRIVATE
  12.    mothertask
  13.    threadtask
  14.    threadstatus:INT
  15.    proc2bethread
  16.    name[34]:ARRAY OF CHAR
  17.    arg
  18. ENDOBJECT
  19.  
  20.  
  21. DEF proc2bethread, threadclass:PTR TO thread
  22.  
  23. PROC threadstart()
  24.    geta4()
  25.    proc2bethread(threadclass)
  26. ENDPROC
  27.  
  28. PROC signalCTRL_F(task)
  29.    Signal(task, SIGBREAKF_CTRL_F)
  30. ENDPROC
  31.  
  32. PROC waitCTRL_F()
  33.    Wait(SIGBREAKF_CTRL_F)
  34. ENDPROC
  35.  
  36. PROC thread(proc, name=NIL) OF thread
  37.    self.proc2bethread := proc
  38.    self.mothertask := FindTask(0)
  39.    self.threadstatus := THREAD_DEAD
  40.    IF name THEN AstrCopy(self.name, name, 33) ELSE AstrCopy(self.name, 'unnamed', 33)
  41. ENDPROC
  42.  
  43. PROC setArg(arg) OF thread
  44.    self.arg := arg
  45. ENDPROC
  46.  
  47. PROC start(pri=NIL, tags=NIL) OF thread
  48.    /* globals */
  49.    threadclass := self
  50.    proc2bethread := self.proc2bethread
  51.    /* start it */
  52.    self.threadtask:=CreateNewProc(
  53.     [
  54.     NP_ENTRY,{threadstart}, -> where the thread process begins
  55.     NP_NAME, self.name,
  56.     NP_PRIORITY, pri,
  57.     IF tags = NIL THEN TAG_END ELSE TAG_MORE,
  58.     tags
  59.     ])
  60.    /* wait for it to initialize */
  61.    IF self.threadtask THEN waitCTRL_F()
  62.    /* we are in buissiness */
  63.    self.threadstatus := THREAD_RUNNING
  64. ENDPROC self.threadtask
  65.  
  66. PROC kill() OF thread
  67.    IF self.threadtask
  68.       signalCTRL_F(self.threadtask)
  69.       waitCTRL_F()
  70.       RETURN TRUE
  71.    ENDIF
  72. ENDPROC NIL
  73.  
  74. PROC end() OF thread IS self.kill()
  75.  
  76. PROC ready() OF thread IS signalCTRL_F(self.mothertask)
  77.  
  78. PROC getArg() OF thread IS self.arg
  79.  
  80. PROC imGone() OF thread IS signalCTRL_F(self.mothertask)
  81.  
  82.  
  83.  
  84.