Skip to content

Commit b4f7ed6

Browse files
robertnishiharapcmoritz
authored andcommitted
ARROW-3605: [Plasma] Remove dependence of plasma/events.h on ae.h.
Author: Robert Nishihara <robertnishihara@gmail.com> Closes apache#2826 from robertnishihara/aeinclude and squashes the following commits: aa7177b <Robert Nishihara> Address comments. d6ba51f <Robert Nishihara> Remove dependence of plasma/events.h on ae.h.
1 parent d5510e0 commit b4f7ed6

3 files changed

Lines changed: 32 additions & 18 deletions

File tree

cpp/src/plasma/events.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,18 @@
2121

2222
#include <errno.h>
2323

24+
extern "C" {
25+
#include "ae/ae.h"
26+
}
27+
2428
namespace plasma {
2529

30+
// Verify that the constants defined in events.h are defined correctly.
31+
static_assert(kEventLoopTimerDone == AE_NOMORE, "constant defined incorrectly");
32+
static_assert(kEventLoopOk == AE_OK, "constant defined incorrectly");
33+
static_assert(kEventLoopRead == AE_READABLE, "constant defined incorrectly");
34+
static_assert(kEventLoopWrite == AE_WRITABLE, "constant defined incorrectly");
35+
2636
void EventLoop::FileEventCallback(aeEventLoop* loop, int fd, void* context, int events) {
2737
FileCallback* callback = reinterpret_cast<FileCallback*>(context);
2838
(*callback)(events);

cpp/src/plasma/events.h

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,24 @@
2222
#include <memory>
2323
#include <unordered_map>
2424

25-
extern "C" {
26-
#include "ae/ae.h"
27-
}
25+
struct aeEventLoop;
2826

2927
namespace plasma {
3028

29+
// The constants below are defined using hardcoded values taken from ae.h so
30+
// that ae.h does not need to be included in this file.
31+
3132
/// Constant specifying that the timer is done and it will be removed.
32-
constexpr int kEventLoopTimerDone = AE_NOMORE;
33+
constexpr int kEventLoopTimerDone = -1; // AE_NOMORE
34+
35+
/// A successful status.
36+
constexpr int kEventLoopOk = 0; // AE_OK
3337

3438
/// Read event on the file descriptor.
35-
constexpr int kEventLoopRead = AE_READABLE;
39+
constexpr int kEventLoopRead = 1; // AE_READABLE
3640

3741
/// Write event on the file descriptor.
38-
constexpr int kEventLoopWrite = AE_WRITABLE;
42+
constexpr int kEventLoopWrite = 2; // AE_WRITABLE
3943

4044
typedef long long TimerID; // NOLINT
4145

@@ -57,29 +61,29 @@ class EventLoop {
5761

5862
/// Add a new file event handler to the event loop.
5963
///
60-
/// @param fd The file descriptor we are listening to.
61-
/// @param events The flags for events we are listening to (read or write).
62-
/// @param callback The callback that will be called when the event happens.
63-
/// @return Returns true if the event handler was added successfully.
64+
/// \param fd The file descriptor we are listening to.
65+
/// \param events The flags for events we are listening to (read or write).
66+
/// \param callback The callback that will be called when the event happens.
67+
/// \return Returns true if the event handler was added successfully.
6468
bool AddFileEvent(int fd, int events, const FileCallback& callback);
6569

6670
/// Remove a file event handler from the event loop.
6771
///
68-
/// @param fd The file descriptor of the event handler.
72+
/// \param fd The file descriptor of the event handler.
6973
void RemoveFileEvent(int fd);
7074

7175
/// Register a handler that will be called after a time slice of
72-
/// "timeout" milliseconds.
76+
/// "timeout" milliseconds.
7377
///
74-
/// @param timeout The timeout in milliseconds.
75-
/// @param callback The callback for the timeout.
76-
/// @return The ID of the newly created timer.
78+
/// \param timeout The timeout in milliseconds.
79+
/// \param callback The callback for the timeout.
80+
/// \return The ID of the newly created timer.
7781
int64_t AddTimer(int64_t timeout, const TimerCallback& callback);
7882

7983
/// Remove a timer handler from the event loop.
8084
///
81-
/// @param timer_id The ID of the timer that is to be removed.
82-
/// @return The ae.c error code. TODO(pcm): needs to be standardized
85+
/// \param timer_id The ID of the timer that is to be removed.
86+
/// \return The ae.c error code. TODO(pcm): needs to be standardized
8387
int RemoveTimer(int64_t timer_id);
8488

8589
/// \brief Run the event loop.

cpp/src/plasma/store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ void PlasmaStore::RemoveGetRequest(GetRequest* get_request) {
280280
}
281281
// Remove the get request.
282282
if (get_request->timer != -1) {
283-
ARROW_CHECK(loop_->RemoveTimer(get_request->timer) == AE_OK);
283+
ARROW_CHECK(loop_->RemoveTimer(get_request->timer) == kEventLoopOk);
284284
}
285285
delete get_request;
286286
}

0 commit comments

Comments
 (0)