Generic asynchronous events abstraction. Designed to support multiple event libraries such as libev and libuv. Only one library can be supported per build.
void as_event_close_loops |
( |
) | |
|
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
-
capacity | Number of event loops to create. |
- Returns
- Event loop array.
Find client's event loop abstraction given the external event loop.
- Parameters
-
- Returns
- Client's generic event loop abstraction that is used in client async commands. Returns NULL if loop not found.
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 218 of file as_event.h.
References as_event_loop::next.
static as_event_loop* as_event_loop_get_by_index |
( |
uint32_t |
index) | |
|
|
inlinestatic |
Retrieve event loop by array index.
- Parameters
-
index | Event loop array index. |
- Returns
- Client's generic event loop abstraction that is used in client async commands.
Definition at line 205 of file as_event.h.
References as_event_loop::index.
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;
} my_loop;
static void* my_loop_worker_thread(void* udata) {
struct my_loop* myloop = udata;
myloop->
loop = ev_loop_new(EVFLAG_AUTO);
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
-
- 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;
} my_loop;
static void* my_loop_worker_thread(void* udata) {
struct my_loop* myloop = udata;
myloop->loop = ev_loop_new(EVFLAG_AUTO);
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
-
capacity | Number of externally created event loops. |
- Returns
- True if all external loops were initialized.