/**
*** static char cvs_id[] = "$Id: xthreads,v 1.7 2004/02/17 06:01:57 gvaraksi Exp $";
***
**/
#ifndef _XTHREADS
#define _XTHREADS
#include <xstddef>
#include <yvals.h>

_STD_BEGIN

		// CLASS _Atomic_counter
class _Atomic_counter
	{

public:
	_Atomic_counter() : _Counter(0) {}
	_Atomic_counter(const long &_Val) : _Counter(_Val) {}
	long operator++() _THROW0();
	long operator--() _THROW0();

	operator long() const _THROW0()
	{
		return _Counter;
	}
	
protected:
	long _Counter;
	};

////////// moved from yvals.h

		// CLASS _Lockit
class _Lockit
	{	// lock while object in existence -- MUST NEST
public:

  #if !_MULTI_THREAD
   #define _LOCKIT(x)

	explicit _Lockit()
		{	// do nothing
		}

	explicit _Lockit(int)
		{	// do nothing
		}

	~_Lockit()
		{	// do nothing
		}

  #else /* _MULTI_THREAD */
   #define _LOCKIT(x)	lockit x

	explicit _Lockit()
		: _Locktype(_LOCK_MALLOC)
		{	// set default lock
		_MAYBE_LOCK
			_Locksyslock(_Locktype);
		}

	explicit _Lockit(int _Type)
		: _Locktype(_Type)
		{	// set the lock
		_MAYBE_LOCK
			_Locksyslock(_Locktype);
		}

	~_Lockit()
		{	// clear the lock
		_MAYBE_LOCK
			_Unlocksyslock(_Locktype);
		}

private:
	int _Locktype;
  #endif /* _MULTI_THREAD */

private:
	_Lockit(const _Lockit&);			// not defined
	_Lockit& operator=(const _Lockit&);	// not defined
	};

class _Mutex
	{	// lock under program control
public:
	_Mutex();
	~_Mutex();

  #if !_MULTI_THREAD || !_IOSTREAM_OP_LOCKS
    void _Lock()
		{	// do nothing
		}

	void _Unlock()
		{	// do nothing
	}

  #else /* !_MULTI_THREAD || !_IOSTREAM_OP_LOCKS */
	void _Lock();
	void _Unlock();

private:
	_Mutex(const _Mutex&);				// not defined
	_Mutex& operator=(const _Mutex&);	// not defined
	void *_Mtx;
  #endif /* !_MULTI_THREAD || !_IOSTREAM_OP_LOCKS */

	};
_STD_END

///////////////////////////// end moved from yvals.h
#endif /* _XTHREADS */

/*
 * Copyright (c) 1992-2003 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V4.02:1161 */
