int8 RingBuffer::read(uint8 *dat) { uint32 bufsize = 0; uint32 tmprp = 0; if (g_wcounter <= (g_rcounter+1)) { tmprp = 0; } if (checkReadData() < 0) { return -1; } g_rcounter++; tmprp = readBuffer(sizeof(bufsize), this->m_rp, (uint8 *)&bufsize); //没到结尾处,直接取 if (bufsize + this->m_rp < this->m_size) { std::string ret = std::string(this->m_buffer[tmprp], bufsize); dat = (uint8 *)ret.c_str(); tmprp = (tmprp + bufsize) % this->m_size; } else tmprp = readBuffer(bufsize, tmprp, dat); setReadPoint(tmprp); return 0; }
virtual void readDone(unsigned int tag) { if ( verbose ) { //printf( "%s received read page buffer: %d %d\n", log_prefix, rbuf, curReadsInFlight ); printf( "LOG: pagedone: tag=%d; inflight=%d\n", tag, curReadsInFlight ); fflush(stdout); } //check checkReadData(tag); pthread_mutex_lock(&flashReqMutex); curReadsInFlight --; if ( curReadsInFlight < 0 ) { fprintf(stderr, "LOG: **ERROR: Read requests in flight cannot be negative %d\n", curReadsInFlight ); curReadsInFlight = 0; } if ( readTagTable[tag].busy == false ) { fprintf(stderr, "LOG: **ERROR: received unused buffer read done %d\n", tag); testPass = 0; } readTagTable[tag].busy = false; //pthread_cond_broadcast(&flashFreeTagCond); pthread_mutex_unlock(&flashReqMutex); }
virtual void readDone(unsigned int tag, unsigned int status) { bool tempPassed = true; printf("LOG: readdone: tag=%d inflight=%d\n", tag, curReadsInFlight ); fflush(stdout); //check tempPassed = checkReadData(tag); pthread_mutex_lock(&flashReqMutex); curReadsInFlight --; if ( tempPassed == false ) { testPassed = false; printf("LOG: **ERROR: check read data failed @ tag=%d\n",tag); } if ( curReadsInFlight < 0 ) { fprintf(stderr, "LOG: **ERROR: Read requests in flight cannot be negative %d\n", curReadsInFlight ); curReadsInFlight = 0; } if ( readTagTable[tag].busy == false ) { fprintf(stderr, "LOG: **ERROR: received unused buffer read done %d\n", tag); testPassed = false; } readTagTable[tag].busy = false; pthread_mutex_unlock(&flashReqMutex); }