/*++
"This software program is available to you under a choice of one of two
licenses.  You may choose to be licensed under either the GNU General Public
License (GPL) Version 2, June 1991, available at
http://www.fsf.org/copyleft/gpl.html, or the Intel BSD + Patent License,
the text of which follows:

"Recipient" has requested a license and Intel Corporation ("Intel") is willing
to grant a license for the software entitled InfiniBand(tm) System Software
(the "Software") being provided by Intel Corporation.

The following definitions apply to this License:

"Licensed Patents" means patent claims licensable by Intel Corporation which
are necessarily infringed by the use or sale of the Software alone or when
combined with the operating system referred to below.

"Recipient" means the party to whom Intel delivers this Software.
"Licensee" means Recipient and those third parties that receive a license to
any operating system available under the GNU Public License version 2.0 or
later.

Copyright (c) 1996-2003 Intel Corporation. All rights reserved.

The license is provided to Recipient and Recipient's Licensees under the
following terms.

Redistribution and use in source and binary forms of the Software, with or
without modification, are permitted provided that the following conditions are
met:
Redistributions of source code of the Software may retain the above copyright
notice, this list of conditions and the following disclaimer.

Redistributions in binary form of the Software may reproduce the above
copyright notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

Neither the name of Intel Corporation nor the names of its contributors shall
be used to endorse or promote products derived from this Software without
specific prior written permission.

Intel hereby grants Recipient and Licensees a non-exclusive, worldwide,
royalty-free patent license under Licensed Patents to make, use, sell, offer
to sell, import and otherwise transfer the Software, if any, in source code
and object code form. This license shall include changes to the Software that
are error corrections or other minor changes to the Software that do not add
functionality or features when the Software is incorporated in any version of
a operating system that has been distributed under the GNU General Public
License 2.0 or later.  This patent license shall apply to the combination of
the Software and any operating system licensed under the GNU Public License
version 2.0 or later if, at the time Intel provides the Software to Recipient,
such addition of the Software to the then publicly available versions of such
operating system available under the GNU Public License version 2.0 or later
(whether in gold, beta or alpha form) causes such combination to be covered by
the Licensed Patents. The patent license shall not apply to any other
combinations which include the Software. No hardware per se is licensed
hereunder.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
--*/

/*
 * Abstract:
 *	Declaration of event abstraction.
 *
 * Environment:
 *	All
 *
 * $Revision: 1.1 $
 */

#ifndef _CL_EVENT_H_
#define _CL_EVENT_H_

/* Indicates that waiting on an event should never timeout */
#define EVENT_NO_TIMEOUT	0xFFFFFFFF

#include <complib/cl_event_osd.h>

/****h* Component Library/Event
* NAME
*	Event
*
* DESCRIPTION
*	The Event provides the ability to suspend and wakeup a thread.
*
*	The event functions operates on a cl_event_t structure which should be
*	treated as opaque and should be manipulated only through the provided
*	functions.
*
* SEE ALSO
*	Structures:
*		cl_event_t
*
*	Initialization/Destruction:
*		cl_event_construct, cl_event_init, cl_event_destroy
*
*	Manipulation:
*		cl_event_signal, cl_event_reset, cl_event_wait_on
*********/

