Skip to content

Commit

Permalink
Add function to remove active work list entries.
Browse files Browse the repository at this point in the history
Later on, we can add re-use of the indexes, to prevent an ever-growing
array.
  • Loading branch information
jnthn committed Jan 18, 2017
1 parent 40f4a7e commit 4241f5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/io/eventloop.c
Expand Up @@ -173,3 +173,18 @@ MVMAsyncTask * MVM_io_eventloop_get_active_work(MVMThreadContext *tc, int work_i
MVM_panic(1, "use of invalid eventloop work item index %d", work_idx);
}
}

/* Removes an active work index from the active work list, enabling any
* memory associated with it to be collected. Replaces the work index with -1
* so that any future use of the task will be a failed lookup. */
void MVM_io_eventloop_remove_active_work(MVMThreadContext *tc, int *work_idx_to_clear) {
int work_idx = *work_idx_to_clear;
if (work_idx >= 0 && work_idx < MVM_repr_elems(tc, tc->instance->event_loop_active)) {
*work_idx_to_clear = -1;
MVM_repr_bind_pos_o(tc, tc->instance->event_loop_active, work_idx, tc->instance->VMNull);
/* TODO: start to re-use the indices */
}
else {
MVM_panic(1, "cannot remove invalid eventloop work item index %d", work_idx);
}
}
1 change: 1 addition & 0 deletions src/io/eventloop.h
Expand Up @@ -21,3 +21,4 @@ void MVM_io_eventloop_send_cancellation_notification(MVMThreadContext *tc, MVMAs

int MVM_io_eventloop_add_active_work(MVMThreadContext *tc, MVMObject *async_task);
MVMAsyncTask * MVM_io_eventloop_get_active_work(MVMThreadContext *tc, int work_idx);
void MVM_io_eventloop_remove_active_work(MVMThreadContext *tc, int *work_idx_to_clear);

0 comments on commit 4241f5e

Please sign in to comment.