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 #pragma once 16 17 #include <mutex> 18 #include <stack> 19 20 #include <ditto/instruction.h> 21 22 namespace dittosuite { 23 24 class LockInterface : public Instruction { 25 protected: 26 pthread_mutex_t* mutex_; 27 28 LockInterface(const LockInterface&) = delete; 29 LockInterface& operator=(const LockInterface&) = delete; 30 31 LockInterface(const std::string& name, const Params& params, pthread_mutex_t* mutex); 32 virtual ~LockInterface() = default; 33 }; 34 35 class Lock : public LockInterface { 36 public: 37 inline static const std::string kName = "lock"; 38 39 Lock(const Lock&) = delete; 40 Lock& operator=(const Lock&) = delete; 41 42 explicit Lock(const Params& params, pthread_mutex_t* mutex); 43 ~Lock() = default; 44 45 private: 46 void SetUpSingle() override; 47 void RunSingle() override; 48 }; 49 50 class Unlock : public LockInterface { 51 public: 52 inline static const std::string kName = "unlock"; 53 54 Unlock(const Unlock&) = delete; 55 Unlock& operator=(const Unlock&) = delete; 56 57 explicit Unlock(const Params& params, pthread_mutex_t* mutex); 58 ~Unlock() = default; 59 60 private: 61 void SetUpSingle() override; 62 void RunSingle() override; 63 }; 64 65 } // namespace dittosuite 66