Fix some old license headers
[folly.git] / folly / io / async / EventUtil.h
1 /*
2  * Copyright 2004-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
21 #include <folly/portability/Event.h>
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     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)); } \
37     //
38
39 FOLLY_LIBEVENT_DEF_ACCESSORS(flags)
40
41 # undef FOLLY_LIBEVENT_COMPAT_PLUCK
42 # undef FOLLY_LIBEVENT_DEF_ACCESSORS
43
44 /**
45  * low-level libevent utility functions
46  */
47 class EventUtil {
48  public:
49   static bool isEventRegistered(const struct event* ev) {
50     // If any of these flags are set, the event is registered.
51     enum {
52       EVLIST_REGISTERED = (EVLIST_INSERTED | EVLIST_ACTIVE |
53                            EVLIST_TIMEOUT | EVLIST_SIGNAL)
54     };
55     return (event_ref_flags(ev) & EVLIST_REGISTERED);
56   }
57 };
58
59 } // folly