home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1996 November
/
VPR9611B.ISO
/
vabasic
/
ntclnt.exe
/
DISK8
/
data.8
/
datab
/
INCLUDE
/
NOMT.HH
< prev
next >
Wrap
Text File
|
1996-07-29
|
6KB
|
181 lines
//==========================================================================//
// $Source: /rcs/crcs/general/nomt.hh,v $
// Checked in by: $Author: alaind $
// $Date: 1996/04/17 17:50:55 $
// $Revision: 1.3 $
//--------------------------------------------------------------------------//
// //
// Copyright (c) 1995, Visual Edge Software Ltd. //
// //
// All rights reserved. This notice is intended as a precaution //
// against inadvertent publication, and shall not be deemed to con- //
// stitute an acknowledgment that publication has occurred nor to //
// imply any waiver of confidentiality. The year included in the //
// notice is the year of the creation of the work. //
// //
//----------------------------------------------------------------------------
// DESCRIPTION:
//
// VeThread is a class which manage threads in a multithread environment.
// A Thread have a state and a priority.
// Create a thread with the constructor, just initialize some properties.
// The Start method create the real system thread and keep a pointer on it.
// A thread can also suspend is execution and Resume it.
//
// VeThreadEvent manage events on threads. An event is used to synchronize
// the threads. An event have two state: signaled and unsignaled.
// When the event is nsignaled, all the thread blocked on this event,
// will wait until the event be signaled. The event is signaled by an other
// thread when a specific condition is satisfied.
//
// VeLock is a class that is used to synchronize threads who shared the same
// data. It is done by locking a code section, and this allow only one thread
// to execute the code in this section. As long the lock is own by a thread
// all others threads who want to access the same code section will be waiting
//
// VeLock can be overlapped. If in the same code section a VeLock is locked
// many times (overlapped locks)a, while all the lock acquired are not
// released, the VeLock will still locked.
// If a thread ends, all the locks locked by this thread will be unlocked.
//
// VeAutoLock is a class that assures a locked VeLock object that it will be
// unlocked. This is done by using the destructor which do the unlock
// operation.
//
// VeRefCnt is a thread-safe reference counting class. The increment and
// decrement of the object are atomic, because they use a mecanism for
// synchronizing access to a variable that is shared by multiple threads.
//
// Note: This file is for non multithread support plateform.
// It should be included only by vthread.hh
//==========================================================================//
#ifndef NOMT_HH
#define NOMT_HH
//=========================================================================
// VeThread - A thread class
//-------------------------------------------------------------------------
VCLASS VeThread : public VeDllBasedClass
{
public:
VOPERDECL VeThread();
VOPERDECL ~VeThread();
VMETHODDECL(status_t) Start( VTThreadFunction startRoutine,
void *arg,
bool_t suspended,
long stackSize=0);
VMETHODDECL(status_t) Stop();
VMETHODDECL(status_t) PutPriority(VTThreadPriority newPrio);
VMETHODDECL(VTThreadPriority) Priority();
VMETHODDECL(VTThreadState) State();
VMETHODDECL(status_t) Suspend();
VMETHODDECL(status_t) Resume();
};
//=========================================================================
// VeThreadEvent - A event thread class
//-------------------------------------------------------------------------
VCLASS VeThreadEvent : public VeDllBasedClass
{
public:
VOPERDECL VeThreadEvent();
VOPERDECL ~VeThreadEvent();
VMETHODDECL(status_t) Wait();
VMETHODDECL(status_t) Trigger();
};
//=========================================================================
// VeLock - A thread locking class
//-------------------------------------------------------------------------
VCLASS VeLock : public VeDllBasedClass
{
public:
VINLINEDECL(status_t) Acquire();
VINLINEDECL(status_t) Release();
};
//=========================================================================
// VeAutoLock - A thread Auto-locking class
//-------------------------------------------------------------------------
VCLASS VeAutoLock : public VeDllBasedClass
{
public:
VINLINEOPERDECL VeAutoLock(VeLock& );
VINLINEOPERDECL VeAutoLock(VeLock* );
};
//=========================================================================
// VeRefCount - A thread-safe reference counting class
//-------------------------------------------------------------------------
VCLASS VeRefCount : public VeDllBasedClass
{
public:
VINLINEOPERDECL VeRefCount();
VINLINEDECL(void) operator++();
VINLINEDECL(void) operator++(int);
VINLINEDECL(bool_t) operator--();
VINLINEDECL(void) operator--(int);
VINLINEDECL(bool_t) IsReferenced();
VINLINEDECL(void) Initialize(long value);
VINLINEDECL(long) Value();
private:
long itsValue;
};
//-------------------------------------------------------------------------
// inline methods
//-------------------------------------------------------------------------
VINLINEDEF(status_t) VeLock::Acquire()
{ return OKStatus; }
VINLINEDEF(status_t) VeLock::Release()
{ return OKStatus; }
VINLINEOPERDEF VeAutoLock::VeAutoLock(VeLock& )
{}
VINLINEOPERDEF VeAutoLock::VeAutoLock(VeLock* )
{}
VINLINEOPERDEF VeRefCount::VeRefCount()
{ itsValue = 0; }
VINLINEDEF(void) VeRefCount::operator++()
{ ++itsValue; }
VINLINEDEF(void) VeRefCount::operator++(int)
{ itsValue++; }
VINLINEDEF(bool_t) VeRefCount::operator--()
{
--itsValue;
if (itsValue > 0) return TRUE;
else return FALSE;
}
VINLINEDEF(void) VeRefCount::operator--(int)
{ itsValue--; }
VINLINEDEF(bool_t) VeRefCount::IsReferenced()
{
if (itsValue > 0) return TRUE;
else return FALSE;
}
VINLINEDEF(void) VeRefCount::Initialize(long value)
{
itsValue = value;
}
VINLINEDEF(long) VeRefCount::Value()
{
return itsValue;
}
#endif // NOMT_HH