/* * * 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 #include #include #include #include #ifndef BPBUFF_REALLOC /*@brief internal function used to add a slot or, in case of shared memory, a page of slots * (of BPBUFF_SHM_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_slotadd(BPBuffer * buffer, BPSlot * prev) { BPSlot *added; BPSlotPtr prev_diff; switch (buffer->type) { case buff_shm: prev_diff = BPtoSlotPtr(buffer, prev); 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\n"); break; case buff_local: default: if (!(added = calloc(1, sizeof(BPSlotAdded)))) return NULL; ((BPSlotAdded *) added)->next_added = buffer->added_slots; buffer->added_slots = (BPSlotAdded *) added; added->next = prev->next; bp_log(FNC_LOG_DEBUG, "slot added\n"); break; } prev->next = BPtoSlotPtr(buffer, added); return added; } #endif // BPBUFF_REALLOC