1*d6b92ffaSHans Petter Selasky /* 2*d6b92ffaSHans Petter Selasky * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved. 3*d6b92ffaSHans Petter Selasky * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved. 4*d6b92ffaSHans Petter Selasky * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. 5*d6b92ffaSHans Petter Selasky * 6*d6b92ffaSHans Petter Selasky * This software is available to you under a choice of one of two 7*d6b92ffaSHans Petter Selasky * licenses. You may choose to be licensed under the terms of the GNU 8*d6b92ffaSHans Petter Selasky * General Public License (GPL) Version 2, available from the file 9*d6b92ffaSHans Petter Selasky * COPYING in the main directory of this source tree, or the 10*d6b92ffaSHans Petter Selasky * OpenIB.org BSD license below: 11*d6b92ffaSHans Petter Selasky * 12*d6b92ffaSHans Petter Selasky * Redistribution and use in source and binary forms, with or 13*d6b92ffaSHans Petter Selasky * without modification, are permitted provided that the following 14*d6b92ffaSHans Petter Selasky * conditions are met: 15*d6b92ffaSHans Petter Selasky * 16*d6b92ffaSHans Petter Selasky * - Redistributions of source code must retain the above 17*d6b92ffaSHans Petter Selasky * copyright notice, this list of conditions and the following 18*d6b92ffaSHans Petter Selasky * disclaimer. 19*d6b92ffaSHans Petter Selasky * 20*d6b92ffaSHans Petter Selasky * - Redistributions in binary form must reproduce the above 21*d6b92ffaSHans Petter Selasky * copyright notice, this list of conditions and the following 22*d6b92ffaSHans Petter Selasky * disclaimer in the documentation and/or other materials 23*d6b92ffaSHans Petter Selasky * provided with the distribution. 24*d6b92ffaSHans Petter Selasky * 25*d6b92ffaSHans Petter Selasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26*d6b92ffaSHans Petter Selasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27*d6b92ffaSHans Petter Selasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28*d6b92ffaSHans Petter Selasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29*d6b92ffaSHans Petter Selasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30*d6b92ffaSHans Petter Selasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31*d6b92ffaSHans Petter Selasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32*d6b92ffaSHans Petter Selasky * SOFTWARE. 33*d6b92ffaSHans Petter Selasky * 34*d6b92ffaSHans Petter Selasky */ 35*d6b92ffaSHans Petter Selasky 36*d6b92ffaSHans Petter Selasky /* 37*d6b92ffaSHans Petter Selasky * Abstract: 38*d6b92ffaSHans Petter Selasky * Declaration of event abstraction. 39*d6b92ffaSHans Petter Selasky */ 40*d6b92ffaSHans Petter Selasky 41*d6b92ffaSHans Petter Selasky #ifndef _CL_EVENT_H_ 42*d6b92ffaSHans Petter Selasky #define _CL_EVENT_H_ 43*d6b92ffaSHans Petter Selasky 44*d6b92ffaSHans Petter Selasky /* Indicates that waiting on an event should never timeout */ 45*d6b92ffaSHans Petter Selasky #define EVENT_NO_TIMEOUT 0xFFFFFFFF 46*d6b92ffaSHans Petter Selasky 47*d6b92ffaSHans Petter Selasky #include <complib/cl_event_osd.h> 48*d6b92ffaSHans Petter Selasky 49*d6b92ffaSHans Petter Selasky #ifdef __cplusplus 50*d6b92ffaSHans Petter Selasky # define BEGIN_C_DECLS extern "C" { 51*d6b92ffaSHans Petter Selasky # define END_C_DECLS } 52*d6b92ffaSHans Petter Selasky #else /* !__cplusplus */ 53*d6b92ffaSHans Petter Selasky # define BEGIN_C_DECLS 54*d6b92ffaSHans Petter Selasky # define END_C_DECLS 55*d6b92ffaSHans Petter Selasky #endif /* __cplusplus */ 56*d6b92ffaSHans Petter Selasky 57*d6b92ffaSHans Petter Selasky BEGIN_C_DECLS 58*d6b92ffaSHans Petter Selasky /****h* Component Library/Event 59*d6b92ffaSHans Petter Selasky * NAME 60*d6b92ffaSHans Petter Selasky * Event 61*d6b92ffaSHans Petter Selasky * 62*d6b92ffaSHans Petter Selasky * DESCRIPTION 63*d6b92ffaSHans Petter Selasky * The Event provides the ability to suspend and wakeup a thread. 64*d6b92ffaSHans Petter Selasky * 65*d6b92ffaSHans Petter Selasky * The event functions operates on a cl_event_t structure which should be 66*d6b92ffaSHans Petter Selasky * treated as opaque and should be manipulated only through the provided 67*d6b92ffaSHans Petter Selasky * functions. 68*d6b92ffaSHans Petter Selasky * 69*d6b92ffaSHans Petter Selasky * SEE ALSO 70*d6b92ffaSHans Petter Selasky * Structures: 71*d6b92ffaSHans Petter Selasky * cl_event_t 72*d6b92ffaSHans Petter Selasky * 73*d6b92ffaSHans Petter Selasky * Initialization/Destruction: 74*d6b92ffaSHans Petter Selasky * cl_event_construct, cl_event_init, cl_event_destroy 75*d6b92ffaSHans Petter Selasky * 76*d6b92ffaSHans Petter Selasky * Manipulation: 77*d6b92ffaSHans Petter Selasky * cl_event_signal, cl_event_reset, cl_event_wait_on 78*d6b92ffaSHans Petter Selasky *********/ 79*d6b92ffaSHans Petter Selasky /****f* Component Library: Event/cl_event_construct 80*d6b92ffaSHans Petter Selasky * NAME 81*d6b92ffaSHans Petter Selasky * cl_event_construct 82*d6b92ffaSHans Petter Selasky * 83*d6b92ffaSHans Petter Selasky * DESCRIPTION 84*d6b92ffaSHans Petter Selasky * The cl_event_construct function constructs an event. 85*d6b92ffaSHans Petter Selasky * 86*d6b92ffaSHans Petter Selasky * SYNOPSIS 87*d6b92ffaSHans Petter Selasky */ 88*d6b92ffaSHans Petter Selasky void cl_event_construct(IN cl_event_t * const p_event); 89*d6b92ffaSHans Petter Selasky /* 90*d6b92ffaSHans Petter Selasky * PARAMETERS 91*d6b92ffaSHans Petter Selasky * p_event 92*d6b92ffaSHans Petter Selasky * [in] Pointer to an cl_event_t structure to construct. 93*d6b92ffaSHans Petter Selasky * 94*d6b92ffaSHans Petter Selasky * RETURN VALUE 95*d6b92ffaSHans Petter Selasky * This function does not return a value. 96*d6b92ffaSHans Petter Selasky * 97*d6b92ffaSHans Petter Selasky * NOTES 98*d6b92ffaSHans Petter Selasky * Allows calling cl_event_destroy without first calling cl_event_init. 99*d6b92ffaSHans Petter Selasky * 100*d6b92ffaSHans Petter Selasky * Calling cl_event_construct is a prerequisite to calling any other event 101*d6b92ffaSHans Petter Selasky * function except cl_event_init. 102*d6b92ffaSHans Petter Selasky * 103*d6b92ffaSHans Petter Selasky * SEE ALSO 104*d6b92ffaSHans Petter Selasky * Event, cl_event_init, cl_event_destroy 105*d6b92ffaSHans Petter Selasky *********/ 106*d6b92ffaSHans Petter Selasky 107*d6b92ffaSHans Petter Selasky /****f* Component Library: Event/cl_event_init 108*d6b92ffaSHans Petter Selasky * NAME 109*d6b92ffaSHans Petter Selasky * cl_event_init 110*d6b92ffaSHans Petter Selasky * 111*d6b92ffaSHans Petter Selasky * DESCRIPTION 112*d6b92ffaSHans Petter Selasky * The cl_event_init function initializes an event for use. 113*d6b92ffaSHans Petter Selasky * 114*d6b92ffaSHans Petter Selasky * SYNOPSIS 115*d6b92ffaSHans Petter Selasky */ 116*d6b92ffaSHans Petter Selasky cl_status_t 117*d6b92ffaSHans Petter Selasky cl_event_init(IN cl_event_t * const p_event, IN const boolean_t manual_reset); 118*d6b92ffaSHans Petter Selasky /* 119*d6b92ffaSHans Petter Selasky * PARAMETERS 120*d6b92ffaSHans Petter Selasky * p_event 121*d6b92ffaSHans Petter Selasky * [in] Pointer to an cl_event_t structure to initialize. 122*d6b92ffaSHans Petter Selasky * 123*d6b92ffaSHans Petter Selasky * manual_reset 124*d6b92ffaSHans Petter Selasky * [in] If FALSE, indicates that the event resets itself after releasing 125*d6b92ffaSHans Petter Selasky * a single waiter. If TRUE, the event remains in the signalled state 126*d6b92ffaSHans Petter Selasky * until explicitly reset by a call to cl_event_reset. 127*d6b92ffaSHans Petter Selasky * 128*d6b92ffaSHans Petter Selasky * RETURN VALUES 129*d6b92ffaSHans Petter Selasky * CL_SUCCESS if event initialization succeeded. 130*d6b92ffaSHans Petter Selasky * 131*d6b92ffaSHans Petter Selasky * CL_ERROR otherwise. 132*d6b92ffaSHans Petter Selasky * 133*d6b92ffaSHans Petter Selasky * NOTES 134*d6b92ffaSHans Petter Selasky * Allows calling event manipulation functions, such as cl_event_signal, 135*d6b92ffaSHans Petter Selasky * cl_event_reset, and cl_event_wait_on. 136*d6b92ffaSHans Petter Selasky * 137*d6b92ffaSHans Petter Selasky * The event is initially in a reset state. 138*d6b92ffaSHans Petter Selasky * 139*d6b92ffaSHans Petter Selasky * SEE ALSO 140*d6b92ffaSHans Petter Selasky * Event, cl_event_construct, cl_event_destroy, cl_event_signal, 141*d6b92ffaSHans Petter Selasky * cl_event_reset, cl_event_wait_on 142*d6b92ffaSHans Petter Selasky *********/ 143*d6b92ffaSHans Petter Selasky 144*d6b92ffaSHans Petter Selasky /****f* Component Library: Event/cl_event_destroy 145*d6b92ffaSHans Petter Selasky * NAME 146*d6b92ffaSHans Petter Selasky * cl_event_destroy 147*d6b92ffaSHans Petter Selasky * 148*d6b92ffaSHans Petter Selasky * DESCRIPTION 149*d6b92ffaSHans Petter Selasky * The cl_event_destroy function performs any necessary cleanup of an event. 150*d6b92ffaSHans Petter Selasky * 151*d6b92ffaSHans Petter Selasky * SYNOPSIS 152*d6b92ffaSHans Petter Selasky */ 153*d6b92ffaSHans Petter Selasky void cl_event_destroy(IN cl_event_t * const p_event); 154*d6b92ffaSHans Petter Selasky 155*d6b92ffaSHans Petter Selasky /* 156*d6b92ffaSHans Petter Selasky * PARAMETERS 157*d6b92ffaSHans Petter Selasky * p_event 158*d6b92ffaSHans Petter Selasky * [in] Pointer to an cl_event_t structure to destroy. 159*d6b92ffaSHans Petter Selasky * 160*d6b92ffaSHans Petter Selasky * RETURN VALUE 161*d6b92ffaSHans Petter Selasky * This function does not return a value. 162*d6b92ffaSHans Petter Selasky * 163*d6b92ffaSHans Petter Selasky * NOTES 164*d6b92ffaSHans Petter Selasky * This function should only be called after a call to cl_event_construct 165*d6b92ffaSHans Petter Selasky * or cl_event_init. 166*d6b92ffaSHans Petter Selasky * 167*d6b92ffaSHans Petter Selasky * SEE ALSO 168*d6b92ffaSHans Petter Selasky * Event, cl_event_construct, cl_event_init 169*d6b92ffaSHans Petter Selasky *********/ 170*d6b92ffaSHans Petter Selasky 171*d6b92ffaSHans Petter Selasky /****f* Component Library: Event/cl_event_signal 172*d6b92ffaSHans Petter Selasky * NAME 173*d6b92ffaSHans Petter Selasky * cl_event_signal 174*d6b92ffaSHans Petter Selasky * 175*d6b92ffaSHans Petter Selasky * DESCRIPTION 176*d6b92ffaSHans Petter Selasky * The cl_event_signal function sets an event to the signalled state and 177*d6b92ffaSHans Petter Selasky * releases at most one waiting thread. 178*d6b92ffaSHans Petter Selasky * 179*d6b92ffaSHans Petter Selasky * SYNOPSIS 180*d6b92ffaSHans Petter Selasky */ 181*d6b92ffaSHans Petter Selasky cl_status_t cl_event_signal(IN cl_event_t * const p_event); 182*d6b92ffaSHans Petter Selasky /* 183*d6b92ffaSHans Petter Selasky * PARAMETERS 184*d6b92ffaSHans Petter Selasky * p_event 185*d6b92ffaSHans Petter Selasky * [in] Pointer to an cl_event_t structure to set. 186*d6b92ffaSHans Petter Selasky * 187*d6b92ffaSHans Petter Selasky * RETURN VALUES 188*d6b92ffaSHans Petter Selasky * CL_SUCCESS if the event was successfully signalled. 189*d6b92ffaSHans Petter Selasky * 190*d6b92ffaSHans Petter Selasky * CL_ERROR otherwise. 191*d6b92ffaSHans Petter Selasky * 192*d6b92ffaSHans Petter Selasky * NOTES 193*d6b92ffaSHans Petter Selasky * For auto-reset events, the event is reset automatically once a wait 194*d6b92ffaSHans Petter Selasky * operation is satisfied. 195*d6b92ffaSHans Petter Selasky * 196*d6b92ffaSHans Petter Selasky * Triggering the event multiple times does not guarantee that the same 197*d6b92ffaSHans Petter Selasky * number of wait operations are satisfied. This is because events are 198*d6b92ffaSHans Petter Selasky * either in a signalled on non-signalled state, and triggering an event 199*d6b92ffaSHans Petter Selasky * that is already in the signalled state has no effect. 200*d6b92ffaSHans Petter Selasky * 201*d6b92ffaSHans Petter Selasky * SEE ALSO 202*d6b92ffaSHans Petter Selasky * Event, cl_event_reset, cl_event_wait_on 203*d6b92ffaSHans Petter Selasky *********/ 204*d6b92ffaSHans Petter Selasky 205*d6b92ffaSHans Petter Selasky /****f* Component Library: Event/cl_event_reset 206*d6b92ffaSHans Petter Selasky * NAME 207*d6b92ffaSHans Petter Selasky * cl_event_reset 208*d6b92ffaSHans Petter Selasky * 209*d6b92ffaSHans Petter Selasky * DESCRIPTION 210*d6b92ffaSHans Petter Selasky * The cl_event_reset function sets an event to the non-signalled state. 211*d6b92ffaSHans Petter Selasky * 212*d6b92ffaSHans Petter Selasky * SYNOPSIS 213*d6b92ffaSHans Petter Selasky */ 214*d6b92ffaSHans Petter Selasky cl_status_t cl_event_reset(IN cl_event_t * const p_event); 215*d6b92ffaSHans Petter Selasky /* 216*d6b92ffaSHans Petter Selasky * PARAMETERS 217*d6b92ffaSHans Petter Selasky * p_event 218*d6b92ffaSHans Petter Selasky * [in] Pointer to an cl_event_t structure to reset. 219*d6b92ffaSHans Petter Selasky * 220*d6b92ffaSHans Petter Selasky * RETURN VALUES 221*d6b92ffaSHans Petter Selasky * CL_SUCCESS if the event was successfully reset. 222*d6b92ffaSHans Petter Selasky * 223*d6b92ffaSHans Petter Selasky * CL_ERROR otherwise. 224*d6b92ffaSHans Petter Selasky * 225*d6b92ffaSHans Petter Selasky * SEE ALSO 226*d6b92ffaSHans Petter Selasky * Event, cl_event_signal, cl_event_wait_on 227*d6b92ffaSHans Petter Selasky *********/ 228*d6b92ffaSHans Petter Selasky 229*d6b92ffaSHans Petter Selasky /****f* Component Library: Event/cl_event_wait_on 230*d6b92ffaSHans Petter Selasky * NAME 231*d6b92ffaSHans Petter Selasky * cl_event_wait_on 232*d6b92ffaSHans Petter Selasky * 233*d6b92ffaSHans Petter Selasky * DESCRIPTION 234*d6b92ffaSHans Petter Selasky * The cl_event_wait_on function waits for the specified event to be 235*d6b92ffaSHans Petter Selasky * triggered for a minimum amount of time. 236*d6b92ffaSHans Petter Selasky * 237*d6b92ffaSHans Petter Selasky * SYNOPSIS 238*d6b92ffaSHans Petter Selasky */ 239*d6b92ffaSHans Petter Selasky cl_status_t 240*d6b92ffaSHans Petter Selasky cl_event_wait_on(IN cl_event_t * const p_event, 241*d6b92ffaSHans Petter Selasky IN const uint32_t wait_us, IN const boolean_t interruptible); 242*d6b92ffaSHans Petter Selasky /* 243*d6b92ffaSHans Petter Selasky * PARAMETERS 244*d6b92ffaSHans Petter Selasky * p_event 245*d6b92ffaSHans Petter Selasky * [in] Pointer to an cl_event_t structure on which to wait. 246*d6b92ffaSHans Petter Selasky * 247*d6b92ffaSHans Petter Selasky * wait_us 248*d6b92ffaSHans Petter Selasky * [in] Number of microseconds to wait. 249*d6b92ffaSHans Petter Selasky * 250*d6b92ffaSHans Petter Selasky * interruptible 251*d6b92ffaSHans Petter Selasky * [in] Indicates whether the wait operation can be interrupted 252*d6b92ffaSHans Petter Selasky * by external signals. 253*d6b92ffaSHans Petter Selasky * 254*d6b92ffaSHans Petter Selasky * RETURN VALUES 255*d6b92ffaSHans Petter Selasky * CL_SUCCESS if the wait operation succeeded in response to the event 256*d6b92ffaSHans Petter Selasky * being set. 257*d6b92ffaSHans Petter Selasky * 258*d6b92ffaSHans Petter Selasky * CL_TIMEOUT if the specified time period elapses. 259*d6b92ffaSHans Petter Selasky * 260*d6b92ffaSHans Petter Selasky * CL_NOT_DONE if the wait was interrupted by an external signal. 261*d6b92ffaSHans Petter Selasky * 262*d6b92ffaSHans Petter Selasky * CL_ERROR if the wait operation failed. 263*d6b92ffaSHans Petter Selasky * 264*d6b92ffaSHans Petter Selasky * NOTES 265*d6b92ffaSHans Petter Selasky * If wait_us is set to EVENT_NO_TIMEOUT, the function will wait until the 266*d6b92ffaSHans Petter Selasky * event is triggered and never timeout. 267*d6b92ffaSHans Petter Selasky * 268*d6b92ffaSHans Petter Selasky * If the timeout value is zero, this function simply tests the state of 269*d6b92ffaSHans Petter Selasky * the event. 270*d6b92ffaSHans Petter Selasky * 271*d6b92ffaSHans Petter Selasky * If the event is already on the signalled state at the time of the call 272*d6b92ffaSHans Petter Selasky * to cl_event_wait_on, the call completes immediately with CL_SUCCESS. 273*d6b92ffaSHans Petter Selasky * 274*d6b92ffaSHans Petter Selasky * SEE ALSO 275*d6b92ffaSHans Petter Selasky * Event, cl_event_signal, cl_event_reset 276*d6b92ffaSHans Petter Selasky *********/ 277*d6b92ffaSHans Petter Selasky 278*d6b92ffaSHans Petter Selasky END_C_DECLS 279*d6b92ffaSHans Petter Selasky #endif /* _CL_EVENT_H_ */ 280