| 2013 | } |
| 2014 | |
| 2015 | LIBFDB_API |
| 2016 | fdb_status fdb_iterator_prev(fdb_iterator *iterator) |
| 2017 | { |
| 2018 | if (!iterator) { |
| 2019 | return FDB_RESULT_INVALID_HANDLE; |
| 2020 | } |
| 2021 | |
| 2022 | fdb_status result = FDB_RESULT_SUCCESS; |
| 2023 | |
| 2024 | if (!atomic_cas_uint8_t(&iterator->handle->handle_busy, 0, 1)) { |
| 2025 | return FDB_RESULT_HANDLE_BUSY; |
| 2026 | } |
| 2027 | |
| 2028 | if (iterator->hbtrie_iterator) { |
| 2029 | while ((result = _fdb_iterator_prev(iterator)) == |
| 2030 | FDB_RESULT_KEY_NOT_FOUND); |
| 2031 | } else { |
| 2032 | while ((result = _fdb_iterator_seq_prev(iterator)) == |
| 2033 | FDB_RESULT_KEY_NOT_FOUND); |
| 2034 | } |
| 2035 | if (result == FDB_RESULT_SUCCESS) { |
| 2036 | iterator->direction = FDB_ITR_REVERSE; |
| 2037 | } else { |
| 2038 | iterator->_dhandle = NULL; // fail fdb_iterator_get also |
| 2039 | if (iterator->direction != FDB_ITR_DIR_NONE) { |
| 2040 | iterator->direction = FDB_ITR_DIR_NONE; |
| 2041 | if ((iterator->seqtree_iterator || iterator->seqtrie_iterator) && |
| 2042 | iterator->status == FDB_ITR_IDX) { |
| 2043 | iterator->_offset = BLK_NOT_FOUND; |
| 2044 | } |
| 2045 | if (iterator->tree_cursor) { |
| 2046 | iterator->tree_cursor = avl_next(iterator->tree_cursor); |
| 2047 | if (iterator->tree_cursor && |
| 2048 | iterator->status == FDB_ITR_WAL) { |
| 2049 | // if the last document was returned from WAL, |
| 2050 | // shift again, past curkey into next |
| 2051 | iterator->tree_cursor = avl_next(iterator->tree_cursor); |
| 2052 | } |
| 2053 | } |
| 2054 | } |
| 2055 | } |
| 2056 | |
| 2057 | atomic_cas_uint8_t(&iterator->handle->handle_busy, 1, 0); |
| 2058 | atomic_incr_uint64_t(&iterator->handle->op_stats->num_iterator_moves); |
| 2059 | return result; |
| 2060 | } |
| 2061 | |
| 2062 | LIBFDB_API |
| 2063 | fdb_status fdb_iterator_next(fdb_iterator *iterator) |
nothing calls this directly
no test coverage detected