std::shared_ptr wait()

in src/kernel_aio.cc [258:292]


			std::shared_ptr<IAsyncIop> wait(int group_id) {
				if (!started) assert(!"IOManager not started!");

				groups_mutex.lock();
				auto group = groups[group_id];
				groups_mutex.unlock();

				// wait on a single event
				io_event event = {0};
				int err = io_getevents(group->ctx, 1, 1, &event, NULL);
				if (err != 1) {
					perror("IOManager failed: io_getevents returned unexpected result");
					exit(1);
				}

				// get the op
				void * in_flight_id = event.data;
				auto op = group->in_flight[in_flight_id];
				group->in_flight.erase(in_flight_id);

				// remove from cbarray, destroy array if need be
				auto array = op->cb_array;
				--array->items_left;
				if (!array->items_left) {
					free(array->array); // free the malloc'd memory
					group->arrays.erase(array); // remove from the set
					// the only remaining reference to this CbArray is in the ops that used it
					// it will be overwritten and eventually destroyed automatically
				}

				// update return and error fields
				op->result = (int)event.res;

				return op;
			}