#include "poll_funcs_tevent.h"
#include "tevent.h"
#include "system/select.h"
+#include "dlinklist.h"
/*
* A poll_watch is asked for by the engine using this library via
};
struct poll_funcs_tevent_context {
- unsigned refcount;
+ struct poll_funcs_tevent_handle *handles;
struct poll_funcs_state *state;
unsigned slot; /* index into state->contexts[] */
struct tevent_context *ev;
* multiple times. So we have to share one poll_funcs_tevent_context.
*/
struct poll_funcs_tevent_handle {
+ struct poll_funcs_tevent_handle *prev, *next;
struct poll_funcs_tevent_context *ctx;
};
return NULL;
}
- ctx->refcount = 0;
+ ctx->handles = NULL;
ctx->state = state;
ctx->ev = ev;
ctx->slot = slot;
static int poll_funcs_tevent_context_destructor(
struct poll_funcs_tevent_context *ctx)
{
+ struct poll_funcs_tevent_handle *h;
+
ctx->state->contexts[ctx->slot] = NULL;
+
+ for (h = ctx->handles; h != NULL; h = h->next) {
+ h->ctx = NULL;
+ }
+
return 0;
}
}
handle->ctx = state->contexts[slot];
- handle->ctx->refcount += 1;
+ DLIST_ADD(handle->ctx->handles, handle);
talloc_set_destructor(handle, poll_funcs_tevent_handle_destructor);
return handle;
fail:
static int poll_funcs_tevent_handle_destructor(
struct poll_funcs_tevent_handle *handle)
{
- if (handle->ctx->refcount == 0) {
+ if (handle->ctx == NULL) {
+ return 0;
+ }
+ if (handle->ctx->handles == NULL) {
abort();
}
- handle->ctx->refcount -= 1;
- if (handle->ctx->refcount != 0) {
- return 0;
+ DLIST_REMOVE(handle->ctx->handles, handle);
+
+ if (handle->ctx->handles == NULL) {
+ TALLOC_FREE(handle->ctx);
}
- TALLOC_FREE(handle->ctx);
return 0;
}