• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 ARM Limited. All rights reserved.
3  *
4  * Copyright 2016 The Android Open Source Project
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19  #ifndef GRALLOC_COMMON_REGISTERED_HANDLE_POOL_H
20  #define GRALLOC_COMMON_REGISTERED_HANDLE_POOL_H
21 
22 #include <cutils/native_handle.h>
23 #include <mutex>
24 #include <unordered_set>
25 #include <algorithm>
26 #include <functional>
27 
28 /* An unordered set to internally store / retrieve imported buffer handles */
29 class RegisteredHandlePool
30 {
31 public:
32 	/* Stores the buffer handle in the internal list */
33 	bool add(buffer_handle_t bufferHandle);
34 
35 	/* Retrieves and removes the buffer handle from internal list */
36 	native_handle_t* remove(buffer_handle_t buffer);
37 
38 	/* Retrieves the buffer handle from internal list */
39 	buffer_handle_t get(const void* buffer);
40 
41 	/* Applies a function to each buffer handle */
42 	void for_each(std::function<void(const buffer_handle_t &)> fn);
43 
44 	bool isRegistered(buffer_handle_t handle);
45 
46 private:
47 	std::mutex mutex;
48 	std::unordered_set<buffer_handle_t> bufPool;
49 };
50 
51 #endif /* GRALLOC_COMMON_REGISTERED_HANDLE_POOL_H */
52