summaryrefslogtreecommitdiff
path: root/include/utils/MsgMutex.h
diff options
context:
space:
mode:
authorseunggi.hong <seunggi.hong@samsung.com>2015-04-03 17:44:25 +0900
committerseunggi.hong <seunggi.hong@samsung.com>2015-04-03 17:46:03 +0900
commit873b33b178b7b31d1074e5c1f93b2f68f839416b (patch)
tree6a084331009e4d82c6351b2690e76161fd0a485b /include/utils/MsgMutex.h
parent1cd776d274fc36821557958fca79abeec457a703 (diff)
downloadmsg-service-873b33b178b7b31d1074e5c1f93b2f68f839416b.tar.gz
msg-service-873b33b178b7b31d1074e5c1f93b2f68f839416b.tar.bz2
msg-service-873b33b178b7b31d1074e5c1f93b2f68f839416b.zip
Change-Id: I73019c4c236709be9c36c1744a3bcce4b98076e4 Signed-off-by: seunggi.hong <seunggi.hong@samsung.com>
Diffstat (limited to 'include/utils/MsgMutex.h')
-rwxr-xr-xinclude/utils/MsgMutex.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/include/utils/MsgMutex.h b/include/utils/MsgMutex.h
index 45ea049..c3b1cc6 100755
--- a/include/utils/MsgMutex.h
+++ b/include/utils/MsgMutex.h
@@ -1,20 +1,17 @@
/*
- * msg-service
- *
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
#ifndef __MSG_MUTEX_H__
@@ -36,8 +33,23 @@ void WaitMsgReady(int sec);
class Mutex
{
public:
- Mutex(){ pthread_mutex_init(&m, 0); }
+ Mutex(){
+ pthread_mutexattr_t mattr;
+ pthread_mutexattr_init(&mattr);
+ pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init(&m, &mattr);
+ pthread_mutexattr_destroy(&mattr);
+ }
+ ~Mutex(){ pthread_mutex_destroy(&m); }
void lock(){ pthread_mutex_lock(&m); }
+
+ int timedlock(){
+ struct timespec abs_time;
+ clock_gettime(CLOCK_REALTIME, &abs_time);
+ abs_time.tv_sec += 1;
+ return pthread_mutex_timedlock(&m, &abs_time);
+ }
+
void unlock(){ pthread_mutex_unlock(&m); }
pthread_mutex_t* pMutex() { return &m; }