2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 /* standard library header */
21 /* SLP library header */
24 #include "Synchronous.h"
26 namespace smartcard_service_api
28 Synchronous::Synchronous()
30 pthread_mutex_init(&syncMutex, NULL);
31 pthread_cond_init(&syncCondition, NULL);
34 void Synchronous::syncLock()
36 pthread_mutex_lock(&syncMutex);
39 void Synchronous::syncUnlock()
41 pthread_mutex_unlock(&syncMutex);
44 int Synchronous::waitTimedCondition(int second)
52 gettimeofday(&now, NULL);
53 ts.tv_sec = now.tv_sec + second;
54 ts.tv_nsec = now.tv_usec * 1000;
56 result = pthread_cond_timedwait(&syncCondition, &syncMutex, &ts);
60 result = pthread_cond_wait(&syncCondition, &syncMutex);
66 void Synchronous::signalCondition()
68 pthread_cond_signal(&syncCondition);
71 } /* namespace smartcard_service_api */