home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 3.ddi / TASK.ZIP / MESS.CPP next >
Encoding:
C/C++ Source or Header  |  1989-08-21  |  1.1 KB  |  46 lines

  1. /*****************************************************
  2. file: MESS.CPP      Copyright 1989 by Dlugosz Software
  3.    inter-task messages for multitasking system
  4. *****************************************************/
  5.  
  6. #include "usual.hpp"
  7. #include "task.hpp"
  8. #include "sem.hpp"
  9. #include "mess.hpp"
  10.  
  11. /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
  12.  
  13. message::message()
  14. : s1(1), s2(0)
  15. {
  16. // nothing else to do
  17. }
  18.  
  19. /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
  20.  
  21. message::~message() {}
  22.  
  23. /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
  24.  
  25. bool message::put (void* p)
  26. {
  27. if (!s1--) return FALSE;
  28.    /* wait my turn to get into the function body, and then prevent others
  29.       from getting in after me */
  30. buf= p;  //place message
  31. s2++;  //give reader the go-ahead
  32. if (!s1--) return FALSE;  //wait for return reciept
  33. s1++;  //let next writer in to the function body
  34. return TRUE;
  35. }
  36.  
  37. /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
  38.  
  39. bool message::get (void** p)
  40. {
  41. if (!s2--) return FALSE;  //wait for message to come in
  42. *p= buf;
  43. // note that this task still has exclusive access to the message.
  44. // you must call done() to let the next writer through.
  45. }
  46.