/* * * 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 internal function used to add a page of slots (of BPBUFF_MEM_PAGE size). * WARNING: the function assumes that the caller (bp_write or bp_getslot) locked the buffer mutex * @return the first BPSlot of new added page of slots. * */ BPSlot *bp_addpage(BPBuffer * buffer, BPSlot * prev) { BPSlot *added; unsigned int i; ptrdiff_t prev_diff; switch (buffer->type) { case buff_shm: prev_diff = prev - buffer->slots; added = bp_shm_addpage(buffer); prev = buffer->slots + prev_diff; buffer->slots[buffer->known_slots - 1].next = prev->next; // last added slot in shm new page is linked to the prev->next in old queue bp_log(FNC_LOG_DEBUG, "BPSlots page added in SHM memory (%u slots - %s)\n", buffer->known_slots, buffer->filename); break; case buff_local: prev_diff = prev - buffer->slots; if (!(added = realloc(buffer->slots, (buffer->control->nslots + BPBUFF_MEM_PAGE) * sizeof(BPSlot)))) return NULL; buffer->slots = added; prev = buffer->slots + prev_diff; // init new slots for (i = buffer->control->nslots; i < buffer->control->nslots + BPBUFF_MEM_PAGE - 1; i++) { added[i].refs = 0; added[i].slot_seq = 0; added[i].next = i + 1; } // last slot added[i].refs = 0; added[i].slot_seq = 0; added[i].next = prev->next; added = &added[buffer->control->nslots]; buffer->control->nslots += BPBUFF_MEM_PAGE; buffer->known_slots = buffer->control->nslots; bp_log(FNC_LOG_DEBUG, "BPSlots page added in local bufferpool (%u slots)\n", buffer->known_slots); break; default: return NULL; break; } prev->next = BPtoSlotPtr(buffer, added); return added; }