/* * * 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 #include #define RETURN_ERR do { \ bp_unlock(cons->buffer); \ return 1; \ } while (0) /* ! move current read position * * @return 1 on error, 0 otherwise * */ int bp_gotreader(BPConsumer * cons) { BPSlot *last_read; BPSlot *next; bp_lock(cons->buffer); if (bp_shm_refresh(cons->buffer)) RETURN_ERR; 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)) next = &cons->buffer->slots[last_read->next]; else RETURN_ERR; } else if (last_read && (cons->buffer->slots[last_read->next].slot_seq < next->slot_seq)) next = &cons->buffer->slots[last_read->next]; next->refs--; cons->last_seq = next->slot_seq; // if ( msync(next, sizeof(BPSlot), MS_ASYNC) ) // if ( msync(cons->buffer->slots, cons->buffer->known_slots * sizeof(BPSlot), MS_ASYNC) ) // printf("*** slot msync error\n"); cons->last_read_pos = BPtoSlotPtr(cons->buffer, next); cons->read_pos = next->next; // cons->read_pos->refs--; bp_dump(cons, NULL); bp_unlock(cons->buffer); // return cons->read_pos; return 0; // next; } #undef RETURN_ERR