亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? shared_memory.h

?? 簡(jiǎn)單的動(dòng)態(tài)內(nèi)存管理程序源代碼
?? H
?? 第 1 頁(yè) / 共 3 頁(yè)
字號(hào):
    bit_vec(num_of_segments,bit_vector_buff) {    // initialize out to end of the bit_vector buffer    for (int i=0; i<bit_vec_size; i++) {//       shmid[i]=-1;//       buffers[i]=0;      bit_vector_buff[i]=0;    }    mem_ptr = 0;    // finish initializing the other buffers to num_of_segments//    for (int i=bit_vec_size+1; i<num_of_segments; i++) {//       shmid[i]=-1;//       buffers[i]=0;//     }  };  // constructor    // destructor  template<allocator_key_t alloc_key, allocator_addr_t alloc_addr>  shared<alloc_key, alloc_addr>::~shared() {    // Just the bit_vec should be automatically destroyed.    // Opposite of the constructor    // Check the reference count on the shared memory segment    // If last object referencing shared memory, delete it #ifdef DEBUG    std::cerr << __FILE__ << ":" << __LINE__ <<      " ~shared() : mem_ptr : " << mem_ptr << std::endl;#endif    // unmap shared memory    for(mappings_t::iterator it = mappings.begin(); it != mappings.end(); it++) {      // for each segment in the shared object      // if it is not referenced, unlink it#ifdef DEBUG      std::cerr << __FILE__ << ":" << __LINE__ << " ~shared() : alloc_addr : "		<< it->first << std::endl;#endif      shared_memory_header_t* smh = static_cast<shared_memory_header_t*>(it->second.first);      int ref_count = smh->get_ref_count();#ifdef DEBUG      std::cerr << __FILE__ << ":" << __LINE__ << " ~shared() : ref_count : "		<< ref_count << std::endl;#endif      std::cerr.flush();      if (!ref_count) {	smh->~shared_memory_header_t();	int ret_val = munmap(it->second.first, it->second.second.st_size);	if (ret_val == -1) {	  std::clog << "Status: " << __FILE__ << ':' << __LINE__ ;	  std::clog << ": shared memory munmap: " << strerror(errno) << std::endl;	}	// unlink shared memory	std::clog << "Status: " << __FILE__ << ':' << __LINE__ ;	std::clog << ": shared memory shm_unlink called" << std::endl;	ret_val = shm_unlink(it->first.data());	if (ret_val == -1) {	  std::clog << "Status: " << __FILE__ << ':' << __LINE__ ;	  std::clog << ": shared memory shm_unlink: " << strerror(errno) << std::endl;	  std::clog << "Shared memory segement: " << it->first.data() << std::endl;	}#ifdef DEBUG	std::cerr << __FILE__ << ":" << __LINE__ <<	  " ~shared() deleting shm : " << std::endl;#endif	// delete the map key	mappings.erase(it);      }    }  };  // destructor  //     }//     std::map<allocator_key_t,//       std::pair<void*,struct stat> >::iterator it = mappings.find(alloc_key);//     if (it != mappings.end()) {//       // Both initialized and mapped. Retrieve pointer and allocation is over.//       // first, destroy the locks//       } else {// 	// Other process still pointing  to the shared memory.  Do not// 	// remove the  shared memory// 	// Further  do  not   decrement  the  ref_count.   Only  those// 	// functions with actually allocate and deallocate memory from// 	// the  shared  memory  segment  change the  reference  count.// 	// Shared creates a segment if  it does not exist, and removes// 	// it  when  the  reference   count  is  zero  and  it  exits.// 	// Otherwise, the it does not affect the ref_count.// #ifdef DEBUG// 	std::cerr << __FILE__ << ":" << __LINE__ <<// 	  " ~shared() : decrementing ref_count: "  <<// 	  ref_count << std::endl;// #endif//       }  // copy constructor  template<allocator_key_t alloc_key, allocator_addr_t alloc_addr>  shared<alloc_key, alloc_addr>::shared(const shared<alloc_key, alloc_addr>& t)  :    // segment pages have no overhead, they are just space    num_of_pages(t.num_of_pages),    page_size(t.page_size),    segment_size (t.segment_size),    bit_vec(t.bit_vec) {    mem_ptr = t.mem_ptr;    // Most  of the  important shared::shared  attributes  are static.    // therefore there  is only one  version of them declared  for all    // process  objects.  They are  in a  sense global,  and therefore    // need  not be copied,  as the  same verison  is accessed  by all    // objects in the same process.  }; // copy constructor    // assignment operator  template<allocator_key_t alloc_key, allocator_addr_t alloc_addr>  shared<alloc_key,	 alloc_addr>& shared<alloc_key,			     alloc_addr>::operator=(const shared<alloc_key,						    alloc_addr>& t)  {    if (this != &t) {		// avoid self assignment: t=t      mem_ptr = t.mem_ptr;    }    return *this;  };  // assignment operator    ////////////////////////////////////////////////////////////////////  //////    shared<>::allocate(const int& proj_id)  ////////////////////////////////////////////////////////////////////  //////     //////    proj_id -    //////      //////    Creates a  large allocation of  shared memory used  by the  //////    allocator.  Returns a pointer to the newly allocated page,  //////    parameter  indicates if  the page  is newly  allocated and  //////    therefore NOT  initialized, or if the page  was already in  //////    use and simply attached.  //////      //////      //////      ////////////////////////////////////////////////////////////////////  // void* shared::allocate(allocator_key_t key_val) {  template<allocator_key_t alloc_key,	   allocator_addr_t alloc_addr>  memory_index_t shared<alloc_key,     			alloc_addr>::allocate(const int& proj_id) {// 			alloc_addr>::allocate() {    // alloc_key - string describing key name, identifies which     //             shared memory segment.    // returns  a  pointer  to  the newly  allocated  page,  parameter    // indicates  if the  page is  newly allocated  and  therefore NOT    // initialized,  or if  the page  was  already in  use and  simply    // attached.    // All shared memory blocks have the shared memory header class    // instantiated at the beginning of their memory space.	// Variables	//   initialized - describes  whether share memory segment has	//                 header installed.	//   mapped - describes whether the process has already mapped	//            this  shared  memory  segment  into  its virtual	//            memory.		// Possible senarios at this point:	//    1. Brand new shared memory segment, just created for the	//       first time.  Needs to be initiallized and mapped.	//    2. Existing shared memory segment:	//       a. Process has already  mapped this segment, retrieve	//          pointer from stored mapping	//       b. 1st time process is accessing this shared segment.	//          The segment needs to be mapped into this process's	//          shared memory space.    void* ptr = (void*) -1;    bool initialized = false;    struct stat stat;    int fd;            // open shared memory    // first try to open shared memory as if it already exists    // if that fails, create the shared memory and initialize it    std::stringstream alloc_key_ss;    // create the shared segment key    alloc_key_ss << alloc_key << "_" << proj_id;#ifdef DEBUG    std::cerr << __FILE__ << ":" << __LINE__ << " shared<>::allocate() : alloc_key_ss.str().data() : "	      << alloc_key_ss.str().data() << std::endl;#endif    if ((fd = shm_open(alloc_key_ss.str().data(), O_RDWR, S_IRWXU | S_IRWXG)) == -1) {      // Opening existing shared memory failed.  Create it.      fd = shm_open(alloc_key_ss.str().data(), O_RDWR|O_CREAT, S_IRWXU | S_IRWXG);      // now needs to be mapped      // truncate it to required size      if (ftruncate(fd, (off_t)segment_size) != -1) {	// get info on the shared memory segment file descriptor	fstat(fd, &stat);	// After  truncating the  file descriptor,  see if  the shared	// memory is already  mapped?  If so, return a  pointer to the	// existing mapped shared memory; otherwise, map it.	// convert the shared memory's requested address	// from its char string to an number.	std::string stringval(alloc_addr);	std::istringstream sin(stringval);	int x;	sin >> std::hex  >> x;		// add an offset based on the proj_id to the memory address	x = x + segment_size*(proj_id-1);#ifdef DEBUG	std::cerr << __FILE__ << ":" << __LINE__ << " shared<>::allocate() : alloc_addr : "		  << alloc_addr << std::endl;	std::cerr << __FILE__ << ":" << __LINE__ << " shared<>::allocate() : x : "		  << std::hex << x << std::dec << std::endl;#endif	// map shared memory	ptr =	  mmap((void*) x, stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);	// mmap((void*) x, stat.st_size, PROT_READ | PROT_WRITE, MAP_FIXED|MAP_SHARED, fd, 0);	if (ptr != MAP_FAILED) {	  //	    if (msync((void*) x, stat.st_size, MS_SYNC | MS_INVALIDATE) != -1) {	  // Install the memory header in the allocated shared memory	  // ref_count will be set to 0 by the constructor	  memset(ptr,0,stat.st_size);	  new(ptr)shared_memory_header_t(num_of_pages,					 page_size,					 alloc_key_ss.str().data(),					 (int) ptr,					 stat.st_size,					 proj_id);  // shmid	  // store off the successful mapping for future retrieval#ifdef DEBUG	  std::cerr << __FILE__ << ":" << __LINE__ << " shared<>::allocate() : " <<	    "Inserting map val alloc_key_ss.str() : "		    << alloc_key_ss.str() << std::endl;#endif	  mappings.insert(std::pair<std::string,			  std::pair<void*,struct stat> >(alloc_key_ss.str(),							 std::pair<void*,struct stat>(ptr,stat)));	}  else { // if (ptr != MAP_FAILED)	  // create an error message to throw with the exception	  std::stringstream s;	  s << "Error: " << __FILE__ << ':' << __LINE__ << ':'	    << " memory map mmap failed : " << strerror(errno) <<	    std::endl;	  std::clog << s;	  throw (Alloc_Exception::mmap_exception(s.str()));	}  // if (ptr != MAP_FAILED)      } else {  // if (ftruncate(fd, (off_t)segment_size) != -1)	// create an error message to throw with the exception	std::stringstream s;	s << "Error: " << __FILE__ << ':' << __LINE__ << ':'	  << " shared memory ftruncate: " << strerror(errno) <<	  std::endl;	std::clog << s;	throw (Alloc_Exception::shm_exception(s.str()));      }  // if (ftruncate(fd, (off_t)segment_size) != -1)    } else {  // if ((int fd = shm_open(alloc_key, O_RDWR, S_IRWXU | S_IRWXG)) == -1)      // shared memory already exists.  See if it has been mapped into      // this process's memory?      std::map<std::string,	std::pair<void*,struct stat> >::iterator it = mappings.find(alloc_key_ss.str());      if (it != mappings.end()) {	// shared memory segment has already been mapped into this segment	initialized = true;	ptr = it->second.first;      } else {  // if (it != mappings.end())	// shared memory segment has not yet been mapped	// memory map it	fstat(fd, &stat);	// convert the shared memory's requested address	// from its char string to an number.	std::string stringval(alloc_addr);	std::istringstream sin(stringval);	int x;	sin >> std::hex  >> x;	// add an offset based on the proj_id to the memory address	x = x + segment_size*(proj_id-1);#ifdef DEBUG	std::cerr << __FILE__ << ":" << __LINE__ << " shared<>::allocate() : alloc_addr : "		  << alloc_addr << std::endl;	std::cerr << __FILE__ << ":" << __LINE__ << " shared<>::allocate() : x : "		  << std::hex << x << std::dec << std::endl;#endif	ptr =	  mmap((void*) x, stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);	// mmap((void*) x, stat.st_size, PROT_READ | PROT_WRITE, MAP_FIXED|MAP_SHARED, fd, 0);	if (ptr == MAP_FAILED) {	  // create an error message to throw with the exception	  std::stringstream s;	  s << "Error: " << __FILE__ << ':' << __LINE__ << ':'	    << " memory map mmap failed : " << strerror(errno) <<	    std::endl;	  std::clog << s;	  throw (Alloc_Exception::mmap_exception(s.str()));	}  // if (ptr == MAP_FAILED)	// store off the successful mapping for future retrieval#ifdef DEBUG	std::cerr << __FILE__ << ":" << __LINE__ << " shared<>::allocate() : " <<	  "Inserting map val alloc_key_ss.str().data() : "		  << alloc_key_ss.str().data() << std::endl;#endif	mappings.insert(std::pair<std::string,			std::pair<void*,struct stat> >(alloc_key_ss.str(),						       std::pair<void*,struct stat>(ptr,stat)));	// Do not touch the  reference count, ref_count.  Only objects	// which allocate  and deallocate  memory from the  segment to	// the allocator  touch the reference counter.   If the shared	// object deconstructs  and the ref_count  is 0, it  takes the	// whole  segement  down   with  it.   Otherwise  the  segment	// persists.#ifdef DEBUG	shared_memory_header_t* smh = static_cast<shared_memory_header_t*>(ptr);	int ref_count = smh->get_ref_count();	std::cerr << __FILE__ << ":" << __LINE__ << " shared<>::allocate() : ref_count : "		  << ref_count << std::endl;#endif      }  // if (it != mappings.end())    } // if ((int fd = shm_open(alloc_key, O_RDWR, S_IRWXU | S_IRWXG)) == -1)    mem_ptr = ptr;    return memory_index_t(ptr, proj_id, initialized);      };  // shared<>::allocate(const int& proj_id)       ////////////////////////////////////////////////////////////////////  //////    shared<>::free(memory_index_t mem_idx)  ////////////////////////////////////////////////////////////////////  //////     //////    mem_idx -  contains description of shared  memory block to  //////               be freed by the function.  //////      //////    Release allocated shared memory segment  //////      //////      //////      ////////////////////////////////////////////////////////////////////      // free()  template<allocator_key_t alloc_key, allocator_addr_t alloc_addr>  bool shared<alloc_key, alloc_addr>::free() {        bool return_flag = true;#ifdef DEBUG    std::cerr << __FILE__ << ':' << __LINE__ << ": " << "shared<>::free()" << std::endl;#endif    return return_flag;  }; // bool shared::free(memory_index_t mem_idx)};  // namespace mem_space#endif // SHARED_MEMORY_H

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产乱一区二区| 午夜激情一区二区三区| 91精品国产高清一区二区三区| 成人黄色大片在线观看| 国产大陆a不卡| 国产另类ts人妖一区二区| 激情综合网最新| 国产伦精品一区二区三区免费| 韩国av一区二区三区在线观看| 国产真实乱对白精彩久久| 国产乱子伦视频一区二区三区| 国产精品亚洲一区二区三区妖精 | 在线播放一区二区三区| 色噜噜狠狠成人网p站| 亚洲柠檬福利资源导航| 日本欧美大码aⅴ在线播放| 精品国产乱码久久久久久图片 | 成人激情综合网站| 99久久99久久综合| 欧美日韩在线亚洲一区蜜芽| 777精品伊人久久久久大香线蕉| 这里只有精品视频在线观看| 欧美成人一区二区| 欧美国产国产综合| 亚洲成av人在线观看| 麻豆成人久久精品二区三区红 | 日韩情涩欧美日韩视频| 久久久久综合网| 亚洲欧美日韩电影| 激情都市一区二区| 国产一区二区在线视频| 色呦呦一区二区三区| 6080午夜不卡| 国产精品国产三级国产| 午夜视频在线观看一区二区| 国产乱码精品一区二区三区忘忧草| a美女胸又www黄视频久久| 精品国产乱码久久久久久免费| 中文字幕成人在线观看| 日韩电影在线观看网站| 丁香六月综合激情| 日韩一区二区麻豆国产| 国产精品第13页| 久久99精品久久久| 欧美日韩在线播放| 国产精品青草综合久久久久99| 日韩成人午夜精品| 色综合久久综合中文综合网| 久久中文娱乐网| 丝袜美腿高跟呻吟高潮一区| 99久久国产免费看| 国产免费成人在线视频| 蜜臀av国产精品久久久久 | 热久久国产精品| 91女神在线视频| 国产校园另类小说区| 蜜臀国产一区二区三区在线播放 | 亚洲成人一二三| 99国产一区二区三精品乱码| 久久久久久夜精品精品免费| 免费观看在线综合| 欧美日韩国产小视频| 一区二区三区鲁丝不卡| 99久久亚洲一区二区三区青草 | 成人黄色电影在线| 国产色91在线| 国产成人在线视频免费播放| 日韩精品一区二区三区四区视频| 午夜激情综合网| 欧美高清一级片在线| 丝袜脚交一区二区| 欧美夫妻性生活| 日韩精品国产欧美| 欧美日韩三级一区二区| 亚洲成人精品影院| 色系网站成人免费| 亚洲综合激情小说| 91久久人澡人人添人人爽欧美| 亚洲国产精品成人综合色在线婷婷 | 国产精品99久久久久久有的能看| 日韩精品一区二区三区中文不卡 | 日韩毛片视频在线看| 成人午夜免费av| 亚洲欧洲另类国产综合| 97精品久久久午夜一区二区三区| 国产精品国产三级国产| 色欧美片视频在线观看 | 国产婷婷精品av在线| 国产综合色产在线精品| 久久亚洲精精品中文字幕早川悠里 | 日韩激情av在线| 在线综合视频播放| 精品无人码麻豆乱码1区2区 | 日韩和欧美一区二区三区| 56国语精品自产拍在线观看| 青青草97国产精品免费观看无弹窗版| 欧美一区2区视频在线观看| 精品亚洲国内自在自线福利| 亚洲国产一区视频| 欧美乱妇23p| 国产高清亚洲一区| 一区二区三国产精华液| 欧美一区二区视频网站| 大尺度一区二区| 亚洲一区二区三区免费视频| 日韩欧美综合在线| 成人av免费在线| 天天av天天翘天天综合网| 久久色.com| 欧美视频自拍偷拍| 国产乱淫av一区二区三区| 一区二区三区成人在线视频| 久久综合成人精品亚洲另类欧美 | 蜜臀久久99精品久久久久久9| 久久久精品国产免大香伊| 色国产精品一区在线观看| 极品少妇一区二区| 亚洲一卡二卡三卡四卡| 国产视频一区不卡| 欧美一区二区高清| 欧洲视频一区二区| 国产成人午夜精品5599| 日韩成人伦理电影在线观看| 国产精品福利av| 日韩精品一区二区在线| 精品污污网站免费看| 成人美女视频在线观看18| 免费成人你懂的| 亚洲网友自拍偷拍| 五月天中文字幕一区二区| 综合激情网...| 欧美高清一级片在线观看| 日韩欧美不卡一区| 91麻豆精品国产91| 欧美三级中文字幕在线观看| 成人综合婷婷国产精品久久蜜臀| 麻豆专区一区二区三区四区五区| 亚洲在线视频一区| 自拍偷拍国产亚洲| 亚洲欧洲一区二区在线播放| 日本一区二区三区免费乱视频| 精品日韩欧美在线| 欧美一区二区三区性视频| 欧美性感一类影片在线播放| 91免费看`日韩一区二区| 成人激情动漫在线观看| 风间由美一区二区av101 | 国产精品美女久久久久久久久久久 | 成人精品视频一区二区三区尤物| 美女网站一区二区| 日本色综合中文字幕| 日韩国产成人精品| 免费久久精品视频| 看国产成人h片视频| 激情综合亚洲精品| 国产美女视频一区| 国产高清久久久| 国产99久久久精品| 99riav久久精品riav| 91小视频在线| 欧美在线视频不卡| 欧美日韩国产美女| 日韩一区二区免费高清| 亚洲精品一区二区三区四区高清| 久久综合久久综合九色| 国产性色一区二区| 亚洲日本va午夜在线影院| 亚洲资源中文字幕| 免费人成精品欧美精品| 国产一区二区三区不卡在线观看 | 在线观看国产91| 欧美丝袜自拍制服另类| 91精品久久久久久久久99蜜臂| 91精品国产综合久久久蜜臀粉嫩| 91精品欧美福利在线观看| 日韩一区二区三区四区五区六区| 精品国产91洋老外米糕| 国产丝袜在线精品| 亚洲一区中文在线| 久久97超碰国产精品超碰| 国产精品一品二品| 成人avav影音| 欧美日韩一区二区三区四区 | 中文字幕欧美区| 亚洲伦在线观看| 蜜臀99久久精品久久久久久软件| 精品夜夜嗨av一区二区三区| 成人成人成人在线视频| 欧美三级乱人伦电影| 国产精品网站导航| 视频一区欧美精品| 国产激情视频一区二区在线观看| 国产精品一二三四区| 在线观看亚洲a| 久久综合999| 日韩成人dvd| 在线视频一区二区三| 国产婷婷色一区二区三区在线| 午夜成人免费电影| 99这里都是精品|