sc_bool _sc_iterator3_f_a_a_next(sc_iterator3 *it) { sc_addr arc_addr; SC_ADDR_MAKE_EMPTY(arc_addr); if (it->finished == SC_TRUE) return SC_FALSE; it->results[0] = it->params[0].addr; // try to find first output arc if (SC_ADDR_IS_EMPTY(it->results[1])) { sc_element *el = 0; STORAGE_CHECK_CALL(sc_storage_element_lock(it->ctx, it->params[0].addr, &el)); g_assert(el != null_ptr); arc_addr = el->first_out_arc; STORAGE_CHECK_CALL(sc_storage_element_unlock(it->ctx, it->params[0].addr)); }else { sc_element *el = 0; STORAGE_CHECK_CALL(sc_storage_element_lock(it->ctx, it->results[1], &el)); g_assert(el != null_ptr); arc_addr = el->arc.next_out_arc; _sc_iterator_unref_element(it->ctx, el, it->results[1]); STORAGE_CHECK_CALL(sc_storage_element_unlock(it->ctx, it->results[1])); } // iterate throught output arcs while (SC_ADDR_IS_NOT_EMPTY(arc_addr)) { sc_element *el = 0; // lock required elements to prevent deadlock with deletion while (el == null_ptr) STORAGE_CHECK_CALL(sc_storage_element_lock_try(it->ctx, arc_addr, s_max_iterator_lock_attempts, &el)); if (!sc_element_itref_add(sc_storage_get_element_meta(it->ctx, arc_addr))) { STORAGE_CHECK_CALL(sc_storage_element_unlock(it->ctx, arc_addr)); continue; } sc_addr next_out_arc = el->arc.next_out_arc; if (sc_element_is_request_deletion(el) == SC_FALSE) { sc_addr arc_end = el->arc.end; sc_type arc_type = el->flags.type; sc_access_levels arc_access = el->flags.access_levels; sc_access_levels end_access; if (sc_storage_get_access_levels(it->ctx, arc_end, &end_access) != SC_RESULT_OK) end_access = sc_access_lvl_make_max; STORAGE_CHECK_CALL(sc_storage_element_unlock(it->ctx, arc_addr)); sc_type el_type; sc_storage_get_element_type(it->ctx, arc_end, &el_type); if (sc_iterator_compare_type(arc_type, it->params[1].type) && sc_iterator_compare_type(el_type, it->params[2].type) && sc_access_lvl_check_read(it->ctx->access_levels, arc_access) && sc_access_lvl_check_read(it->ctx->access_levels, end_access) ) { // store found result it->results[1] = arc_addr; it->results[2] = arc_end; return SC_TRUE; } } else { _sc_iterator_unref_element(it->ctx, el, arc_addr); STORAGE_CHECK_CALL(sc_storage_element_unlock(it->ctx, arc_addr)); } // go to next arc arc_addr = next_out_arc; } it->finished = SC_TRUE; return SC_FALSE; }
sc_bool _sc_iterator3_a_a_f_next(sc_iterator3 *it) { sc_addr arc_addr; SC_ADDR_MAKE_EMPTY(arc_addr) it->results[2] = it->params[2].addr; // try to find first input arc if (SC_ADDR_IS_EMPTY(it->results[1])) { sc_element *el = 0; STORAGE_CHECK_CALL(sc_storage_element_lock(it->ctx, it->params[2].addr, &el)); g_assert(el != null_ptr); arc_addr = el->first_in_arc; STORAGE_CHECK_CALL(sc_storage_element_unlock(it->ctx, it->params[2].addr)); }else { sc_element *el = 0; STORAGE_CHECK_CALL(sc_storage_element_lock(it->ctx, it->results[1], &el)); g_assert(el != null_ptr); arc_addr = el->arc.next_in_arc; _sc_iterator_unref_element(it->ctx, el, it->results[1]); STORAGE_CHECK_CALL(sc_storage_element_unlock(it->ctx, it->results[1])); } // trying to find input arc, that created before iterator, and wasn't deleted while (SC_ADDR_IS_NOT_EMPTY(arc_addr)) { sc_element *el = 0; while (el == null_ptr) STORAGE_CHECK_CALL(sc_storage_element_lock_try(it->ctx, arc_addr, s_max_iterator_lock_attempts, &el)); if (!sc_element_itref_add(sc_storage_get_element_meta(it->ctx, arc_addr))) { STORAGE_CHECK_CALL(sc_storage_element_unlock(it->ctx, arc_addr)); continue; } sc_addr next_in_arc = el->arc.next_in_arc; if (sc_element_is_request_deletion(el) == SC_FALSE) { sc_type arc_type = el->flags.type; sc_addr arc_begin = el->arc.begin; sc_access_levels arc_access = el->flags.access_levels; sc_access_levels begin_access; if (sc_storage_get_access_levels(it->ctx, arc_begin, &begin_access) != SC_RESULT_OK) begin_access = sc_access_lvl_make_max; STORAGE_CHECK_CALL(sc_storage_element_unlock(it->ctx, arc_addr)); sc_type el_type = 0; sc_storage_get_element_type(it->ctx, arc_begin, &el_type); if (sc_iterator_compare_type(arc_type, it->params[1].type) && sc_iterator_compare_type(el_type, it->params[0].type) && sc_access_lvl_check_read(it->ctx->access_levels, arc_access) && sc_access_lvl_check_read(it->ctx->access_levels, begin_access) ) { // store found result it->results[1] = arc_addr; it->results[0] = arc_begin; return SC_TRUE; } } else { _sc_iterator_unref_element(it->ctx, el, arc_addr); STORAGE_CHECK_CALL(sc_storage_element_unlock(it->ctx, arc_addr)); } // go to next arc arc_addr = next_in_arc; } it->finished = SC_TRUE; return SC_FALSE; }
sc_result sc_memory_get_element_type(sc_memory_context const * ctx, sc_addr addr, sc_type *result) { return sc_storage_get_element_type(ctx, addr, result); }