| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2009, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bkni_event_group.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/4 $ |
|---|
| 12 | * $brcm_Date: 4/27/09 11:36a $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Implementatation of the Magnum KNI for user space Linux applications. |
|---|
| 17 | * |
|---|
| 18 | * Revision History: |
|---|
| 19 | * |
|---|
| 20 | * $brcm_Log: /magnum/basemodules/kni/linuxuser/bkni_event_group.h $ * |
|---|
| 21 | * |
|---|
| 22 | * Hydra_Software_Devel/4 4/27/09 11:36a haisongw |
|---|
| 23 | * PR54625:support C++ compiler in bkni_event_group.h |
|---|
| 24 | * |
|---|
| 25 | * Hydra_Software_Devel/3 2/26/04 12:29p erickson |
|---|
| 26 | * PR9736: fixed comment |
|---|
| 27 | * |
|---|
| 28 | * Hydra_Software_Devel/2 2/26/04 12:21p erickson |
|---|
| 29 | * PR9736: updated comments |
|---|
| 30 | * |
|---|
| 31 | * Hydra_Software_Devel/1 2/11/04 10:52p vsilyaev |
|---|
| 32 | * PR 9736: API for event multiplexing |
|---|
| 33 | * |
|---|
| 34 | ***************************************************************************/ |
|---|
| 35 | #ifndef BKNI_EVENT_GROUP_H_ |
|---|
| 36 | #define BKNI_EVENT_GROUP_H_ |
|---|
| 37 | |
|---|
| 38 | #include "bkni_multi.h" |
|---|
| 39 | |
|---|
| 40 | /*=************************************************************************* |
|---|
| 41 | Summary: |
|---|
| 42 | The event group implements event multiplexing. An application |
|---|
| 43 | can group multiple events and then wait in the single thread any of these |
|---|
| 44 | events to be set. |
|---|
| 45 | |
|---|
| 46 | The BKNI_EventGroup kernel interface is an optional component of the kernel interface. |
|---|
| 47 | It shall not be used by the porting interface, base modules or common utilites. |
|---|
| 48 | It is only for application needs. |
|---|
| 49 | |
|---|
| 50 | Example: |
|---|
| 51 | #include "bkni_event_group.h" |
|---|
| 52 | |
|---|
| 53 | ... |
|---|
| 54 | BKNI_EventHandle event1, event2; |
|---|
| 55 | BKNI_EventHandle events[2]; |
|---|
| 56 | unsigned nevents; |
|---|
| 57 | |
|---|
| 58 | BKNI_EventGroupHandle group; |
|---|
| 59 | |
|---|
| 60 | BKNI_CreateEvent(&event1); |
|---|
| 61 | BKNI_CreateEvent(&event2); |
|---|
| 62 | |
|---|
| 63 | BKNI_CreateEventGroup(&group); |
|---|
| 64 | |
|---|
| 65 | BKNI_AddEventGroup(group, event1); |
|---|
| 66 | BKNI_AddEventGroup(group, event2); |
|---|
| 67 | |
|---|
| 68 | BKNI_WaitForGroup(group, 1000, events, 2, &nevents); |
|---|
| 69 | |
|---|
| 70 | printf("Got %d events", nevents); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | ****************************************************************************/ |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | /************************************************************************** |
|---|
| 77 | Summary: |
|---|
| 78 | Event group handle |
|---|
| 79 | **************************************************************************/ |
|---|
| 80 | typedef struct BKNI_GroupObj *BKNI_EventGroupHandle; |
|---|
| 81 | #ifdef __cplusplus |
|---|
| 82 | extern "C" { |
|---|
| 83 | #endif |
|---|
| 84 | |
|---|
| 85 | /************************************************************************** |
|---|
| 86 | Summary: |
|---|
| 87 | This function is used to create a new event group |
|---|
| 88 | |
|---|
| 89 | Description: |
|---|
| 90 | This function create a new evetn group |
|---|
| 91 | |
|---|
| 92 | Returns: |
|---|
| 93 | BERR_SUCCESS - Event groupt was created successfully. |
|---|
| 94 | BERR_OS_ERROR - The system failed and group wasn't created |
|---|
| 95 | **************************************************************************/ |
|---|
| 96 | BERR_Code BKNI_CreateEventGroup( |
|---|
| 97 | BKNI_EventGroupHandle *pGroup |
|---|
| 98 | ); |
|---|
| 99 | |
|---|
| 100 | /************************************************************************** |
|---|
| 101 | Summary: |
|---|
| 102 | This function is used to destroy an event group |
|---|
| 103 | |
|---|
| 104 | Description: |
|---|
| 105 | This function destroy a new evetn group. |
|---|
| 106 | Note: application shall not be inside BKNI_WaitForGroup while calling this function. |
|---|
| 107 | |
|---|
| 108 | Returns: |
|---|
| 109 | N/A |
|---|
| 110 | **************************************************************************/ |
|---|
| 111 | void BKNI_DestroyEventGroup( |
|---|
| 112 | BKNI_EventGroupHandle group |
|---|
| 113 | ); |
|---|
| 114 | |
|---|
| 115 | /************************************************************************** |
|---|
| 116 | Summary: |
|---|
| 117 | This function is used to add an event into the event group |
|---|
| 118 | |
|---|
| 119 | Description: |
|---|
| 120 | This function adds an event into the event group. If event is already |
|---|
| 121 | set off, active BKNI_WaitForGroup would be woken up immediatly. |
|---|
| 122 | |
|---|
| 123 | Note: Event could belong only to the one group at the time. |
|---|
| 124 | |
|---|
| 125 | Returns: |
|---|
| 126 | BERR_SUCCESS - Event was added into the group successfully |
|---|
| 127 | BERR_OS_ERROR - The system failed and event wasn't added |
|---|
| 128 | **************************************************************************/ |
|---|
| 129 | BERR_Code |
|---|
| 130 | BKNI_AddEventGroup( |
|---|
| 131 | BKNI_EventGroupHandle group, /* Event group */ |
|---|
| 132 | BKNI_EventHandle event /* Event to add into the group */ |
|---|
| 133 | ); |
|---|
| 134 | |
|---|
| 135 | /************************************************************************** |
|---|
| 136 | Summary: |
|---|
| 137 | This function is used to remove an event from the event group |
|---|
| 138 | |
|---|
| 139 | Description: |
|---|
| 140 | This function removes to event from the event group |
|---|
| 141 | |
|---|
| 142 | Returns: |
|---|
| 143 | BERR_SUCCESS - Event was removed from the group successfully |
|---|
| 144 | BERR_OS_ERROR - The system failed and the group state is unspecified |
|---|
| 145 | **************************************************************************/ |
|---|
| 146 | BERR_Code |
|---|
| 147 | BKNI_RemoveEventGroup( |
|---|
| 148 | BKNI_EventGroupHandle group, /* Event group */ |
|---|
| 149 | BKNI_EventHandle event /* Event to remove from the group */ |
|---|
| 150 | ); |
|---|
| 151 | |
|---|
| 152 | /************************************************************************** |
|---|
| 153 | Summary: |
|---|
| 154 | This function is used to wait for the any event from the group. |
|---|
| 155 | |
|---|
| 156 | Description: |
|---|
| 157 | This function waits for the any event from the group. This function |
|---|
| 158 | could exit either because of timeout, or when some event[s] are set. |
|---|
| 159 | In the latter case it would save the number of events and events themselves in |
|---|
| 160 | the events structure. |
|---|
| 161 | After the event is saved in the user specified area, the event is cleared out. |
|---|
| 162 | |
|---|
| 163 | Returns: |
|---|
| 164 | BERR_SUCCESS - Event was removed from the group successfully |
|---|
| 165 | BERR_OS_ERROR - The system failed and the group state is unspecified |
|---|
| 166 | **************************************************************************/ |
|---|
| 167 | BERR_Code |
|---|
| 168 | BKNI_WaitForGroup( |
|---|
| 169 | BKNI_EventGroupHandle group, /* event group */ |
|---|
| 170 | int timeoutMsec, /* timeout in milliseconds, use BKNI_INFINITE to wait without timeout */ |
|---|
| 171 | BKNI_EventHandle *events, /* [out] pass out the events that were triggered |
|---|
| 172 | (specified by *nevents) */ |
|---|
| 173 | unsigned max_events, /* the maximum number of events which can be passed out using |
|---|
| 174 | the events parameter. Generally this should be equal to the |
|---|
| 175 | number of events in the BKNI_EventGroup. */ |
|---|
| 176 | unsigned *nevents /* [out] number of events which were stored in the user specified area */ |
|---|
| 177 | ); |
|---|
| 178 | |
|---|
| 179 | #ifdef __cplusplus |
|---|
| 180 | } |
|---|
| 181 | #endif |
|---|
| 182 | #endif /* BKNI_EVENT_GROUP_H_ */ |
|---|
| 183 | |
|---|
| 184 | |
|---|