void* malloc(size_t size) { mythread* thread = getById(pthread_self()); if (size >= N) { mybucket* b = bfind(thread->big_list, size); if (b == 0) { b = bfind(glob_list, size); if (b == 0) { b = bcreate(size); return b->mem; } pthread_mutex_lock(&glob_mutex); bdelete(&glob_list, &glob_list_end, b); glob_size--; pthread_mutex_unlock(&glob_mutex); return b->mem; } pthread_mutex_lock(&thread->thread_mutex); bdelete(&thread->big_list, &thread->big_list_end, b); thread->bigsize--; pthread_mutex_unlock(&thread->thread_mutex); return b->mem; } else { mybucket* b = bfind(thread->small_list, size); if (b == 0) { b = bcreate(size); return b->mem; } pthread_mutex_lock(&thread->thread_mutex); bdelete(&thread->small_list, &thread->small_list_end, b); thread->smallsize--; pthread_mutex_unlock(&thread->thread_mutex); return b->mem; } }
ProfileInCorrelation* ProfileCorrelation::addProfile(Profile* p, int id, int position) { if (!p) { return 0; } if (id > 0) { if (id > _lastProfileInCorrelationId) { _lastProfileInCorrelationId = id; } } else { _lastProfileInCorrelationId++; } if (position > 0) { _profiles.insert(position, new ProfileInCorrelation(_lastProfileInCorrelationId, p->getName(), p->getDescription(), p, position)); } else { _profiles.append(new ProfileInCorrelation(_lastProfileInCorrelationId, p->getName(), p->getDescription(), p)); } renumberProfilesInBed(); return getById(_lastProfileInCorrelationId); }
IdType MetadataStream::add( std::shared_ptr< MetadataInternal >& spMetadataInternal) { if( !this->getSchema(spMetadataInternal->getDesc()->getSchemaName()) ) VMF_EXCEPTION(vmf::NotFoundException, "Metadata schema is not in the stream"); IdType id = spMetadataInternal->getId(); if(id != INVALID_ID) { if(this->getById(id) == nullptr) { if(nextId < id) nextId = id + 1; } else VMF_EXCEPTION(IncorrectParamException, "Metadata with such id is already in the stream"); } else { id = nextId++; spMetadataInternal->setId(id); } internalAdd(spMetadataInternal); addedIds.push_back(id); if(!spMetadataInternal->vRefs.empty()) { auto spItem = getById(id); for(auto ref = spMetadataInternal->vRefs.begin(); ref != spMetadataInternal->vRefs.end(); ref++) { auto referencedItem = getById(ref->first); if(referencedItem != nullptr) spItem->addReference(referencedItem, ref->second); else m_pendingReferences[ref->first].push_back(std::make_pair(id, ref->second)); } } auto pendingReferences = m_pendingReferences[id]; if(!pendingReferences.empty()) { for(auto pendingId = pendingReferences.begin(); pendingId != pendingReferences.end(); pendingId++) getById(pendingId->first)->addReference(spMetadataInternal, pendingId->second); m_pendingReferences[id].clear(); m_pendingReferences.erase(id); } return id; }
void free(void* ptr) { if (ptr == 0) return; mybucket* b = (mybucket*)(ptr - sizeof(mybucket)); if (b->size >= N) { mythread* th = getById(pthread_self()); pthread_mutex_lock(&th->thread_mutex); badd(&th->big_list, &th->big_list_end,b); th->bigsize++; pthread_mutex_unlock(&th->thread_mutex); if (th->bigsize > MAX_BIG_SIZE) { mybucket* moving = th->big_list; pthread_mutex_lock(&th->thread_mutex); bdelete(&th->big_list, &th->big_list_end, moving); th->bigsize--; pthread_mutex_unlock(&th->thread_mutex); pthread_mutex_lock(&glob_mutex); badd(&glob_list, &glob_list_end, moving); glob_size++; pthread_mutex_unlock(&glob_mutex); if (glob_size > MAX_GLOB_SIZE) { mybucket* d = glob_list; pthread_mutex_lock(&glob_mutex); bdelete(&glob_list, &glob_list_end, d); glob_size--; pthread_mutex_unlock(&glob_mutex); bdestroy(d); } } } else { mythread* th = getById(b->id); pthread_mutex_lock(&th->thread_mutex); badd(&th->small_list, &th->small_list_end, b); th->smallsize++; pthread_mutex_unlock(&th->thread_mutex); if (th->smallsize > MAX_SMALL_SIZE) { mybucket* d = th->small_list; pthread_mutex_lock(&th->thread_mutex); bdelete(&th->small_list, &th->small_list_end,d); th->smallsize--; pthread_mutex_unlock(&th->thread_mutex); bdestroy(d); } } }
MojErr MojDbLevelQuery::getVal(MojDbStorageItem*& itemOut, bool& foundOut) { MojObject id; MojErr err = parseId(id); MojErrCheck(err); err = getById(id, itemOut, foundOut); MojErrCheck(err); return MojErrNone; }
Entity * EntityManager::getById(const std::string & name, Entity * self) const { EntityHandle handle = getById(name); if(handle == EntityHandle()) { return NULL; } else if(handle == EntityHandle_Self) { return self; } else { return entries[handle.handleData()]; } }
//デッキから魔法を取得 Magic* MagicManager::getMagicByHandCards(cocos2d::__Array &handcards) { int id = 0; for (auto idx = 0; idx < handcards.count(); idx++) { auto card = (PlayerCard*) handcards.getObjectAtIndex(idx); if(card->getSelected()){ id += card->getIdentifer(); } } return getById(id); }
void NNSamples::merge( NNSamples *src ) { ASSERT( src -> nSizeIn == nSizeIn ); ASSERT( src -> nSizeOut == nSizeOut ); for( int s = 0; s < src -> count(); s++ ) { NNSample *sample = src -> getByPos( s ); if( getById( sample -> getId() ) != NULL ) continue; add( sample ); } }
Entity * EntityManager::getById(const std::string & name, Entity * self) const { long index = getById(name); return (index == -1) ? NULL : (index == -2) ? self : entries[index]; }
void EntityManager::addEntity( Entity *e){ assert(e); if ( !getById( e->getId())) { entities_.push_back( e); } }
bool PeerTable::containsId(pid_t peerId) const { return bool(getById(peerId)); }