1 // Copyright (C) 2024 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <ditto/logger.h>
16 #include <ditto/shared_variables.h>
17 #include <ditto/utils.h>
18
19 #include <ditto/lock.h>
20
21 namespace dittosuite {
22
LockInterface(const std::string & name,const Params & params,pthread_mutex_t * mutex)23 LockInterface::LockInterface(const std::string& name, const Params& params, pthread_mutex_t* mutex)
24 : Instruction(name, params), mutex_(mutex) {}
25
Lock(const Params & params,pthread_mutex_t * mutex)26 Lock::Lock(const Params& params, pthread_mutex_t* mutex) : LockInterface(kName, params, mutex) {}
27
SetUpSingle()28 void Lock::SetUpSingle() {
29 Instruction::SetUpSingle();
30 }
31
RunSingle()32 void Lock::RunSingle() {
33 if (syscall_.LockMutex(mutex_)) {
34 PLOGF("Cannot lock mutex");
35 }
36 }
37
Unlock(const Params & params,pthread_mutex_t * mutex)38 Unlock::Unlock(const Params& params, pthread_mutex_t* mutex)
39 : LockInterface(kName, params, mutex) {}
40
SetUpSingle()41 void Unlock::SetUpSingle() {
42 Instruction::SetUpSingle();
43 }
44
RunSingle()45 void Unlock::RunSingle() {
46 if (syscall_.UnlockMutex(mutex_)) {
47 PLOGF("Cannot unlock mutex");
48 }
49 }
50
51 } // namespace dittosuite
52