All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Structures | Functions
Asynchronous Event Abstraction

Description

Generic asynchronous events abstraction. Designed to support multiple event libraries such as libev and libuv. Only one library can be supported per build.

Data Structures

struct  as_event_loop
 

Functions

void as_event_close_loops ()
 
as_event_loopas_event_create_loops (uint32_t capacity)
 
as_event_loopas_event_loop_find (void *loop)
 
static as_event_loopas_event_loop_get ()
 
static as_event_loopas_event_loop_get_by_index (uint32_t index)
 
as_event_loopas_event_set_external_loop (void *loop)
 
bool as_event_set_external_loop_capacity (uint32_t capacity)
 

Function Documentation

void as_event_close_loops ( )

Close internally created event loops and release memory for event loop abstraction. This method should be called once on program shutdown if as_event_create_loops() or as_event_set_external_loop_capacity() was called.

as_event_loop* as_event_create_loops ( uint32_t  capacity)

Create new event loops. This method should only be called when asynchronous client commands will be used and the calling program itself is not asynchronous. If this method is used, it must be called before aerospike_connect().

Parameters
capacityNumber of event loops to create.
as_event_loop* as_event_loop_find ( void *  loop)

Find client's event loop abstraction given the external event loop.

Parameters
loopExternal event loop.
Returns
Client's generic event loop abstraction that is used in client async commands. Returns NULL if loop not found.
static as_event_loop* as_event_loop_get ( )
inlinestatic

Retrieve a random event loop using round robin distribution.

Returns
Client's generic event loop abstraction that is used in client async commands.

Definition at line 215 of file as_event.h.

static as_event_loop* as_event_loop_get_by_index ( uint32_t  index)
inlinestatic

Retrieve event loop by array index.

Parameters
indexEvent loop array index.
Returns
Client's generic event loop abstraction that is used in client async commands.

Definition at line 202 of file as_event.h.

as_event_loop* as_event_set_external_loop ( void *  loop)

Register an external event loop with the client. This method should be called when the calling program wants to share event loops with the client. This reduces resource usage and can increase performance.

This method must be called in the same thread as the event loop that is being registered.

This method is used in conjunction with as_event_set_external_loop_capacity() to fully define the external loop to the client and obtain a reference the client's event loop abstraction.

struct {
pthread_t thread;
struct ev_loop* loop;
as_event_loop* as_loop;
} my_loop;
static void* my_loop_worker_thread(void* udata) {
struct my_loop* myloop = udata;
myloop->loop = ev_loop_new(EVFLAG_AUTO);
myloop->as_loop = as_event_set_external_loop(myloop->loop);
ev_loop(myloop->loop, 0);
ev_loop_destroy(myloop->loop);
return NULL;
}
int capacity = 8;
struct my_loop* loops = malloc(sizeof(struct my_loop) * capacity);
for (int i = 0; i < capacity; i++) {
struct my_loop* myloop = &loops[i];
return pthread_create(&myloop->thread, NULL, my_loop_worker_thread, myloop) == 0;
}
Parameters
loopExternal event loop.
Returns
Client's generic event loop abstraction that is used in client async commands. Returns NULL if external loop capacity would be exceeded.
bool as_event_set_external_loop_capacity ( uint32_t  capacity)

Set the number of externally created event loops. This method should be called when the calling program wants to share event loops with the client. This reduces resource usage and can increase performance.

This method is used in conjunction with as_event_set_external_loop() to fully define the the external loop to the client and obtain a reference the client's event loop abstraction.

struct {
pthread_t thread;
struct ev_loop* loop;
as_event_loop* as_loop;
} my_loop;
static void* my_loop_worker_thread(void* udata) {
struct my_loop* myloop = udata;
myloop->loop = ev_loop_new(EVFLAG_AUTO);
myloop->as_loop = as_event_set_external_loop(myloop->loop);
ev_loop(myloop->loop, 0);
ev_loop_destroy(myloop->loop);
return NULL;
}
int capacity = 8;
struct my_loop* loops = malloc(sizeof(struct my_loop) * capacity);
for (int i = 0; i < capacity; i++) {
struct my_loop* myloop = &loops[i];
return pthread_create(&myloop->thread, NULL, my_loop_worker_thread, myloop) == 0;
}
Parameters
capacityNumber of externally created event loops.