#ifdef __cplusplus
extern "C" {
#endif

/****f* Component Library: Event/cl_event_construct
* NAME
*	cl_event_construct
*
* DESCRIPTION
*	The cl_event_construct function constructs an event.
*
* SYNOPSIS
*/
	void
	 cl_event_construct(IN cl_event_t * const p_event);
/*
* PARAMETERS
*	p_event
*		[in] Pointer to an cl_event_t structure to construct.
*
* RETURN VALUE
*	This function does not return a value.
*
* NOTES
*	Allows calling cl_event_destroy without first calling cl_event_init.
*
*	Calling cl_event_construct is a prerequisite to calling any other event
*	function except cl_event_init.
*
* SEE ALSO
*	Event, cl_event_init, cl_event_destroy
*********/

/****f* Component Library: Event/cl_event_init
* NAME
*	cl_event_init
*
* DESCRIPTION
*	The cl_event_init function initializes an event for use.
*
* SYNOPSIS
*/
	 cl_status_t
	    cl_event_init(IN cl_event_t * const p_event,
			  IN const boolean_t manual_reset);
/*
* PARAMETERS
*	p_event
*		[in] Pointer to an cl_event_t structure to initialize.
*
*	manual_reset
*		[in] If FALSE, indicates that the event resets itself after releasing
*		a single waiter.  If TRUE, the event remains in the signalled state
*		until explicitly reset by a call to cl_event_reset.
*
* RETURN VALUES
*	CL_SUCCESS if event initialization succeeded.
*
*	CL_ERROR otherwise.
*
* NOTES
*	Allows calling event manipulation functions, such as cl_event_signal,
*	cl_event_reset, and cl_event_wait_on.
*
*	The event is initially in a reset state.
*
* SEE ALSO
*	Event, cl_event_construct, cl_event_destroy, cl_event_signal,
*	cl_event_reset, cl_event_wait_on
*********/

/****f* Component Library: Event/cl_event_destroy
* NAME
*	cl_event_destroy
*
* DESCRIPTION
*	The cl_event_destroy function performs any necessary cleanup of an event.
*
* SYNOPSIS
*/
	void
	 cl_event_destroy(IN cl_event_t * const p_event);

/*
* PARAMETERS
*	p_event
*		[in] Pointer to an cl_event_t structure to destroy.
*
* RETURN VALUE
*	This function does not return a value.
*
* NOTES
*	This function should only be called after a call to cl_event_construct
*	or cl_event_init.
*
* SEE ALSO
*	Event, cl_event_construct, cl_event_init
*********/

/****f* Component Library: Event/cl_event_signal
* NAME
*	cl_event_signal
*
* DESCRIPTION
*	The cl_event_signal function sets an event to the signalled state and
*	releases at most one waiting thread.
*
* SYNOPSIS
*/
	 cl_status_t cl_event_signal(IN cl_event_t * const p_event);
/*
* PARAMETERS
*	p_event
*		[in] Pointer to an cl_event_t structure to set.
*
* RETURN VALUES
*	CL_SUCCESS if the event was successfully signalled.
*
*	CL_ERROR otherwise.
*
* NOTES
*	For auto-reset events, the event is reset automatically once a wait
*	operation is satisfied.
*
*	Triggering the event multiple times does not guarantee that the same
*	number of wait operations are satisfied. This is because events are
*	either in a signalled on non-signalled state, and triggering an event
*	that is already in the signalled state has no effect.
*
* SEE ALSO
*	Event, cl_event_reset, cl_event_wait_on
*********/

/****f* Component Library: Event/cl_event_reset
* NAME
*	cl_event_reset
*
* DESCRIPTION
*	The cl_event_reset function sets an event to the non-signalled state.
*
* SYNOPSIS
*/
	 cl_status_t cl_event_reset(IN cl_event_t * const p_event);
/*
* PARAMETERS
*	p_event
*		[in] Pointer to an cl_event_t structure to reset.
*
* RETURN VALUES
*	CL_SUCCESS if the event was successfully reset.
*
*	CL_ERROR otherwise.
*
* SEE ALSO
*	Event, cl_event_signal, cl_event_wait_on
*********/

/****f* Component Library: Event/cl_event_wait_on
* NAME
*	cl_event_wait_on
*
* DESCRIPTION
*	The cl_event_wait_on function waits for the specified event to be
*	triggered for a minimum amount of time.
*
* SYNOPSIS
*/
	 cl_status_t
	    cl_event_wait_on(IN cl_event_t * const p_event,
			     IN const uint32_t wait_us,
			     IN const boolean_t interruptible);
/*
* PARAMETERS
*	p_event
*		[in] Pointer to an cl_event_t structure on which to wait.
*
*	wait_us
*		[in] Number of microseconds to wait.
*
*	interruptible
*		[in] Indicates whether the wait operation can be interrupted
*		by external signals.
*
* RETURN VALUES
*	CL_SUCCESS if the wait operation succeeded in response to the event
*	being set.
*
*	CL_TIMEOUT if the specified time period elapses.
*
*	CL_NOT_DONE if the wait was interrupted by an external signal.
*
*	CL_ERROR if the wait operation failed.
*
* NOTES
*	If wait_us is set to EVENT_NO_TIMEOUT, the function will wait until the
*	event is triggered and never timeout.
*
*	If the timeout value is zero, this function simply tests the state of
*	the event.
*
*	If the event is already on the signalled state at the time of the call
*	to cl_event_wait_on, the call completes immediately with CL_SUCCESS.
*
* SEE ALSO
*	Event, cl_event_signal, cl_event_reset
*********/

#ifdef __cplusplus
}				/* extern "C" */
#endif
#endif				/* _CL_EVENT_H_ */
