proxygen
EventBaseLocal.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015-present Facebook, Inc.
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 
18 #include <folly/MapUtil.h>
19 #include <atomic>
20 #include <thread>
21 
22 namespace folly {
23 namespace detail {
24 
26  auto locked = eventBases_.rlock();
27  for (auto* evb : *locked) {
28  evb->runInEventBaseThread([this, evb, key = key_] {
29  evb->localStorage_.erase(key);
30  evb->localStorageToDtor_.erase(this);
31  });
32  }
33 }
34 
37 
38  return folly::get_default(evb.localStorage_, key_, {}).get();
39 }
40 
43 
44  evb.localStorage_.erase(key_);
45  evb.localStorageToDtor_.erase(this);
46 
47  eventBases_.wlock()->erase(&evb);
48 }
49 
52 
53  eventBases_.wlock()->erase(&evb);
54 }
55 
56 void EventBaseLocalBase::setVoid(EventBase& evb, std::shared_ptr<void>&& ptr) {
58 
59  auto alreadyExists = evb.localStorage_.find(key_) != evb.localStorage_.end();
60 
61  evb.localStorage_.emplace(key_, std::move(ptr));
62 
63  if (!alreadyExists) {
64  eventBases_.wlock()->insert(&evb);
65  evb.localStorageToDtor_.insert(this);
66  }
67 }
68 
69 std::atomic<std::size_t> EventBaseLocalBase::keyCounter_{0};
70 } // namespace detail
71 } // namespace folly
void * ptr
static std::atomic< std::size_t > keyCounter_
Map::mapped_type get_default(const Map &map, const Key &key)
Definition: MapUtil.h:31
folly::Synchronized< std::unordered_set< EventBase * > > eventBases_
std::unordered_map< std::size_t, std::shared_ptr< void > > localStorage_
Definition: EventBase.h:786
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void * getVoid(EventBase &evb)
std::unordered_set< detail::EventBaseLocalBaseBase * > localStorageToDtor_
Definition: EventBase.h:787
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void setVoid(EventBase &evb, std::shared_ptr< void > &&ptr)
void dcheckIsInEventBaseThread() const
Definition: EventBase.h:520
void onEventBaseDestruction(EventBase &evb) override