/* * * 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 /*! @brief get a new empty slot from bufferpool. * * It do NOT mark the slot as busy, this action will be performed by * bp_write that MUST be called at the end of operations with the obtained * slot. * * @return empty slot. */ BPSlot *bp_getslot(BPBuffer * buffer) { BPSlot *slot; bp_lock(buffer); if (bp_shm_refresh(buffer)) return NULL; slot = &buffer->slots[buffer->control->write_pos]; if (buffer->slots[slot->next].refs > 0) { if (!(slot = bp_addpage(buffer, slot))) { bp_unlock(buffer); return NULL; } } else { slot = &buffer->slots[slot->next]; } bp_unlock(buffer); return slot; }