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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? shared_memory.cc

?? 簡單的動態內存管理程序源代碼
?? CC
字號:
// file: shared_memory.cc// author: Marc Bumble// June 1, 2000// Page memory source for shared memory // Copyright (C) 2000 by Marc D. Bumble//  This program is free software; you can redistribute it and/or//  modify it under the terms of the GNU General Public License//  as published by the Free Software Foundation; either version 2//  of the License, or (at your option) any later version.//  This program 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 General Public License for more details.//  You should have received a copy of the GNU General Public License//  along with this program; if not, write to the Free Software//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.#include <shared_memory.h>namespace mem_space {      ////////////////////////////////////////////////////////////////////  //////                             Memory Locks  ////////////////////////////////////////////////////////////////////  //////     //////    Locks are  mutual exclusion locks used  to protect process  //////    from  writing  simultaneously   to  shared  memory.   Each  //////    allocator will  get one semaphore set, and  then with that  //////    semaphore  set, each chunk  will lock  individual elements  //////    with  semaphores from  that  set.  So  each  chunk is  has  //////    access to the semid and the semnum.  A semid is common for  //////    all chunks within a given  allocator, and then each of the  //////    allocator's  chunks will  have its  own  individual semnum  //////    which indicates which semaphore in the semid array.  //////      ////////////////////////////////////////////////////////////////////  // constructor  locks::locks(const mem_space::allocator_key_t& alloc_key,	       const int& proj_id) {    std::string key_file(alloc_key);    // create a file for System V ftok from alloc_key    key_file = std::string("/tmp") + key_file;    // create the empty shm key file, used by ftok()    std::ofstream to(key_file.data());    if (!to) perror("Cannot open key file");    to.close();    // set the semaphore key    key_t mykey = ftok(key_file.c_str(),proj_id);    if (mykey == -1) {      std::clog << "Error:" << __FILE__ << ':' << __LINE__ << ':'		<< " ftok unable to create sem key: " << strerror(errno) 		<< ":  " << key_file << std::endl;      // create an error message to throw with the exception      std::stringstream s;      s << __FILE__ << ':' << __LINE__ << ':'			  << " project id out of range (1 <= proj_id < 128).";      throw (Alloc_Exception::ftok_exception(s.str()));    }    semid = semget(mykey, num_in_array, IPC_CREAT | IPC_EXCL | 0666);//     std::clog << "Status:" << __FILE__ << ':' << __LINE__ << ':'// 	      << " semid: " << semid << "  " << strerror(errno)// 	      << std::endl;    if (semid >= 0) {      // first to create the semaphores      // need to initialize the semaphore set      union semun arg;      struct semid_ds seminfo;      arg.buf = &seminfo;      // set all semaphores to 1 unit avail      // binary locks, ie one process can sieze the lock at a time for each page.      short unsigned sem_vals[num_in_array];       for (int i = 0; i < num_in_array; i++) {	sem_vals[i] = 1;// 	std::clog << "i = " << i << std::endl;      }      arg.array = sem_vals;      if (semctl(semid, 0, SETALL, arg) == -1) {	std::cerr << "File: " << __FILE__ << ':' << __LINE__ << ':'<< "locks::make_lock()";	std::cerr << ": semaphore creation error: " << strerror(errno) << std::endl;	std::stringstream s;	s << __FILE__ << ':' << __LINE__ << ':'	  << " semaphore creation error.";	throw (Alloc_Exception::lock_creation_exception(s.str()));      }    } else {      // The semaphore set already exists      // Do not initialize, just attach and wait until the semaphores are initialized      union semun arg;      struct semid_ds seminfo;      arg.buf = &seminfo;      // wait  at  most for  10  tries to  see  if  the semaphore  get      // initialized by  the process which  created it.  If  within 10      // tests, the process does not get initialized, then fail.      const int& tries = 10;      bool initialized = false;      for (int i = 0; ((i < tries) && (!initialized)); i++) {	// retrieve information on the semaphores	semctl(semid,0,IPC_STAT,arg);	if (arg.buf->sem_otime != 0) {	  initialized = true;	}	sleep(1);      }      if (!initialized) {	std::cerr << "File: " << __FILE__ << ':' << __LINE__ << ':'<< "locks::locks()";	std::cerr << ": semaphore initialization error: " << strerror(errno) << std::endl;	std::stringstream s;	s << __FILE__ << ':' << __LINE__ << ':'	  << " semaphore initialization error.";	throw (Alloc_Exception::lock_creation_exception(s.str()));      }    }  }; // constructor    // destructor  locks::~locks() {    // union semun semctl_arg;    //     for (int i=0; i<num_in_array; i++) {      //      int semctlresult = semctl(semid, i, IPC_RMID, semctl_arg);#ifdef DEBUG    std::cerr << __FILE__ << ":" << __LINE__ << " ~locks()" << std::endl;#endif    int semctlresult = semctl(semid, 0, IPC_RMID);    if ((semctlresult!=0)&&(errno!=EINVAL)) {      std::cerr << __FILE__ << ':' << __LINE__ << " locks::~locks(): ";      std::cerr << " semid: " << semid << "semctlresult: ";      std::cerr << semctlresult << " " << strerror(errno) << std::endl;    }#ifdef SHARED_MEMORY_MESG    std::cerr << "semid: " << semid << " shmctlresult: ";    std::cerr << semctlresult << " " << strerror(errno) << std::endl;#endif    //     }  }; // destructor  // copy consqtructor  locks::locks(const locks& t) {    semid=t.semid;  }; // copy constructor  // assignment operator  locks& locks::operator=(const locks& t) {    if (this != &t) {		// avoid self assignment: t=t      semid=t.semid;    }  // if (this != &t)    return *this;  };  // assignment operator    // equality operator  bool locks::operator==(const locks& t) {    bool flag=false;    if (semid==t.semid) {      flag=true;    }    return flag;  };  // equality operator  // lock print  void locks::print() const {    // print the current semaphore lock values    struct semid_ds seminfo;    union semun arg;    arg.buf = &seminfo;    semctl(semid, 0, IPC_STAT, arg);    //    int nsems = arg.buf->sem_nsems;    unsigned short sem_vals[num_in_array];    arg.array = sem_vals;    semctl(semid, 0, GETALL, arg);    std::cerr << std::endl;    std::cerr << "locks::print()" << std::endl;    std::cerr << "semid    = " << semid << std::endl;    std::cerr << "semval[] = ";    for (int i = 0; i < num_in_array; i++) {      if (!(i%25)) {	std::cerr << std::endl;	std::cerr << "           ";      }      std::cerr << ":" << sem_vals[i];    }    std::cerr << std::endl;  };  //   void locks::lock(int page_num) {    // only set one lock at a time    struct sembuf sem_buf_array[num_in_array];    sem_buf_array[0].sem_num = page_num % num_in_array;    sem_buf_array[0].sem_op = -1;   // take the lock, subtract it away.    sem_buf_array[0].sem_flg = SEM_UNDO;//     std::cerr << __FILE__ << ':' << __LINE__ << ':'<< " locks::lock()";//     std::cerr << "semid: " << semid << std::endl;    int result = semop(semid, sem_buf_array, 1);  // operate on 1 lock at a time    if (result!=0) {      std::stringstream s;      std::cerr << __FILE__ << ':' << __LINE__ << ':'<< " locks::lock()";      std::cerr << ": semaphore lock: " << strerror(errno) << " result: " << result << std::endl;      s << ": semaphore lock errno: " << strerror(errno) << " result: " << result;      s << " lock attempt error." << " semid: " << semid << " page_num: " << page_num;      std::cerr << s .str()<< std::endl;      throw (Alloc_Exception::locking_exception(s.str()));   }	  };  // void lock(int page_num)  //   void locks::unlock(int page_num) {    // only clear one lock at a time    struct sembuf sem_buf_array[1];    sem_buf_array[0].sem_num = page_num % num_in_array;    sem_buf_array[0].sem_op = 1;       // release the lock, add it back    sem_buf_array[0].sem_flg = SEM_UNDO;    int result = semop(semid, sem_buf_array, 1); // operate on 1 lock at a time    if (result!=0) {      std::stringstream s;      std::cerr << __FILE__ << ':' << __LINE__ << ':'<< " locks::unlock()";      std::cerr << ": semaphore unlock: " << strerror(errno) << " result: " << result << std::endl;      s << ": semaphore unlock errno: " << strerror(errno) << " result: " << result;      s << " unlock attempt error." << " semid: " << semid << " page_num: " << page_num;      std::cerr << s .str()<< std::endl;      throw (Alloc_Exception::locking_exception(s.str()));   }	  };  // void unlock(int page_num)      ////////////////////////////////////////////////////////////////////  //////                     class shared_memory_header  ////////////////////////////////////////////////////////////////////  //////     //////    This class is embedded as  the first element in all shared  //////    memory segments.   It contains information  describing the  //////    state of the allocated memory segment.  This class uses no  //////    memory pointers as the  shared memory segment is mapped to  //////    different  addresses  for  different  processes.   So  all  //////    address values must be relative offsets from the beginning  //////    of the allocated segment.  //////      ////////////////////////////////////////////////////////////////////      int shared_memory_header_t::get_page_offset(int page_num) {    // returns the  offset from  the beginning of  the segment  to the    // page  indicated by  page_num.  Just  calculates size  offset in    // terms of  the number of  bytes.  If shm (shared  memory header)    // points to the beginning of the allocated shared memory segment,    // then  the actual  page address  can be  interepreted  using the    // following calls:    //    // int start_page_offset = smh->get_page_offset(start_page4);    // unsigned char* addr = reinterpret_cast<unsigned char*>(smh) +    //                       start_page_offset;    //    // addr  will  then  contain  the correct  memory  address.   This    // approach  is  required because  the  shared  memory segment  is    // memory mapped  to each process  differently, so an  offset from    // the beginning of the segment address is required.    return sizeof(shared_memory_header_t) + bit_vec_size +       page_num*page_size;  }; // get_page_offset()  }  // namespace mem_space

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩一区二区免费视频| 精品久久久久香蕉网| 国产99久久久久久免费看农村| 精品一区二区三区免费播放| 极品尤物av久久免费看| 久久国产精品99久久人人澡| 国产麻豆成人传媒免费观看| 成人av电影在线| 在线欧美小视频| 日韩一区二区视频| 久久日一线二线三线suv| 欧美国产激情二区三区| 国产精品毛片久久久久久| 亚洲欧美日韩国产一区二区三区 | 91免费视频网址| 久久se这里有精品| 奇米在线7777在线精品| 国产在线播放一区| 99久久99久久综合| 在线视频一区二区三| 制服.丝袜.亚洲.另类.中文| 精品国产免费视频| 国产精品福利一区二区| 婷婷久久综合九色综合伊人色| 另类小说视频一区二区| 99视频一区二区| 在线电影一区二区三区| 国产午夜亚洲精品理论片色戒| 国产精品九色蝌蚪自拍| 婷婷久久综合九色综合伊人色| 国产精品99久久久久久久vr| 在线一区二区视频| 久久众筹精品私拍模特| 亚洲一区日韩精品中文字幕| 精品一区二区三区在线观看 | 精品视频一区二区不卡| 日韩欧美国产综合| 亚洲色欲色欲www在线观看| 男人的天堂久久精品| 成人黄色片在线观看| 欧美日韩国产综合视频在线观看| 26uuu国产日韩综合| 亚洲一区二区在线免费看| 极品尤物av久久免费看| 欧美日韩一区三区| 综合精品久久久| 国产美女一区二区三区| 67194成人在线观看| 亚洲欧美日韩精品久久久久| 国产高清不卡一区| 日韩午夜精品视频| 亚洲大尺度视频在线观看| 成人一区二区三区视频| 欧美成人伊人久久综合网| 亚洲成人黄色影院| 一本一本大道香蕉久在线精品 | 色先锋久久av资源部| 国产欧美日韩在线看| 日本欧美大码aⅴ在线播放| 在线中文字幕不卡| 亚洲欧美日韩综合aⅴ视频| 99久久久久久| 国产精品初高中害羞小美女文| 国内成人精品2018免费看| 91麻豆精品国产91久久久更新时间| 亚洲一区在线观看视频| 欧美在线观看一区二区| 亚洲欧美色图小说| 91久久人澡人人添人人爽欧美 | 亚洲愉拍自拍另类高清精品| 99久久国产免费看| 成人欧美一区二区三区小说| 成人精品在线视频观看| 中文字幕电影一区| 不卡在线观看av| 日韩美女精品在线| 91丨porny丨中文| 一区二区三区丝袜| 欧美性极品少妇| 日日夜夜免费精品| 欧美一卡二卡在线| 国产资源在线一区| 欧美极品另类videosde| eeuss鲁片一区二区三区在线观看| 国产精品女同一区二区三区| 91在线免费看| 香蕉加勒比综合久久| 日韩欧美综合一区| 国产99一区视频免费| 亚洲日穴在线视频| 宅男噜噜噜66一区二区66| 免费观看成人av| 中文字幕精品综合| 在线免费观看日本欧美| 美女免费视频一区二区| 国产女同性恋一区二区| 一本久道久久综合中文字幕| 青娱乐精品视频在线| 国产拍欧美日韩视频二区| 一本一道综合狠狠老| 日本视频在线一区| 国产精品午夜在线| 欧美欧美午夜aⅴ在线观看| 国产一区中文字幕| 一区二区三区色| 精品三级在线看| 一本色道久久综合亚洲91| 久久精品国产77777蜜臀| 亚洲欧美自拍偷拍| 日韩欧美精品在线视频| 色综合中文综合网| 99久久精品情趣| 日韩av在线播放中文字幕| 久久综合九色综合久久久精品综合 | 亚洲色欲色欲www| 欧美一级理论片| 不卡av电影在线播放| 日本不卡视频一二三区| 国产精品乱码一区二区三区软件| 69p69国产精品| 91浏览器在线视频| 韩国av一区二区三区在线观看| 亚洲一区二区三区美女| 久久久99免费| 91精品国产乱码久久蜜臀| 91亚洲大成网污www| 国产精一品亚洲二区在线视频| 亚洲福利电影网| 亚洲欧美日韩一区| 中文幕一区二区三区久久蜜桃| 3d动漫精品啪啪1区2区免费 | 精品国产凹凸成av人网站| 欧美日韩免费一区二区三区视频| 国产精品 欧美精品| 久久av资源网| 丝袜亚洲精品中文字幕一区| 亚洲精品乱码久久久久久久久| 久久久久久久久久看片| 日韩免费看的电影| 欧美精品tushy高清| 欧美亚洲综合色| 一本一本大道香蕉久在线精品| 大尺度一区二区| 国产激情偷乱视频一区二区三区| 久久精品国产99久久6| 久久精品国产亚洲一区二区三区| 一区二区三区高清在线| 夜夜精品视频一区二区 | 图片区小说区国产精品视频| 洋洋成人永久网站入口| 一区二区三区中文字幕精品精品| 亚洲色图在线视频| 亚洲黄色在线视频| 一区二区三区在线免费播放| 一区二区三区日韩| 亚洲 欧美综合在线网络| 五月天一区二区三区| 香蕉成人啪国产精品视频综合网| 亚洲va中文字幕| 奇米影视7777精品一区二区| 美女高潮久久久| 国产乱人伦偷精品视频免下载| 国产一区二区三区电影在线观看 | 亚洲人精品午夜| 亚洲女同ⅹxx女同tv| 亚洲福利视频导航| 蜜臀av性久久久久蜜臀aⅴ流畅 | 91在线观看高清| 欧美午夜精品一区二区三区| 8x8x8国产精品| 久久久久久免费毛片精品| 国产人伦精品一区二区| 亚洲欧美国产三级| 日韩电影网1区2区| 国产99一区视频免费| 91久久香蕉国产日韩欧美9色| 欧美一区二区三区四区久久| 久久综合久久综合九色| 亚洲免费伊人电影| 免费在线视频一区| 成人免费福利片| 欧美精品一二三四| 国产精品婷婷午夜在线观看| 亚洲精品国产无套在线观| 久久99精品国产91久久来源| 99久久久久免费精品国产 | 国产精品77777| 在线观看免费亚洲| 精品国产精品一区二区夜夜嗨| 自拍偷拍国产精品| 蜜桃视频一区二区| 色先锋资源久久综合| 欧美mv日韩mv国产网站app| 一区二区三区在线不卡| 韩国欧美国产1区| 欧美精品日韩精品| 国产精品久久久久一区二区三区共| 丝袜亚洲精品中文字幕一区| 99国产精品视频免费观看| 久久色中文字幕|