void GridMovement::removePos(int id) { std::lock_guard<std::shared_timed_mutex> writerLock(gridMutex); for(auto posItr=posMap->begin(); posItr!=posMap->end(); ++posItr) { if(posItr != posMap->end()) { pList *tmp = &posItr->second; for(auto it=tmp->begin(); it != tmp->end(); ++it) { if(it != tmp->end()) { if(*it == id) { //Output::Inst()->kprintf("remove something id'ish...%i,%i", *it,id); tmp->remove(id); break; } } } if(tmp->empty()) { posMap->erase(posItr); } } } }
void addToTeleBook(const std::string& na, int tele){ std::lock_guard<std::shared_timed_mutex> writerLock(teleBookMutex); std::cout << "\nSTARTING UPDATE " << na; std::this_thread::sleep_for(std::chrono::milliseconds(500)); teleBook[na]= tele; std::cout << " ... ENDING UPDATE " << na << std::endl; }
void GridMovement::initGrid(int scale) { std::lock_guard<std::shared_timed_mutex> writerLock(gridMutex); if(posMap != NULL) { delete posMap; } posMap = new std::unordered_map<std::string, pList>(); GridMovement::scale = scale; }
status_t StreamingRingBuffer::Write(const void *buffer, size_t length) { BAutolock writerLock(fWriterLocker); if (!writerLock.IsLocked()) return B_ERROR; BAutolock dataLock(fDataLocker); if (!dataLock.IsLocked()) return B_ERROR; while (length > 0) { size_t copyLength = min_c(length, fBufferSize - fWritePosition); copyLength = min_c(copyLength, fBufferSize - fReadable); if (copyLength == 0) { fWriterWaiting = true; dataLock.Unlock(); status_t result; do { TRACE("waiting in writer\n"); result = acquire_sem(fWriterNotifier); TRACE("done waiting in writer with status: 0x%08lx\n", result); } while (result == B_INTERRUPTED); if (result != B_OK) return result; if (!dataLock.Lock()) return B_ERROR; continue; } memcpy(fBuffer + fWritePosition, buffer, copyLength); fWritePosition = (fWritePosition + copyLength) % fBufferSize; fReadable += copyLength; buffer = (uint8 *)buffer + copyLength; length -= copyLength; if (fReaderWaiting) { release_sem_etc(fReaderNotifier, 1, B_DO_NOT_RESCHEDULE); fReaderWaiting = false; } } return B_OK; }
bool GridMovement::updateIfFree(int oldX, int oldY, int newX, int newY, int id) { std::lock_guard<std::shared_timed_mutex> writerLock(gridMutex); char buffer[64]; sprintf(buffer,"%i,%i", oldX, oldY); std::string index = buffer; auto posItr = posMap->find(index); pList *tmp = &posItr->second; if(posItr != posMap->end()) { for(auto it=tmp->begin(); it != tmp->end(); it++ ) { if (*it == id) { tmp->remove(id); break; } } if(tmp->empty()) { posMap->erase(posItr); } } sprintf(buffer,"%i,%i",newX,newY); index = buffer; if(posMap->find(index) == posMap->end() ) { pList tmp; tmp.push_back(id); posMap->insert(std::pair<std::string, pList >(index,tmp)); } else { return true; } return false; }
void GridMovement::addPos(int x, int y, int id) { std::lock_guard<std::shared_timed_mutex> writerLock(gridMutex); //Output::Inst()->kprintf("ID..X:%i,Y:%i", x, y); //add id to position map: char buffer[64]; sprintf(buffer,"%i,%i",x,y); std::string index = buffer; if(posMap->find(index) == posMap->end() ) { pList tmp; tmp.push_back(id); posMap->insert(std::pair<std::string, pList >(index,tmp)); } else { pList *tmp = &posMap->find(index)->second; tmp->push_back(id); } }
SdfLayerRefPtr& UsdKatanaCache::_FindOrCreateSessionLayer( FnAttribute::GroupAttribute sessionAttr, std::string rootLocation) { // Grab a reader lock for reading the _sessionKeyCache boost::upgrade_lock<boost::upgrade_mutex> readerLock(UsdKatanaGetSessionCacheLock()); std::string cacheKey = FnAttribute::GroupAttribute("s", sessionAttr, "r", FnAttribute::StringAttribute(rootLocation), true).getHash().str(); // Open the usd stage SdfLayerRefPtr sessionLayer; if (_sessionKeyCache.find(cacheKey) == _sessionKeyCache.end()) { boost::upgrade_to_unique_lock<boost::upgrade_mutex> writerLock(readerLock); sessionLayer = SdfLayer::CreateAnonymous(); _sessionKeyCache[cacheKey] = sessionLayer; std::string rootLocationPlusSlash = rootLocation + "/"; FnAttribute::GroupAttribute variantsAttr = sessionAttr.getChildByName("variants"); for (int64_t i = 0, e = variantsAttr.getNumberOfChildren(); i != e; ++i) { std::string entryName = FnAttribute::DelimiterDecode( variantsAttr.getChildName(i)); FnAttribute::GroupAttribute entryVariantSets = variantsAttr.getChildByIndex(i); if (entryVariantSets.getNumberOfChildren() == 0) { continue; } if (!pystring::startswith(entryName, rootLocationPlusSlash)) { continue; } std::string primPath = pystring::slice(entryName, rootLocation.size()); for (int64_t i = 0, e = entryVariantSets.getNumberOfChildren(); i != e; ++i) { std::string variantSetName = entryVariantSets.getChildName(i); FnAttribute::StringAttribute variantValueAttr = entryVariantSets.getChildByIndex(i); if (!variantValueAttr.isValid()) { continue; } std::string variantSetSelection = variantValueAttr.getValue("", false); SdfPath varSelPath(primPath); SdfPrimSpecHandle spec = SdfCreatePrimInLayer( sessionLayer, varSelPath.GetPrimPath()); if (spec) { std::pair<std::string, std::string> sel = varSelPath.GetVariantSelection(); spec->SetVariantSelection(variantSetName, variantSetSelection); } } } FnAttribute::GroupAttribute activationsAttr = sessionAttr.getChildByName("activations"); for (int64_t i = 0, e = activationsAttr.getNumberOfChildren(); i != e; ++i) { std::string entryName = FnAttribute::DelimiterDecode( activationsAttr.getChildName(i)); FnAttribute::IntAttribute stateAttr = activationsAttr.getChildByIndex(i); if (stateAttr.getNumberOfValues() != 1) { continue; } if (!pystring::startswith(entryName, rootLocationPlusSlash)) { continue; } std::string primPath = pystring::slice(entryName, rootLocation.size()); SdfPath varSelPath(primPath); SdfPrimSpecHandle spec = SdfCreatePrimInLayer( sessionLayer, varSelPath.GetPrimPath()); spec->SetActive(stateAttr.getValue()); } } return _sessionKeyCache[cacheKey]; }
void GridMovement::clearGrid() { std::lock_guard<std::shared_timed_mutex> writerLock(gridMutex); posMap->clear(); }