Skip to content

Commit

Permalink
address ion's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pcmoritz committed Sep 17, 2016
1 parent 0b7d81c commit 1859505
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
12 changes: 12 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
} \
} while (0);

/* Return and error codes. */

/* If a fatal error happens, the process exits with an exit code. */

#define GIVE_UP(STATUS_CODE) \
do { \
LOG_ERR("Giving up with status code %d", STATUS_CODE); \
exit(STATUS_CODE); \
} while (0);

/* Unique IDs */

#define UNIQUE_ID_SIZE 20

typedef struct { unsigned char id[UNIQUE_ID_SIZE]; } unique_id;
Expand Down
4 changes: 2 additions & 2 deletions event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ int64_t event_loop_attach(event_loop *loop,
int type,
void *data,
int fd,
int events) {
int events_tag) {
assert(utarray_len(loop->items) == utarray_len(loop->waiting));
int64_t index = utarray_len(loop->items);
event_loop_item item = {.type = type, .data = data};
utarray_push_back(loop->items, &item);
struct pollfd waiting = {.fd = fd, .events = events};
struct pollfd waiting = {.fd = fd, .events = events_tag};
utarray_push_back(loop->waiting, &waiting);
return index;
}
Expand Down
11 changes: 10 additions & 1 deletion event_loop.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#ifndef EVENT_LOOP_H
#define EVENT_LOOP_H

/* This header defines the data structure and methods for an event loop.
* The event loop allows user code to listen to reads and writes that happen
* on file descriptors. We are using this for async io with the database
* that holds the state and to communicate between object stores, worker
* processes and the local scheduler. */

#include <poll.h>
#include <stdint.h>

Expand All @@ -13,6 +19,9 @@ typedef struct {
void *data;
} event_loop_item;

/* This is the main event loop datastructure which holds the pollfd struct
* for the poll system call and also user data associated with connections
* (like the status) of the connection. */
typedef struct {
/* Array of event_loop_items that hold information for connections. */
UT_array *items;
Expand All @@ -27,7 +36,7 @@ int64_t event_loop_attach(event_loop *loop,
int type,
void *data,
int fd,
int events);
int events_tag);
void event_loop_detach(event_loop *loop, int64_t index, int shall_close);
int event_loop_poll(event_loop *loop);
int64_t event_loop_size(event_loop *loop);
Expand Down
2 changes: 1 addition & 1 deletion state/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void db_connect(const char *db_address,
int client_port,
db_conn *db);

/* Attach global system store onnection to event loop. Returns the index of the
/* Add the global system store onnection to event loop. Returns the index of the
* connection in the loop. */
int64_t db_attach(db_conn *db, event_loop *loop, int connection_type);

Expand Down

0 comments on commit 1859505

Please sign in to comment.