/* * * This file is part of bufferpool * * Copyright (C) 2007 by LScube team * See AUTHORS for more details * * bufferpool is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * bufferpool is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with bufferpool; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include #define RETURN(x) do { \ bp_unlock(cons->buffer); \ return x; \ } while (0) /*! Check if buffer is empty for a given consumer. * * Checks in this function are taken from bp_read() and not * optimized * * @param Consumer to be checked. * @return 1 if buffer is empty, 0 if not. * @return -1 on error. * * @see bp_read * */ int bp_isempty(BPConsumer * cons) { BPSlot *last_read; BPSlot *next; bp_lock(cons->buffer); if(bp_shm_refresh(cons->buffer)) RETURN(-1); last_read = BPtoSlot(cons->buffer, cons->last_read_pos); next = &cons->buffer->slots[cons->read_pos]; if (!next->refs || (next->slot_seq < cons->last_seq)) { // added some slots? if (last_read && cons->buffer->slots[last_read->next].refs && (cons->buffer->slots[last_read->next].slot_seq > cons->last_seq)) RETURN(0); else RETURN(1); } else if (last_read && (cons->buffer->slots[last_read->next].slot_seq < next->slot_seq)) RETURN(0); bp_unlock(cons->buffer); return 0; } #undef RETURN