Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLEANUP: Move event callback functions to mc_util files #713

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions mc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,44 @@ ENGINE_ERROR_CODE tokenize_sblocks(mblck_list_t *blist, int keylen, int keycnt,
return tokenize_mblocks(blist, keylen-2, keycnt, maxklen,
must_backward_compatible, tokens);
}

/*
* event callback functions
*/

/* event handlers structure */
struct engine_event_handler {
EVENT_CALLBACK cb;
const void *cb_data;
struct engine_event_handler *next;
};
static struct engine_event_handler *engine_event_handlers[MAX_ENGINE_EVENT_TYPE + 1];

/*
* Register a callback.
*/
void register_callback(ENGINE_HANDLE *eh,
ENGINE_EVENT_TYPE type,
EVENT_CALLBACK cb, const void *cb_data)
{
struct engine_event_handler *h =
calloc(sizeof(struct engine_event_handler), 1);

assert(h);
h->cb = cb;
h->cb_data = cb_data;
h->next = engine_event_handlers[type];
engine_event_handlers[type] = h;
}

/*
* Perform all callbacks of a given type for the given connection.
*/
void perform_callbacks(ENGINE_EVENT_TYPE type,
const void *data, const void *c)
{
for (struct engine_event_handler *h = engine_event_handlers[type];
h; h = h->next) {
h->cb(c, type, data, h->cb_data);
}
}
8 changes: 8 additions & 0 deletions mc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef MC_UTIL_H
#define MC_UTIL_H

#include <memcached/callback.h>
#include <memcached/extension.h>

/* length of string representing 4 bytes integer is 10 */
Expand Down Expand Up @@ -95,4 +96,11 @@ ENGINE_ERROR_CODE tokenize_sblocks(mblck_list_t *blist, int keylen, int keycnt,
int maxklen, bool must_backward_compatible,
token_t *tokens);

/* event callback functions */
void register_callback(ENGINE_HANDLE *eh,
ENGINE_EVENT_TYPE type,
EVENT_CALLBACK cb, const void *cb_data);
void perform_callbacks(ENGINE_EVENT_TYPE type,
const void *data, const void *c);

#endif
27 changes: 0 additions & 27 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ static struct event_base *main_base;
struct thread_stats *default_thread_stats;
topkeys_t *default_topkeys = NULL;

static struct engine_event_handler *engine_event_handlers[MAX_ENGINE_EVENT_TYPE + 1];

#ifdef ENABLE_ZK_INTEGRATION
static char *arcus_zk_cfg = NULL;
#endif
Expand Down Expand Up @@ -443,31 +441,6 @@ void safe_close(int sfd)
}
}

// Register a callback.
static void register_callback(ENGINE_HANDLE *eh,
ENGINE_EVENT_TYPE type,
EVENT_CALLBACK cb, const void *cb_data)
{
struct engine_event_handler *h =
calloc(sizeof(struct engine_event_handler), 1);

assert(h);
h->cb = cb;
h->cb_data = cb_data;
h->next = engine_event_handlers[type];
engine_event_handlers[type] = h;
}

// Perform all callbacks of a given type for the given connection.
static void perform_callbacks(ENGINE_EVENT_TYPE type,
const void *data, const void *c)
{
for (struct engine_event_handler *h = engine_event_handlers[type];
h; h = h->next) {
h->cb(c, type, data, h->cb_data);
}
}

/*
* Free list management for connections.
*/
Expand Down
6 changes: 0 additions & 6 deletions memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,6 @@ struct settings {
} extensions;
};

struct engine_event_handler {
EVENT_CALLBACK cb;
const void *cb_data;
struct engine_event_handler *next;
};

extern struct settings settings;
extern EXTENSION_LOGGER_DESCRIPTOR *mc_logger;

Expand Down
Loading