2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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.
18 /* standard library header */
22 /* SLP library header */
25 #include "Synchronous.h"
27 namespace smartcard_service_api
29 Synchronous::Synchronous()
31 pthread_mutex_init(&syncMutex, NULL);
32 pthread_cond_init(&syncCondition, NULL);
35 void Synchronous::syncLock()
37 pthread_mutex_lock(&syncMutex);
40 void Synchronous::syncUnlock()
42 pthread_mutex_unlock(&syncMutex);
45 int Synchronous::waitTimedCondition(int second)
53 gettimeofday(&now, NULL);
54 ts.tv_sec = now.tv_sec + second;
55 ts.tv_nsec = now.tv_usec * 1000;
57 result = pthread_cond_timedwait(&syncCondition, &syncMutex, &ts);
61 result = pthread_cond_wait(&syncCondition, &syncMutex);
67 void Synchronous::signalCondition()
69 pthread_cond_signal(&syncCondition);
72 } /* namespace smartcard_service_api */