Multiple thread can block on an event.

This commit is contained in:
steve 2000-04-12 01:53:07 +00:00
parent 8dbd64121f
commit b0d0cdbd7d
3 changed files with 28 additions and 7 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: vvm_pevent.cc,v 1.6 2000/04/10 05:26:07 steve Exp $"
#ident "$Id: vvm_pevent.cc,v 1.7 2000/04/12 01:53:07 steve Exp $"
#endif
# include "vvm.h"
@ -31,15 +31,21 @@ vvm_sync::vvm_sync()
void vvm_sync::wait(vvm_thread*thr)
{
assert(hold_ == 0);
assert(thr->sync_back_ == 0);
thr->sync_next_ = hold_;
thr->sync_back_ = this;
hold_ = thr;
}
void vvm_sync::wakeup()
{
while (hold_) {
vvm_thread*tmp = hold_;
hold_ = 0;
if (tmp) tmp->thread_yield();
hold_ = tmp->sync_next_;
assert(tmp->sync_back_ == 0);
tmp->sync_back_ = 0;
tmp->thread_yield();
}
}
@ -130,6 +136,9 @@ void vvm_anyedge::take_value(unsigned key, vpip_bit_t val)
/*
* $Log: vvm_pevent.cc,v $
* Revision 1.7 2000/04/12 01:53:07 steve
* Multiple thread can block on an event.
*
* Revision 1.6 2000/04/10 05:26:07 steve
* All events now use the NetEvent class.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: vvm_thread.cc,v 1.4 2000/02/23 02:56:57 steve Exp $"
#ident "$Id: vvm_thread.cc,v 1.5 2000/04/12 01:53:07 steve Exp $"
#endif
# include "vvm.h"
@ -39,6 +39,8 @@ class delay_event : public vvm_event {
vvm_thread::vvm_thread()
{
sync_next_ = 0;
sync_back_ = 0;
thread_yield();
}
@ -54,6 +56,9 @@ void vvm_thread::thread_yield(unsigned long delay)
/*
* $Log: vvm_thread.cc,v $
* Revision 1.5 2000/04/12 01:53:07 steve
* Multiple thread can block on an event.
*
* Revision 1.4 2000/02/23 02:56:57 steve
* Macintosh compilers do not support ident.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: vvm_thread.h,v 1.5 2000/02/23 02:56:57 steve Exp $"
#ident "$Id: vvm_thread.h,v 1.6 2000/04/12 01:53:07 steve Exp $"
#endif
# include "vvm.h"
@ -33,6 +33,7 @@
* future.
*/
class vvm_sync;
class vvm_thread {
public:
@ -46,10 +47,16 @@ class vvm_thread {
// will return false if it is ready to give up the CPU.
virtual bool go() =0;
// The sync class uses this to list all the threads blocked on it.
vvm_sync*sync_back_;
vvm_thread*sync_next_;
};
/*
* $Log: vvm_thread.h,v $
* Revision 1.6 2000/04/12 01:53:07 steve
* Multiple thread can block on an event.
*
* Revision 1.5 2000/02/23 02:56:57 steve
* Macintosh compilers do not support ident.
*