2 * Copyright 2019 AT&T Intellectual Property
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 // Created by adi ENZEL on 8/28/19.
22 #ifndef E2_MAPWRAPPER_H
23 #define E2_MAPWRAPPER_H
25 #include <unordered_map>
27 #include <shared_mutex>
36 void *find(char *key) {
37 shared_lock<shared_timed_mutex> read(fence);
38 if (mdclog_level_get() >= MDCLOG_DEBUG) {
41 auto entry = keyMap.find(key);
42 if (entry == keyMap.end()) {
48 void setkey(char *key, void *val) {
49 unique_lock<shared_timed_mutex> write(fence);
53 void *erase(char *key) {
54 unique_lock<shared_timed_mutex> write(fence);
55 return (void *)keyMap.erase(key);
59 unique_lock<shared_timed_mutex> write(fence);
63 void getKeys(vector<char *> &v) {
64 shared_lock<shared_timed_mutex> read(fence);
65 for (auto const &e : keyMap) {
66 v.emplace_back((char *)e.first.c_str());
73 std::unordered_map<string, void *> keyMap;
74 shared_timed_mutex fence;
77 #endif //E2_MAPWRAPPER_H