1 2 3 4 5 6 7 8 9 10 11 12
13 14 15
16
17 import xdc.runtime.Assert;
18 import xdc.runtime.Error;
19 import xdc.runtime.knl.ISemaphore;
20
21 /*!
22 * ======== Semaphore ========
23 * Provides semaphore services when an ISemaphore.Handle is available.
24 *
25 * An application can isolate itself from ISemaphore implementations by using
26 * this module. The application must first obtain an ISemaphore.Handle.
27 * It make get such a handle by directly calling {@link SemThread#create} or
28 * {@link SemProcess#create}. Then the application can use the generic
29 * APIs provided by this module.
30 */
31 @DirectCall
32 @RomConsts
33
34 module Semaphore
35 {
36 /*!
37 * ======== PendStatus ========
38 * Error codes returned by Semaphore_pend
39 */
40 enum PendStatus {
41 PendStatus_ERROR = -1,
42 PendStatus_TIMEOUT = 0,
43 PendStatus_SUCCESS = 1
44 };
45
46 /*! Used as the timeout value to specify wait forever */
47 const UInt FOREVER = ISemaphore.FOREVER;
48
49 /*!
50 * Proxy used for optimization.
51 *
52 * If ALL ISemaphore.Handles were created using the same module
53 * (e.g SemProcess) then setting this Proxy to SemProcess and
54 * setting Semaphore.Proxy.abstractInstances$ = false,
55 * Semaphore APIs can have better performance.
56 */
57 proxy Proxy inherits ISemaphore;
58
59 /*!
60 * ======== pend ========
61 * Wait for the semaphore to have a nonzero count, then decrement it.
62 *
63 * The function returns one of the following:
64 * @p(blist)
65 * -{@link #PendStatus_ERROR} if an error occured.
66 * -{@link #PendStatus_TIMEOUT} denotes timeout.
67 * -{@link #PendStatus_SUCCESS} semaphore was decremented.
68 *
69 * @p
70 *
71 * @param(sem) ISemaphore.Handle to be used
72 * @param(timeout) timeout in microseconds or
73 * {@link #FOREVER Semaphore_FOREVER} to wait forever
74 * @param(eb) Pointer to Error.Block
75 * @a(returns) status returned. (refer to above description)
76 */
77 Int pend(ISemaphore.Handle sem, UInt timeout, Error.Block *eb);
78
79 /*!
80 * ======== post ========
81 * Increment the semaphore count.
82 *
83 * @param(sem) ISemaphore.Handle to be used
84 * @param(eb) Pointer to Error.Block
85 * @a(returns) true for success, false for error in Error block.
86 */
87 Bool post(ISemaphore.Handle sem, Error.Block *eb);
88 }
89 90 91
92