CAudioInfo: Refactor getters to return in group
[platform/core/api/audio-io.git] / include / CAudioLocker.h
1 /*
2  * Copyright (c) 2023 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 #include <chrono>
18 #include <thread>
19 #include <mutex>
20 #include <sys/types.h>
21
22 #ifndef __TIZEN_MEDIA_AUDIO_IO_CAUDIOLOCKER_H__
23 #define __TIZEN_MEDIA_AUDIO_IO_CAUDIOLOCKER_H__
24
25 #ifdef __cplusplus
26
27 using namespace std::literals::chrono_literals;
28
29 namespace tizen_media_audio {
30
31     constexpr auto mutex_timeout_s = 4s;
32
33     class CAudioTimedLocker {
34     public:
35         explicit CAudioTimedLocker(const std::string& tag);
36         CAudioTimedLocker(const std::string& tag, std::timed_mutex& m,
37                         std::chrono::seconds timeout = mutex_timeout_s);
38         virtual ~CAudioTimedLocker();
39
40         void lock(std::timed_mutex& m,
41                 std::chrono::seconds timeout = mutex_timeout_s);
42         void unlock();
43
44     private:
45         void updateHolder(const std::string& tag, pid_t tid);
46
47         std::unique_lock<std::timed_mutex> _lock;
48         std::string _tag;
49
50         static std::string _holder;
51         static pid_t _tid;
52
53
54     };
55
56 } /* namespace tizen_media_audio */
57
58 #endif
59 #endif /* __TIZEN_MEDIA_AUDIO_IO_CAUDIOLOCKER_H__ */