/*<html><pre>*/
#ifndef	V_SCHED_H
#define V_SCHED_H

typedef	void	(V_CALL	*thread_proc_t)(void *arg);
typedef void	*thread_t;
typedef void	*mutex_t;
typedef void	*cond_t;
typedef	void	*rwl_fifo_t;

#ifdef	__cplusplus
extern "C" {
#endif	/* __cplusplus */
	/*	Thread API ==================================================== */
	/*	Caller - side */
	thread_t	V_GLOBAL	threadCreate(thread_proc_t start_address,
		void *arg);
	/*	Waits for thread termination */
	vboolean	V_GLOBAL	threadJoin(thread_t thread,u32_t *exit_code);
	/*	Thread - side (call is NOT necessary; if thread routine returns, 
	 *	zero exit code assumed) */
	void		V_GLOBAL	threadExit(u32_t exit_code);
	/*	Returns true if given thread is running */
	vboolean	V_GLOBAL	threadIsLive(thread_t thread);
	/*	Yields control to another thread / process */
	void		V_GLOBAL	schedYield(void);
    /*	TSD key management */
    u32_t		V_GLOBAL	threadCreateKey(void);
    void		V_GLOBAL	threadDestroyKey(u32_t key);
    /*	TSD management */
	void		V_GLOBAL	threadSetSpecific(u32_t key,void_p specific);
	void_p		V_GLOBAL	threadGetSpecific(u32_t key);
	/*
	 *	Returns 'true' if library works in single-threaded mode
	 *	(i.e. if there is only one thread - caller thread).
	 */
	vboolean	V_GLOBAL	libvSafeThread(void);
	/*	Mutex API ===================================================== */
	/*	Creates new mutex */
	mutex_t		V_GLOBAL	mutexCreate();
	/*	Aquires mutex (warning: BLOCKING call !) */
	void		V_GLOBAL	mutexLock(mutex_t mutex);
	/*	Returns 'true' if mutex is aquired, otherwise immidiately 
	 *	returns 'false' */
	vboolean	V_GLOBAL	mutexTryLock(mutex_t mutex);
	/*	Relases mutex */
	void		V_GLOBAL	mutexUnlock(mutex_t mutex);
	/*	Destroys mutex object */
	void		V_GLOBAL	mutexDestroy(mutex_t mutex);
	/*	Conditional variables API ===================================== */
	/*	Creates new condvar; if 'autoreset' == false than condvar must be
	 *	reset explicitly before condWait() */
	cond_t		V_GLOBAL	condCreate(vboolean autoreset);
	/*	Sets manual-reset condvar to TRUE and releases all waiting 
	 *	threads. */
	vboolean	V_GLOBAL	condSet(cond_t cond);
	/*	Sets condvar to FALSE. Does nothing for autoreset condvar. */
	vboolean	V_GLOBAL	condReset(cond_t cond);
	/*	Releases all waiting threads, but doesn't sets condvar to TRUE;
	 *	in case of autoreset condvar, _should be_ same as condSet()
	 * _but_ thit is not true now al least for Win32 - BUGBUG
	 */
	vboolean	V_GLOBAL	condPulse(cond_t cond);
	/*	Blocks until condvar set to TRUE */
	vboolean	V_GLOBAL	condWait(cond_t cond);
	/*	Blocks until condvar set to TRUE or timeout reached; in case
	 *	of error / timeout returns false. */
	vboolean	V_GLOBAL	condTimedWait(cond_t cond,u32_t milliseconds);
	/*	Destroys conditional variable */
	void		V_GLOBAL	condDestroy(cond_t cond);
	/*	Thread-safe FIFO's ============================================ */
	rwl_fifo_t	V_GLOBAL	rwlCreate(void);
	void		V_GLOBAL	rwlDestroy(rwl_fifo_t fifo);
	/*	Sets blocking mode:
	 *		- 	'blockable'==true: rwlPopBuffer() will block until at least
	 *			'len' data available, or until fifo destroyed from another
	 *			thread (in such case rwlPopBuffer() may return value less
	 *			than 'len').
	 *		- 	'blockable'==false: rwlPopBuffer() will not block, but
	 *			immediately return all data available in FIFO.
	 */
	void		V_GLOBAL	rwlBlockMode(rwl_fifo_t fifo,vboolean blockable);
	/*	Adds 'len' bytes from 'buf' to FIFO. */
	void		V_GLOBAL	rwlPushBuffer(rwl_fifo_t fifo,void *buf,u32_t len);
	/* Returns number of bytes stored in 'buf' (can be less than 'len'). */
	u32_t		V_GLOBAL	rwlPopBuffer(rwl_fifo_t fifo,void *buf,u32_t len);
	/* Returns number of bytes available for rwlPopBuffer()'ing. */
	u32_t		V_GLOBAL	rwlCount(rwl_fifo_t fifo);
#ifdef	__cplusplus
}
#endif	/* __cplusplus */

#endif	/* V_SCHED_H */
/*</pre></html>*/
/*EOF*/
