2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __MSG_MUTEX_H__
18 #define __MSG_MUTEX_H__
20 /*==================================================================================================
22 ==================================================================================================*/
31 void WaitMsgReady(int sec);
36 Mutex(){ pthread_mutex_init(&m, 0); }
37 void lock(){ pthread_mutex_lock(&m); }
38 void unlock(){ pthread_mutex_unlock(&m); }
39 pthread_mutex_t* pMutex() { return &m; }
48 MutexLocker(Mutex& mx)
66 CndVar(){ pthread_cond_init(&c, 0); }
67 void wait(pthread_mutex_t* m) { pthread_cond_wait(&c, m); }
68 int timedwait(pthread_mutex_t* m, int sec)
70 struct timeval now = {0};
71 struct timespec timeout = {0};
72 gettimeofday(&now, NULL);
73 timeout.tv_sec = now.tv_sec+sec;
74 timeout.tv_nsec = now.tv_usec;
75 int retcode = pthread_cond_timedwait(&c, m, &timeout);
78 void signal(){ pthread_cond_signal(&c); }
79 void broadcast(){ pthread_cond_broadcast(&c); }