// // memrdma.cc // Based on memamsg.cc // // Copyright (C) 1996 Limit Point Systems, Inc. // // Author: Curtis Janssen // Maintainer: LPS // // This file is part of the SC Toolkit. // // The SC Toolkit is free software; you can redistribute it and/or modify // it under the terms of the GNU Library General Public License as published by // the Free Software Foundation; either version 2, or (at your option) // any later version. // // The SC Toolkit 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 Library General Public License for more details. // // You should have received a copy of the GNU Library General Public License // along with the SC Toolkit; see the file COPYING.LIB. If not, write to // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. // // The U.S. Government is granted a limited license as per AL 91-7. // #ifndef _util_group_memrdma_cc #define _util_group_memrdma_cc #ifdef __GNUC__ #pragma implementation #endif #include #include #include #include #include #include using namespace std; using namespace sc; #ifdef HAVE_HRECV # define DISABLE do { masktrap(1); ExEnv::outn().flush(); } while(0) # define ENABLE do { ExEnv::outn().flush(); masktrap(0); } while(0) extern "C" { long masktrap(long state); } #else # define DISABLE ExEnv::outn().flush() # define ENABLE ExEnv::outn().flush() #endif #define PRINTF(args) do { DISABLE; \ ExEnv::outn() << scprintf args ; \ ExEnv::outn().flush(); \ ENABLE; \ } while(0) #undef PRINTF #define PRINTF(args) /////////////////////////////////////////////////////////////////////// // Members for RDMAMemoryGrp static ClassDesc RDMAMemoryGrp_cd( typeid(RDMAMemoryGrp),"RDMAMemoryGrp",1,"public MsgMemoryGrp", 0, 0, 0); RDMAMemoryGrp::RDMAMemoryGrp(const Ref& msg): MsgMemoryGrp(msg) { data_ = 0; default_pool_size_ = 1000000; } RDMAMemoryGrp::RDMAMemoryGrp(const Ref& keyval): MsgMemoryGrp(keyval) { data_ = 0; default_pool_size_ = 1000000; } void* RDMAMemoryGrp::malloc_region(size_t nbyte) { void *data = 0; for (int i=0; data==0 && iallocate(nbyte); } if (data == 0) { if (default_pool_size_ < nbyte) default_pool_size_ = nbyte * 2; else if (pools_.size() > 4) default_pool_size_ *= 2; void *pooldata = malloc_local(default_pool_size_); Pool *pool = new(pooldata) Pool(default_pool_size_); pools_.push_back(pool); data = pool->allocate(nbyte); } return data; } void RDMAMemoryGrp::free_region(void*data) { char *cdata = reinterpret_cast(data); for (int i=0; i(pools_[i]); if (cdata > pstart && cdata < &pstart[pools_[i]->size()]) { pools_[i]->release(data); return; } } throw ProgrammingError("could not find data to release in a Pool", __FILE__, __LINE__, this->class_desc()); } void RDMAMemoryGrp::set_localsize(size_t localsize) { for (int i=0; i