1 /*
2 * Copyright (c) 2008 Texas Instruments. All rights reserved.
3 * This program and the accompanying materials are made available under the
4 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License
5 * v. 1.0 which accompanies this distribution. The Eclipse Public License is
6 * available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse
7 * Distribution License is available at
8 * http://www.eclipse.org/org/documents/edl-v10.php.
9 *
10 * Contributors:
11 * Texas Instruments - initial implementation
12 * */
13
14 /*
15 * ======== ISemaphore.xdc ========
16 */
17
18 import xdc.runtime.Error;
19
20 /*!
21 * ======== ISemaphore ========
22 * Interface implemented by all front-end semaphore providers.
23 *
24 * {@link #SemThread} and {@link #SemProcess}. [EXPERIMENTAL]
25 * Semaphores can be used for synchronization and mutual exclusion.
26 *
27 * pend() is used to wait for a semaphore. The timeout parameter allows the
28 * caller to wait until a timeout, wait indefinitely, or not wait at all.
29 * The return value indicates whether or not the wait was successful.
30 *
31 * post() is used to signal a semaphore. If no thread is waiting on the
32 * semaphore, then post() increments the semaphore count (for binary
33 * semaphores, the count is always 0 or 1).
34 *
35 */
36 interface ISemaphore {
37
38 /*!
39 * ======== PendStatus ========
40 * Error codes returned by Semaphore_pend
41 */
42 enum PendStatus {
43 PendStatus_ERROR = -1,
44 PendStatus_TIMEOUT = 0,
45 PendStatus_SUCCESS = 1
46 };
47
48 /*! Used as the timeout value to specify wait forever */
49 const UInt FOREVER = ~(0);
50
51 /*! Types of semaphores. */
52 enum Mode {
53 Mode_COUNTING, /*! Counting semaphore. */
54 Mode_BINARY /*! Binary Semaphore. */
55 };
56
57 instance:
58
59 /*!
60 * ======== mode ========
61 * Semaphore mode. Default is COUNTING.
62 *
63 * When mode is BINARY , the semaphore has only two states, available
64 * and unavailable. When mode is COUNTING, the semaphore keeps track of
65 * number of times a semaphore is posted.
66 */
67 config Mode mode = Mode_COUNTING;
68
69 /*!
70 * ======== pend ========
71 * Wait for the semaphore to become available.
72 *
73 * @p(blist) 74 * -{@link #PendStatus_ERROR} if an error occured.
75 * -{@link #PendStatus_TIMEOUT} denotes timeout.
76 * -{@link #PendStatus_SUCCESS} semaphore was decremented.
77 * details.
78 * @p 79 *
80 * @param(timeout) timeout in microseconds
81 * @param(eb) error block
82 * @a(returns) refer to description above
83 */
84 Int pend(UInt timeout, Error.Block *eb);
85
86 /*!
87 * ======== post ========
88 * Increment the semaphore count.
89 *
90 * @param(eb) error block
91 * @a(returns) true for success, false for error in error block
92 */
93 Bool post(Error.Block *eb);
94 }
95 /*
96 * @(#) xdc.runtime.knl; 1, 0, 0,146; 6-14-2011 11:49:32; /db/ztree/library/trees/xdc/xdc-x14x/src/packages/
97 */
98