source: svn/trunk/newcon3bcm2_21bu/magnum/basemodules/kni/ucos_ii/bkni_multi.h

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 8.9 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2010, 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_multi.h $
11 * $brcm_Revision: Hydra_Software_Devel/1 $
12 * $brcm_Date: 8/19/10 8:09a $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/basemodules/kni/ucos_ii/bkni_multi.h $
19 *
20 * Hydra_Software_Devel/1   8/19/10 8:09a jfisher
21 * SW7572-49:  Add nesting check.
22 *
23 * Hydra_Software_Devel/19   4/8/03 4:47p erickson
24 * BKNI_ResetEvent now returns void
25 * Split BKNI_AcquireMutex into Acquire and TryAcquire
26 *
27 * Hydra_Software_Devel/18   4/4/03 12:24p erickson
28 * trying to fix list item
29 *
30 * Hydra_Software_Devel/17   4/4/03 12:22p erickson
31 * updated docs
32 *
33 * Hydra_Software_Devel/16   4/4/03 11:27a erickson
34 * updated documentation
35 *
36 * Hydra_Software_Devel/15   4/3/03 6:13p erickson
37 * some pre 0.9 api rework
38 *
39 * Hydra_Software_Devel/14   4/1/03 7:02p erickson
40 * updated comments
41 *
42 * Hydra_Software_Devel/13   4/1/03 3:16p erickson
43 * update AcquireMutex notes
44 *
45 * Hydra_Software_Devel/12   3/25/03 11:44a erickson
46 * Updated mutex commnets
47 *
48 * Hydra_Software_Devel/11   3/24/03 11:38a erickson
49 * reworked docs
50 *
51 * Hydra_Software_Devel/10   3/12/03 12:04p erickson
52 * updated return codes, comments
53 *
54 * Hydra_Software_Devel/9   3/11/03 6:59p erickson
55 * changed kernelinterface from using object ptrs to handles
56 *
57 * Hydra_Software_Devel/8   3/10/03 8:28p vsilyaev
58 * Added support for tagged kernel interface.
59 *
60 * Hydra_Software_Devel/7   3/10/03 6:37p vsilyaev
61 * Uses extern "C" { } brackets.
62 *
63 * Hydra_Software_Devel/6   3/10/03 2:35p vsilyaev
64 * Fixed the BKNI_TaskPriority enum.
65 *
66 * Hydra_Software_Devel/5   3/10/03 2:34p erickson
67 * expanded comments
68 *
69 * Hydra_Software_Devel/5   3/10/03 2:29p erickson
70 * updated docs
71 *
72 * Hydra_Software_Devel/5   3/10/03 12:36p erickson
73 * linuxkernel tasks initial implementationd
74 *
75 * Hydra_Software_Devel/3   3/7/03 5:20p erickson
76 * linux kernel interface work
77 *
78 * Hydra_Software_Devel/2   3/6/03 6:27p erickson
79 * rework KNI api
80 *
81 * Hydra_Software_Devel/1   3/5/03 5:16p erickson
82 * Initial kernelinterface work
83 *
84 ***************************************************************************/
85#ifndef BKNI_MULTI_H__
86#define BKNI_MULTI_H__
87
88#ifdef __cplusplus
89extern "C" {
90#endif
91
92/*=*************************************************************************
93The multi-tasking kernel interface can only be used by multi-tasking
94modules. In the Magnum architecture, this can only be SysLib modules.
95
96See bkni.h for a kernel interface overview.
97****************************************************************************/
98
99/***************************************************************************
100Summary:
101        BKNI_INFINITE can be passed as a timeout value into BKNI_WaitForEvent
102        for multi-threaded modules.
103****************************************************************************/
104#define BKNI_INFINITE -1
105
106/***************************************************************************
107Summary:
108        Mutex object initialized by BKNI_CreateMutex.
109****************************************************************************/
110typedef struct BKNI_MutexObj *BKNI_MutexHandle;
111
112/***************************************************************************
113Summary:
114        Create a mutex in an unacquired state.
115
116Description:
117        The mutex is returned in an unacquired state, which means that the first call
118        to BKNI_AcquireMutex or BKNI_TryAcquireMutex for that mutex is guaranteed to succeed immediately.
119
120        Note that there is no name parameter in BKNI_CreateMutex. We do not support named
121        mutexes because they are essentially global variables that can lead to deadlock.
122        Passing in a name for debugging purposes might lead to someone to think we
123        support named mutexes.
124
125Returns:
126        BERR_SUCCESS if the mutex is created.
127        BERR_OS_ERROR if mutex was not created.
128****************************************************************************/
129BERR_Code BKNI_CreateMutex(BKNI_MutexHandle *mutex);
130
131
132/***************************************************************************
133Summary:
134        Destroy a mutex.
135
136Description:
137        Destroying a mutex in an acquired state is not allowed and leads to undefined behavior.
138****************************************************************************/
139void BKNI_DestroyMutex(BKNI_MutexHandle mutex);
140
141
142/***************************************************************************
143Summary:
144        Try acquiring exclusive ownership of a mutex, but do not block.
145
146Description:
147        If no other task currently owns the mutex, BKNI_TryAcquireMutex will return
148        with BERR_SUCCESS and the caller retains exclusive ownership until
149        BKNI_ReleaseMutex is called for that mutex.
150
151        If another task currently owns the mutex, BKNI_TryAcquireMutex will not block
152        but will return immediately with BERR_TIMEOUT.
153
154        Magnum code cannot nest calls to BKNI_TryAcquireMutex or BKNI_AcquireMutex.
155        If a mutex has already been acquired in a task, that same task cannot acquire it
156        a second time. It leads to undefined behavior. Some possible results include:
157
158        * Deadlock. The function will never return and the task is hung forever.
159        * Systemhalts.
160        * Error returned and mutex is only acquired once. If the error code is not handled (which is a violation of Magnum rules), race conditions will be introduced.
161        * No error returned and mutex is acquired twice (two releases are required). This may allow bad code to be hidden until another platform uncovers the problem.
162
163        A platform's implementation may chose any of the above results, although we strongly
164        recommend that the function fail and return an error code if possible.
165
166Returns:
167        BERR_SUCCESS - Mutex was acquired successfully.
168        BERR_TIMEOUT - The mutex is already acquired by another task and so the mutex was not acquired.
169        BERR_OS_ERROR - The system failed and the mutex was not acquired.
170
171See Also:
172        BKNI_AcquireMutex, BKNI_ReleaseMutex, Magnum ThreadSafe rules
173****************************************************************************/
174BERR_Code BKNI_TryAcquireMutex(
175        BKNI_MutexHandle mutex
176        );
177
178#if SUPPORT_DST_PLATFORM
179BERR_Code BKNI_AcquireMutexTimeout(BKNI_MutexHandle mutex, unsigned short timeout);
180#endif
181
182/***************************************************************************
183Summary:
184        Acquire exclusive ownership of a mutex, possibly blocking.
185
186Description:
187        Acquire exclusive ownership of a mutex. If another task currently
188        owns the mutex, BKNI_AcquireMutex will block until the mutex can be acquired.
189        After acquiring the mutex, the caller retains exclusive ownership until
190        BKNI_ReleaseMutex is called for that mutex.
191
192        Magnum code cannot nest calls to BKNI_AcquireMutex or BKNI_TryAcquireMutex.
193        If a mutex has already been acquired in a task, that same task cannot acquire it
194        a second time. It leads to undefined behavior. Some possible results include:
195
196        * Deadlock. The function will never return and the task is hung forever.
197        * Systemhalts.
198        * Error returned and mutex is only acquired once. If the error code is not handled (which is a violation of Magnum rules), race conditions will be introduced.
199        * No error returned and mutex is acquired twice (two releases are required). This may allow bad code to be hidden until another platform uncovers the problem.
200
201        A platform's implementation may chose any of the above results, although we strongly
202        recommend that the function fail and return an error code if possible.
203
204Returns:
205        BERR_SUCCESS - Mutex was acquired successfully.
206        BERR_OS_ERROR - The system failed or was interrupted, and the mutex was not acquired.
207
208See Also:
209        BKNI_TryAcquireMutex, BKNI_ReleaseMutex, Magnum ThreadSafe rules
210****************************************************************************/
211BERR_Code BKNI_AcquireMutex(
212        BKNI_MutexHandle mutex
213        );
214
215/***************************************************************************
216Summary:
217        Release exclusive ownership of a mutex.
218
219Description:
220        If you successfully acquired the mutex using BKNI_AcquireMutex or BKNI_TryAcquireMutex,
221        BKNI_ReleaseMutex will release the mutex.
222
223        In Magnum code, releasing a mutex which was acquired in a different task is not
224        allowed and leads to undefined behavior.
225        Also, releasing a mutex which is not in an acquired state is not allowed
226        and leads to undefined behavior.
227
228        A platform implementation does not have to enforce the usage rules noted
229        above. This is because it may not be possible in all cases, and the platform
230        may want to actually allow this behavior in platform-specific (non-Magnum) code.
231
232See Also:
233        BKNI_AcquireMutex, BKNI_TryAcquireMutex, Magnum ThreadSafe rules
234****************************************************************************/
235void BKNI_ReleaseMutex(BKNI_MutexHandle mutex);
236
237#ifdef __cplusplus
238}
239#endif
240
241#endif /* BKNI_MULTI_H__ */
Note: See TracBrowser for help on using the repository browser.