static RSHashCode __RSRenrenFriendClassHash(RSTypeRef rs) { return RSHash(((RSRenrenFriendRef)rs)->_account); }
static RSHashCode __RSCoreUSBDeviceClassHash(RSTypeRef rs) { RSCoreUSBDeviceRef device = (RSCoreUSBDeviceRef)rs; return RSHash(device->_deviceName); }
/* * === FUNCTION ====================================================================== * Name: NVOpenRegion * Description: * ===================================================================================== */ NVRDescr * NVOpenRegion(char * name, /* region name */ void * startingAddr, /* starting addr */ int size) /* region size. The real size is rounded up */ { int nameLen; // check name lenght if ((nameLen=strlen(name))>NV_MAXPATH){ printf("NVOpenRegion name length is longer than NV_MAXPATH\n"); exit(1); } key_t keyNVRegion; int shmId; struct shmid_ds shmDsBuf,* shmDsPtr; shmDsPtr = &shmDsBuf; int flag = 0; NVRDescr *nvrAddr; char *shmPtr; #if defined(SHM) if ((keyNVRegion=ftok(name, 0))<0) { DEBUG_OUTPUT("Please create this file to back the memory."); e("NVOpenRegion ftok error"); } // unsigned int RSHash (char* str, unsigned int len); // get shmId, if not exist create if ((shmId=shmget(keyNVRegion,size,SHM_MODE))<=0) { if (errno==ENOENT){// this region is not exists, create a new one if ((shmId=shmget(keyNVRegion,size,IPC_CREAT|SHM_MODE))<=0){ e("NVOpenRegion shmget error"); } // successfully create this shm flag = 1; // get stat here }else e("NVOpenRegion shmget error"); } // shmat #ifdef FIXMEMBASE if ((shmPtr = shmat(shmId,membase,0) )==(void *)-1) #else /* ----- not FIXMEMBASE ----- */ if ((shmPtr = shmat(shmId,startingAddr,0) )==(void *)-1) #endif /* ----- not FIXMEMBASE ----- */ { e("NVOpenRegion shmat error"); } if ((void *)shmPtr!=membase){ errno = EFAULT; e("NVOpenRegion shmat error"); } // get shm_ds if ((shmctl(shmId,IPC_STAT,&shmDsBuf))<0) { e("NVOpenRegion shmctl error"); } #elif defined(MMAP) #ifdef FIXMEMBASE shmPtr = membase; #else /* ----- not FIXMEMBASE ----- */ shmPtr = startingAddr; #endif /* ----- not FIXMEMBASE ----- */ // open the file int fd; if ( (fd = open(name, O_RDWR, S_IRWXU)) < 0){ if (errno==ENOENT){// this region is not exists, create a new one if ((fd = open(name, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0){ e("NVOpenRegion fd open error"); } // successfully create this file flag = 1; // make it becomes certain size int result = lseek(fd, SHM_SIZE-1, SEEK_SET); if (result == -1) { close(fd); e("NVOpenRegion lseek error"); } result = write(fd, "", 1); if (result < 0) { close(fd); e("NVOpenRegion write at the end of file error"); } }else e("NVOpenRegion fd open error"); } // get file stat struct stat file_stat; if ( fstat( fd, &file_stat) < 0 ) { // printf(" fstat wrong"); // exit(1); e("NVOpenRegion fstat error"); } keyNVRegion = file_stat.st_ino; // ftruncate(fd, file_stat.st_size+size); printf("filein size = %ld\n",file_stat.st_size); void *start_fp; // check size here. // if( ( start_fp = mmap(shmPtr, file_stat.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0 )) == MAP_FAILED) { // printf("mmap wrong"); // exit(0); e("NVOpenRegion mmap error"); } // now you can close close(fd); shmId = RSHash(name, nameLen); // provide shmid using hash // as long as the file exists, the shared memory exists. #endif nvrAddr = (NVRDescr *)shmPtr; if (flag==1) {// initiate the meta data of this region nvrAddr->size = size; nvrAddr->refKey = keyNVRegion; nvrAddr->rootMapOffset = size; nvrAddr->dataRegionOffset = sizeof(NVRDescr); nvrAddr->shareFlag = SHARE; #if defined(SHM) nvrAddr->processCnt = shmDsPtr->shm_nattch; // better processCnt #elif defined(MMAP) nvrAddr->processCnt = 1; // the process creates this shm, the processCnt will always be 1 #endif nvrAddr->nvRootCnt = 0; nvrAddr->ID = shmId; nvrAddr->nameLen = nameLen; memset(nvrAddr->name, '\0', sizeof(nvrAddr->name)); strcpy(nvrAddr->name,name); /* :TODO:11/06/2013 12:53:07 PM:: initiate the rootmap */ mem_init(); if (mm_init()<0) { e("MVMalloc initialization error."); } } else { // update NVRDescr nvrAddr->processCnt = shmDsPtr->shm_nattch; // 1 is the initial value nvrAddr->refKey = keyNVRegion; // it is possible that the keyNVRegion is null and needs to be update // #ifdef DEBUG // printf("%d\n",nvrAddr->refKey); // #endif /* ----- not DEBUG ----- */ mem_init(); // mem_init(); // if (mm_init()<0) // { // e("MVMalloc initialization error."); // } } return nvrAddr; }
static RSHashCode __RSCalendarHash(RSTypeRef obj) { RSCalendarRef calendar = (RSCalendarRef)obj; return RSHash(calendar->_identifier); }