Change how to check pkginfo server ready flag
[platform/core/appfw/pkgmgr-info.git] / src / shared_object.hh
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef SHARED_OBJECT_HH_
18 #define SHARED_OBJECT_HH_
19
20 #include <mutex>
21 #include <string>
22
23 namespace utils {
24
25 template<typename T>
26 class SharedObject {
27  public:
28   T GetObject() {
29     lock_.lock();
30     T ret = object_;
31     lock_.unlock();
32     return ret;
33   }
34   void SetObject(T& object) {
35     lock_.lock();
36     object_ = object;
37     lock_.unlock();
38   }
39   void SetObject(std::string&& object) {
40     lock_.lock();
41     object_ = std::move(object);
42     lock_.unlock();
43   }
44
45  private:
46   T object_;
47   std::mutex lock_;
48 };
49
50 }  // namespace utils
51
52 #endif  // SHARED_OBJECT_HH_