char wxStreamBuffer::GetChar() { wxInputStream *inStream = GetInputStream(); wxCHECK_MSG( inStream, 0, _T("should have a stream in wxStreamBuffer") ); char c; if ( !HasBuffer() ) { inStream->OnSysRead(&c, sizeof(c)); } else { if ( !GetDataLeft() ) { SetError(wxSTREAM_READ_ERROR); c = 0; } else { GetFromBuffer(&c, sizeof(c)); m_stream->m_lastcount = 1; } } return c; }
void wxStreamBuffer::PutChar(char c) { wxOutputStream *outStream = GetOutputStream(); wxCHECK_RET( outStream, _T("should have a stream in wxStreamBuffer") ); // if we don't have buffer at all, just forward this call to the stream, if ( !HasBuffer() ) { outStream->OnSysWrite(&c, sizeof(c)); } else { // otherwise check we have enough space left if ( !GetDataLeft() && !FlushBuffer() ) { // we don't SetError(wxSTREAM_WRITE_ERROR); } else { PutToBuffer(&c, sizeof(c)); m_stream->m_lastcount = 1; } } }
size_t wxStreamBuffer::Read(void *buffer, size_t size) { wxASSERT_MSG( buffer, _T("Warning: Null pointer is about to be used") ); /* Clear buffer first */ memset(buffer, 0x00, size); // lasterror is reset before all new IO calls if ( m_stream ) m_stream->Reset(); size_t readBytes; if ( !HasBuffer() ) { wxInputStream *inStream = GetInputStream(); wxCHECK_MSG( inStream, 0, _T("should have a stream in wxStreamBuffer") ); readBytes = inStream->OnSysRead(buffer, size); } else // we have a buffer, use it { size_t orig_size = size; while ( size > 0 ) { size_t left = GetDataLeft(); // if the requested number of bytes if greater than the buffer // size, read data in chunks if ( size > left ) { GetFromBuffer(buffer, left); size -= left; buffer = (char *)buffer + left; if ( !FillBuffer() ) { SetError(wxSTREAM_EOF); break; } } else // otherwise just do it in one gulp { GetFromBuffer(buffer, size); size = 0; } } readBytes = orig_size - size; } if ( m_stream ) m_stream->m_lastcount = readBytes; return readBytes; }
char wxStreamBuffer::Peek() { wxCHECK_MSG( m_stream && HasBuffer(), 0, _T("should have the stream and the buffer in wxStreamBuffer") ); if ( !GetDataLeft() ) { SetError(wxSTREAM_READ_ERROR); return 0; } char c; GetFromBuffer(&c, sizeof(c)); m_buffer_pos--; return c; }
BOOL ObjectBuffer::RemoveBuffer(Buffer* buf, BOOL bSync) { QCONFIRM_RET_FALSE(buf); if(!HasBuffer(buf)) return TRUE; for (BUFFER_ARRAY::iterator it_buf = m_arrBuffers.begin(); it_buf != m_arrBuffers.end(); ++it_buf) { if ((*it_buf) == buf) { m_arrBuffers.erase(it_buf); break; } } if (buf->IsSync() && bSync) { Broadcast_RemoveBuffer(buf); } return TRUE; }
size_t wxStreamBuffer::Write(const void *buffer, size_t size) { wxASSERT_MSG( buffer, _T("Warning: Null pointer is about to be send") ); if (m_stream) { // lasterror is reset before all new IO calls m_stream->Reset(); } size_t ret; if ( !HasBuffer() && m_fixed ) { wxOutputStream *outStream = GetOutputStream(); wxCHECK_MSG( outStream, 0, _T("should have a stream in wxStreamBuffer") ); // no buffer, just forward the call to the stream ret = outStream->OnSysWrite(buffer, size); } else // we [may] have a buffer, use it { size_t orig_size = size; while ( size > 0 ) { size_t left = GetBytesLeft(); // if the buffer is too large to fit in the stream buffer, split // it in smaller parts // // NB: If stream buffer isn't fixed (as for wxMemoryOutputStream), // we always go to the second case. // // FIXME: fine, but if it fails we should (re)try writing it by // chunks as this will (hopefully) always work (VZ) if ( size > left && m_fixed ) { PutToBuffer(buffer, left); size -= left; buffer = (char *)buffer + left; if ( !FlushBuffer() ) { SetError(wxSTREAM_WRITE_ERROR); break; } m_buffer_pos = m_buffer_start; } else // we can do it in one gulp { PutToBuffer(buffer, size); size = 0; } } ret = orig_size - size; } if (m_stream) { // i am not entirely sure what we do this for m_stream->m_lastcount = ret; } return ret; }
/* #ifdef MULTICAST void InterconnectInterface::Push(unsigned input_deviceID, unsigned output_deviceID, void *data, unsigned int size, int subnetwork) #else */ void InterconnectInterface::Push(unsigned input_deviceID, unsigned output_deviceID, void *data, unsigned int size) //#endif { // added by hpclms if(g_hpcl_comp_config.hpcl_local_en == 1) { cout<<"==========================================================\n"; cout<<" ENABLED LOCAL BASED COMPRESSION \n"; cout<<"==========================================================\n"; mem_fetch* mf_local = static_cast<mem_fetch*>(data); cout<<" Size : "<<size<<"\n"; int data_size = mf_local->get_real_data_size(); cout<<" DATA Size "<<data_size<<"\n"; for(int i=0;i<data_size;++i) { cout<<(char)mf_local->get_real_data(i); cout<<" -- RAW DATA -- "<<i<<"\n"; cout<<"\t"; } } // it should have free buffer assert(HasBuffer(input_deviceID, size)); int output_icntID = _node_map[output_deviceID]; int input_icntID = _node_map[input_deviceID]; #if 0 cout<<"Call interconnect push input: "<<input<<" output: "<<output<<endl; #endif //TODO: move to _IssuePacket //TODO: create a Inject and wrap _IssuePacket and _GeneratePacket unsigned int n_flits = size / _flit_size + ((size % _flit_size)? 1:0); int subnet; if (_subnets == 1) { subnet = 0; } else { //deleted by kh (021316) /* if (input_deviceID < _n_shader ) subnet = 0; else subnet = 1; */ //added by kh (021316) mem_fetch* mf = static_cast<mem_fetch*>(data); if((mf->get_type() == READ_REQUEST) || (mf->get_type() == WRITE_REQUEST)) subnet = 0; else if((mf->get_type() == READ_REPLY) || (mf->get_type() == WRITE_ACK)) subnet = 1; else assert(0); /// } //TODO: Remove mem_fetch to reduce dependency Flit::FlitType packet_type; mem_fetch* mf = static_cast<mem_fetch*>(data); switch (mf->get_type()) { case READ_REQUEST: packet_type = Flit::READ_REQUEST ;break; case WRITE_REQUEST: packet_type = Flit::WRITE_REQUEST ;break; case READ_REPLY: packet_type = Flit::READ_REPLY ;break; case WRITE_ACK: packet_type = Flit::WRITE_REPLY ;break; default: assert (0); } //TODO: _include_queuing ? _traffic_manager->_GeneratePacket( input_icntID, -1, 0 /*class*/, _traffic_manager->_time, subnet, n_flits, packet_type, data, output_icntID); #if DOUB cout <<"Traffic[" << subnet << "] (mapped) sending form "<< input_icntID << " to " << output_icntID << endl; #endif // } }