/** * Copyright (C) ARM Limited 2010-2012. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include #include #include #include "Fifo.h" #include "Logging.h" extern void handleException(); Fifo::Fifo(int numBuffers, int bufferSize) { int which; if (numBuffers > FIFO_BUFFER_LIMIT) { logg->logError(__FILE__, __LINE__, "Number of fifo buffers exceeds maximum"); handleException(); } mNumBuffers = numBuffers; mBufferSize = bufferSize; mWriteCurrent = 0; mReadCurrent = mNumBuffers - 1; // (n-1) pipelined for (which=0; whichlogError(__FILE__, __LINE__, "sem_init(%d) failed", which); handleException(); } // page-align allocate buffers mBuffer[which] = (char*)valloc(bufferSize); if (mBuffer[which] == NULL) { logg->logError(__FILE__, __LINE__, "failed to allocate %d bytes", bufferSize); handleException(); } // touch each page to fault it in for (int i=0; i