1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 ******************************************************************/
21 * @brief This file provides APIs related to mutex and semaphores
37 #endif /* __cplusplus */
39 typedef void *u_mutex;
44 * @brief Initializes the thread system for using other mutex related APIs
47 void u_mutex_init(void);
51 * @brief Creates new mutex
53 * @return Reference to newly created mutex, otherwise NULL.
57 u_mutex u_mutex_new(void);
61 * @brief Lock the mutex
63 * @param mutex The mutex to be locked
66 void u_mutex_lock(u_mutex mutex);
70 * @brief Checks if the mutex can be locked
72 * @param mutex The mutex to be locked
74 * @return CA_TRUE if the mutex is not locked currently, otherwise CA_FALSE.
77 CABool_t u_mutex_trylock(u_mutex mutex);
81 * @brief Unlock the mutex
83 * @param mutex The mutex to be unlocked
86 void u_mutex_unlock(u_mutex mutex);
90 * @brief Free the mutex
92 * @param mutex The mutex to be freed
95 void u_mutex_free(u_mutex mutex);
99 * @brief Creates new condition
101 * @return Reference to newly created @u_cond, otherwise NULL.
105 u_cond u_cond_new(void);
109 * @brief One of threads is woken up if multiple threads are waiting for @cond
111 * @param cond The condtion to be signaled
114 void u_cond_signal(u_cond cond);
117 * @fn u_cond_broadcast
118 * @brief All of threads are woken up if multiple threads are waiting for @cond
120 * @param cond The condtion to be signaled
123 void u_cond_broadcast(u_cond cond);
127 * @brief Waits untill this thread woken up on @cond
129 * @param cond The condtion to be wait for to signal
130 * @param mutex The mutex which is currently locked from calling thread
133 void u_cond_wait(u_cond cond, u_mutex mutex);
137 * @brief Waits untill this thread woken up on @cond,
138 * but not longer than until the time specified by milliseconds.
139 * The mutex is unlocked before falling asleep and locked again before resuming.
140 * If milliseconds is 0 or under, u_cond_timed_wait() acts like u_cond_wait().
142 * @param cond The condtion to be wait for to signal
143 * @param mutex The mutex which is currently locked from calling thread
144 * @param microseconds relative time for waiting, microseconds
147 void u_cond_timed_wait(u_cond cond, u_mutex mutex, int32_t microseconds);
151 * @brief Free the condition
153 * @param cond The condition to be freed
156 void u_cond_free(u_cond cond);
160 #endif /* __cplusplus */