static void SQLX_REMOVE(sqlx_cache_t *cache, sqlx_base_t *base, struct beacon_s *beacon) { sqlx_base_t *next, *prev; /* Update the beacon */ if (beacon->first == base->index) beacon->first = sqlx_base_get_id(sqlx_next_by_id(cache, beacon->first)); if (beacon->last == base->index) beacon->last = sqlx_base_get_id(sqlx_prev_by_id(cache, beacon->last)); /* Update the previous and next */ next = sqlx_get_by_id(cache, base->link.next); prev = sqlx_get_by_id(cache, base->link.prev); if (prev) prev->link.next = sqlx_base_get_id(next); if (next) next->link.prev = sqlx_base_get_id(prev); /* Update the base itself */ base->status = 0; base->link.prev = -1; base->link.next = -1; }
static sqlx_base_t * sqlx_prev_by_id(sqlx_cache_t *cache, gint i) { sqlx_base_t *current; return (current = sqlx_get_by_id(cache, i)) ? sqlx_get_by_id(cache, current->link.prev) : NULL; }
static inline sqlx_base_t * sqlx_next_by_id(sqlx_cache_t *cache, gint i) { sqlx_base_t *current; return (current = sqlx_get_by_id(cache, i)) ? sqlx_get_by_id(cache, current->link.next) : NULL; }
static sqlx_base_t* sqlx_poll_free_base(sqlx_cache_t *cache) { sqlx_base_t *base; base = sqlx_get_by_id(cache, cache->beacon_free.first); if (!base) { errno = ENOENT; return NULL; } return base; }
static void SQLX_UNSHIFT(sqlx_cache_t *cache, sqlx_base_t *base, struct beacon_s *beacon, enum sqlx_base_status_e status) { sqlx_base_t *first; base->link.prev = base->link.next = -1; base->link.next = beacon->first; first = sqlx_get_by_id(cache, beacon->first); if (first) first->link.prev = base->index; beacon->first = base->index; if (beacon->last < 0) beacon->last = base->index; base->status = status; g_get_current_time(&(base->last_update)); }