proxygen
EventUtil.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-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 
17 #pragma once
18 
19 #include <functional>
20 
22 
23 namespace folly {
24 
25 #if LIBEVENT_VERSION_NUMBER <= 0x02010101
26 #define FOLLY_LIBEVENT_COMPAT_PLUCK(name) ev_##name
27 #else
28 #define FOLLY_LIBEVENT_COMPAT_PLUCK(name) ev_evcallback.evcb_##name
29 #endif
30 #define FOLLY_LIBEVENT_DEF_ACCESSORS(name) \
31  inline auto event_ref_##name(struct event* ev) \
32  ->decltype(std::ref(ev->FOLLY_LIBEVENT_COMPAT_PLUCK(name))) { \
33  return std::ref(ev->FOLLY_LIBEVENT_COMPAT_PLUCK(name)); \
34  } \
35  inline auto event_ref_##name(struct event const* ev) \
36  ->decltype(std::cref(ev->FOLLY_LIBEVENT_COMPAT_PLUCK(name))) { \
37  return std::cref(ev->FOLLY_LIBEVENT_COMPAT_PLUCK(name)); \
38  } \
39  //
40 
42 
43 #undef FOLLY_LIBEVENT_COMPAT_PLUCK
44 #undef FOLLY_LIBEVENT_DEF_ACCESSORS
45 
49 class EventUtil {
50  public:
51  static bool isEventRegistered(const struct event* ev) {
52  // If any of these flags are set, the event is registered.
53  enum {
54  EVLIST_REGISTERED =
55  (EVLIST_INSERTED | EVLIST_ACTIVE | EVLIST_TIMEOUT | EVLIST_SIGNAL)
56  };
57  return (event_ref_flags(ev) & EVLIST_REGISTERED);
58  }
59 };
60 
61 } // namespace folly
flags
Definition: http_parser.h:127
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
auto event_ref_flags(struct event *ev) -> decltype(std::ref(ev->ev_flags))
Definition: EventUtil.h:41
static bool isEventRegistered(const struct event *ev)
Definition: EventUtil.h:51
#define FOLLY_LIBEVENT_DEF_ACCESSORS(name)
Definition: EventUtil.h:30