home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************
- file: MESS.CPP Copyright 1989 by Dlugosz Software
- inter-task messages for multitasking system
- *****************************************************/
-
- #include "usual.hpp"
- #include "task.hpp"
- #include "sem.hpp"
- #include "mess.hpp"
-
- /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
-
- message::message()
- : s1(1), s2(0)
- {
- // nothing else to do
- }
-
- /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
-
- message::~message() {}
-
- /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
-
- bool message::put (void* p)
- {
- if (!s1--) return FALSE;
- /* wait my turn to get into the function body, and then prevent others
- from getting in after me */
- buf= p; //place message
- s2++; //give reader the go-ahead
- if (!s1--) return FALSE; //wait for return reciept
- s1++; //let next writer in to the function body
- return TRUE;
- }
-
- /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
-
- bool message::get (void** p)
- {
- if (!s2--) return FALSE; //wait for message to come in
- *p= buf;
- // note that this task still has exclusive access to the message.
- // you must call done() to let the next writer through.
- }
-