2 * Copyright 2004-present Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <folly/portability/Event.h>
25 # if LIBEVENT_VERSION_NUMBER <= 0x02010101
26 # define FOLLY_LIBEVENT_COMPAT_PLUCK(name) ev_##name
28 # define FOLLY_LIBEVENT_COMPAT_PLUCK(name) ev_evcallback.evcb_##name
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 inline auto event_ref_##name(struct event const* ev) -> \
35 decltype(std::cref(ev->FOLLY_LIBEVENT_COMPAT_PLUCK(name))) \
36 { return std::cref(ev->FOLLY_LIBEVENT_COMPAT_PLUCK(name)); } \
39 FOLLY_LIBEVENT_DEF_ACCESSORS(flags)
41 # undef FOLLY_LIBEVENT_COMPAT_PLUCK
42 # undef FOLLY_LIBEVENT_DEF_ACCESSORS
45 * low-level libevent utility functions
49 static bool isEventRegistered(const struct event* ev) {
50 // If any of these flags are set, the event is registered.
52 EVLIST_REGISTERED = (EVLIST_INSERTED | EVLIST_ACTIVE |
53 EVLIST_TIMEOUT | EVLIST_SIGNAL)
55 return (event_ref_flags(ev) & EVLIST_REGISTERED);