Space * space_ini(){ int i; Space *s; s = (Space *) malloc (sizeof(Space)); if(!s) return NULL; sId(s) = -1; for(i = 0; i < 8; i++) neighbour(s)[i] = -1; sDesc(s) = NULL; lDesc(s) = NULL; light(s) = FALSE; isLocked(s) = FALSE; map(s) = NULL; rows(s) = -1; cols(s) = -1; return s; }
void WorldEditorSelection::removeObject( SimObject* obj ) { if( !objInSet( obj ) ) return; // Refuse to remove object if this selection is locked. if( isLocked() ) return; invalidateCentroid(); Parent::removeObject( obj ); if( mAutoSelect ) WorldEditor::markAsSelected( obj, false ); return; }
void test_specall() { #define UNLOCK 0 #define LOCKED 1 #define OPERROR -1 #define PEERROR 10000 int n, cmds, cmd, lid, combination; scanf("%d", &n); Lock *locker[32]; for (int i = 0; i < n; i++) locker[i] = (Lock *) malloc(sizeof(Lock)); for (int i = 0; i < n; i++) init(locker[i]); scanf("%d", &cmds); for (int i = 0; i < cmds; i++) { scanf("%d %d", &cmd, &lid); if (cmd == 1) { int ret = isLocked(locker[lid]); printf("isLocked %d %s\n", lid, ret == OPERROR ? "NOTHING HAPPENED" : ((ret == LOCKED) ? "LOCKED" : (ret == UNLOCK ? "UNLOCK" : "INVALID VALUE"))); } else if (cmd == 2) { scanf("%d", &combination); int ret = lock(locker[lid], combination); if (ret == OPERROR) printf("lock %d %s\n", lid, "NOTHING HAPPENED"); else if (ret == PEERROR) printf("lock %d %s\n", lid, "INVALID COMBINATION"); else printf("lock %d new pwd: %d\n", lid, ret); } else if (cmd == 3) { scanf("%d", &combination); int ret = unlock(locker[lid], combination); printf("unlock %d %s\n", lid, ret == OPERROR ? "NOTHING HAPPENED" : ((ret == LOCKED) ? "LOCKED" : (ret == UNLOCK ? "UNLOCK" : "INVALID VALUE"))); } else { assert(0); } } #undef PEERROR #undef OPERROR #undef LOCKED #undef UNLOCK }
bool LogicInfo::operator==(const LogicInfo& other) const { PrettyCheckArgument(isLocked() && other.isLocked(), *this, "This LogicInfo isn't locked yet, and cannot be queried"); for(theory::TheoryId id = theory::THEORY_FIRST; id < theory::THEORY_LAST; ++id) { if(d_theories[id] != other.d_theories[id]) { return false; } } PrettyCheckArgument(d_sharingTheories == other.d_sharingTheories, *this, "LogicInfo internal inconsistency"); if(isTheoryEnabled(theory::THEORY_ARITH)) { return d_integers == other.d_integers && d_reals == other.d_reals && d_transcendentals == other.d_transcendentals && d_linear == other.d_linear && d_differenceLogic == other.d_differenceLogic; } else { return true; } }
void PurgeableVector::reserveCapacity(size_t capacity) { ASSERT(isLocked()); if (m_isPurgeable) { if (reservePurgeableCapacity(capacity, UseExactCapacity)) return; // Fallback to non-purgeable buffer allocation in case discardable memory allocation failed. } if (!m_vector.capacity()) { // Using reserveInitialCapacity() on the underlying vector ensures that the vector uses the // exact specified capacity to avoid consuming too much memory for small resources. m_vector.reserveInitialCapacity(capacity); } else { m_vector.reserveCapacity(capacity); } moveDataFromDiscardableToVector(); }
void* GrGLIndexBuffer::lock() { GrAssert(fBufferID); GrAssert(!isLocked()); if (this->getGpu()->getCaps().fBufferLockSupport) { this->bind(); // Let driver know it can discard the old data GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, this->sizeInBytes(), NULL, this->dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW)); GR_GL_CALL_RET(GPUGL->glInterface(), fLockPtr, MapBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, GR_GL_WRITE_ONLY)); return fLockPtr; } return NULL; }
bool LogicInfo::operator>=(const LogicInfo& other) const { PrettyCheckArgument(isLocked() && other.isLocked(), *this, "This LogicInfo isn't locked yet, and cannot be queried"); for(theory::TheoryId id = theory::THEORY_FIRST; id < theory::THEORY_LAST; ++id) { if(!d_theories[id] && other.d_theories[id]) { return false; } } PrettyCheckArgument(d_sharingTheories >= other.d_sharingTheories, *this, "LogicInfo internal inconsistency"); if(isTheoryEnabled(theory::THEORY_ARITH) && other.isTheoryEnabled(theory::THEORY_ARITH)) { return (d_integers || !other.d_integers) && (d_reals || !other.d_reals) && (!d_linear || other.d_linear) && (!d_differenceLogic || other.d_differenceLogic); } else { return true; } }
void LockerImpl::dump() const { StringBuilder ss; ss << "lock status: "; // isLocked() must be called without holding _lock if (!isLocked()) { ss << "unlocked"; } else { // SERVER-14978: Dump lock stats information } _lock.lock(); ss << " requests:"; for (LockRequestsMap::const_iterator it = _requests.begin(); it != _requests.end(); ++it) { ss << " " << it->first.toString(); } _lock.unlock(); log() << ss.str() << std::endl; }
bool ShowFunction::saveXML(QXmlStreamWriter *doc) const { Q_ASSERT(doc != NULL); /* Main tag */ doc->writeStartElement(KXMLShowFunction); /* Attributes */ doc->writeAttribute(KXMLShowFunctionID, QString::number(functionID())); doc->writeAttribute(KXMLShowFunctionStartTime, QString::number(startTime())); doc->writeAttribute(KXMLShowFunctionDuration, QString::number(duration())); if (color().isValid()) doc->writeAttribute(KXMLShowFunctionColor, color().name()); if (isLocked()) doc->writeAttribute(KXMLShowFunctionLocked, QString::number(m_locked)); doc->writeEndElement(); return true; }
bool KeychainDatabase::interactiveUnlock() { secdebug("KCdb", "%p attempting interactive unlock", this); SecurityAgent::Reason reason = SecurityAgent::noReason; QueryUnlock query(*this); // take UI interlock and release DbCommon lock (to avoid deadlocks) StSyncLock<Mutex, Mutex> uisync(common().uiLock(), common()); // now that we have the UI lock, interact unless another thread unlocked us first if (isLocked()) { query.inferHints(Server::process()); reason = query(); if (mSaveSecret && reason == SecurityAgent::noReason) { query.retrievePassword(mSecret); } query.disconnect(); } else { secdebug("KCdb", "%p was unlocked during uiLock delay", this); } if (common().isLoginKeychain()) { bool locked = false; service_context_t context = common().session().get_current_service_context(); if ((service_client_kb_is_locked(&context, &locked, NULL) == 0) && locked) { QueryKeybagNewPassphrase keybagQuery(common().session()); keybagQuery.inferHints(Server::process()); CssmAutoData pass(Allocator::standard(Allocator::sensitive)); CssmAutoData oldPass(Allocator::standard(Allocator::sensitive)); SecurityAgent::Reason queryReason = keybagQuery.query(oldPass, pass); if (queryReason == SecurityAgent::noReason) { service_client_kb_change_secret(&context, oldPass.data(), (int)oldPass.length(), pass.data(), (int)pass.length()); } else if (queryReason == SecurityAgent::resettingPassword) { query.retrievePassword(pass); service_client_kb_reset(&context, pass.data(), (int)pass.length()); } } } return reason == SecurityAgent::noReason; }
void MappingParameters::updateParameters() { if (!mapping_ || isLocked()) return; auto applyRotation = [&](mapping::Rotatable* _rotatable) { _rotatable->setRoll(rotation_->x()); _rotatable->setPitch(rotation_->y()); _rotatable->setYaw(rotation_->z()); }; mapping_->setFlipHorizontal(getParamAsBool("Flip horizontal")); mapping_->setFlipVertical(getParamAsBool("Flip vertical")); if (mapping_->getTypeId() == "Equirectangular") { auto* _equirectangular = static_cast<mapping::Equirectangular*>(mapping_); _equirectangular->setStripTop(getParamAsFloat("Strip Top")); _equirectangular->setStripBottom(getParamAsFloat("Strip Bottom")); applyRotation(_equirectangular); } else if (mapping_->getTypeId() == "Fisheye") { auto* _fisheye = static_cast<mapping::Fisheye*>(mapping_); _fisheye->setStretch(getParamAsFloat("Stretch")); applyRotation(_fisheye); } else if (mapping_->getTypeId() == "CubeMap") { auto* _cubemap = static_cast<mapping::CubeMap*>(mapping_); applyRotation(_cubemap); } else if (mapping_->getTypeId() == "Planar") { auto* _planar = static_cast<mapping::Planar*>(mapping_); _planar->setOffset(QVector2D(getParamAsFloat("Offset X"),getParamAsFloat("Offset Y"))); _planar->setStretch(QVector2D(getParamAsFloat("Stretch X"),getParamAsFloat("Stretch Y"))); } emit parametersUpdated(); }
bool Placeable::open(Object *opener) { if (!_hasInventory) return false; if (isOpen()) return true; if (isLocked()) { playSound(_soundLocked); return false; } _lastOpenedBy = opener; playSound(_soundOpened); runScript(kScriptOpen, this, opener); _state = kStateOpen; return true; }
intptr_t KMutex::unlock() { /* not locked */ if (!isLocked()) { return M_OK; } enter_kernel_lock_mode(); g_currentThread->thread->setWaitingMutex(NULL); if (waitList_ ->size() == 0) { owner_ = NULL; } else { owner_ = waitList_->removeAt(0); g_scheduler->EventComes(owner_, MEvent::MUTEX_UNLOCKED); return Scheduler::YIELD; } exit_kernel_lock_mode(); return M_OK; }
LockResult LockerImpl<IsForMMAPV1>::_lockGlobalBegin(OperationContext* opCtx, LockMode mode, Date_t deadline) { dassert(isLocked() == (_modeForTicket != MODE_NONE)); if (_modeForTicket == MODE_NONE) { auto acquireTicketResult = _acquireTicket(opCtx, mode, deadline); if (acquireTicketResult != LOCK_OK) { return acquireTicketResult; } _modeForTicket = mode; } const LockResult result = lockBegin(opCtx, resourceIdGlobal, mode); if (result == LOCK_OK) return LOCK_OK; // Currently, deadlock detection does not happen inline with lock acquisition so the only // unsuccessful result that the lock manager would return is LOCK_WAITING. invariant(result == LOCK_WAITING); return result; }
bool Door::open(Object *opener) { // TODO: Door::open(): Open in direction of the opener if (isOpen() || (_state == kStateDestroyed)) return true; if (isLocked()) { playSound(_soundLocked); runScript(kScriptFailToOpen, this, opener); return false; } _lastOpenedBy = opener; playSound(_soundOpened); runScript(kScriptOpen, this, opener); _state = kStateOpened1; return true; }
/************************************************************************* Create a new window of the specified type *************************************************************************/ Window* WindowManager::createWindow(const String& type, const String& name) { // only allow creation of Window objects if we are in unlocked state if (isLocked()) CEGUI_THROW(InvalidRequestException( "WindowManager is in the locked state.")); String finalName(name.empty() ? generateUniqueWindowName() : name); WindowFactoryManager& wfMgr = WindowFactoryManager::getSingleton(); WindowFactory* factory = wfMgr.getFactory(type); Window* newWindow = factory->createWindow(finalName); char addr_buff[32]; sprintf(addr_buff, "(%p)", static_cast<void*>(newWindow)); Logger::getSingleton().logEvent("Window '" + finalName +"' of type '" + type + "' has been created. " + addr_buff, Informative); // see if we need to assign a look to this window if (wfMgr.isFalagardMappedType(type)) { const WindowFactoryManager::FalagardWindowMapping& fwm = wfMgr.getFalagardMappingForType(type); // this was a mapped type, so assign a look to the window so it can finalise // its initialisation newWindow->d_falagardType = type; newWindow->setWindowRenderer(fwm.d_rendererType); newWindow->setLookNFeel(fwm.d_lookName); initialiseRenderEffect(newWindow, fwm.d_effectName); } d_windowRegistry.push_back(newWindow); // fire event to notify interested parites about the new window. WindowEventArgs args(newWindow); fireEvent(EventWindowCreated, args, EventNamespace); return newWindow; }
void HardwarePixelBuffer::blit(const HardwarePixelBufferSharedPtr &src, const Image::Box &srcBox, const Image::Box &dstBox) { if(isLocked() || src->isLocked()) { OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Source and destination buffer may not be locked!", "HardwarePixelBuffer::blit"); } if(src.getPointer() == this) { OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, "Source must not be the same object", "HardwarePixelBuffer::blit" ) ; } const PixelBox &srclock = src->lock(srcBox, HBL_READ_ONLY); LockOptions method = HBL_NORMAL; if(dstBox.left == 0 && dstBox.top == 0 && dstBox.front == 0 && dstBox.right == mWidth && dstBox.bottom == mHeight && dstBox.back == mDepth) // Entire buffer -- we can discard the previous contents method = HBL_DISCARD; const PixelBox &dstlock = lock(dstBox, method); if(dstlock.getWidth() != srclock.getWidth() || dstlock.getHeight() != srclock.getHeight() || dstlock.getDepth() != srclock.getDepth()) { // Scaling desired Image::scale(srclock, dstlock); } else { // No scaling needed PixelUtil::bulkPixelConversion(srclock, dstlock); } unlock(); src->unlock(); }
void Tuning::updateParameters() { if (!tuning() || isLocked()) return; auto* _projSetup = tuning()->projector().setup(); if (!_projSetup) return; /// Handle free projector setup if (_projSetup->getTypeId() == "FreeSetup") { auto* _p = static_cast<omni::proj::FreeSetup*>(_projSetup); _p->setYaw(getParamAsFloat("Yaw")); _p->setPitch(getParamAsFloat("Pitch")); _p->setRoll(getParamAsFloat("Roll")); _p->setPos( getParamAsFloat("X"), getParamAsFloat("Y"), getParamAsFloat("Z")); } /// Handle Peripheral projector setup if (_projSetup->getTypeId() == "PeripheralSetup") { auto* _p = static_cast<omni::proj::PeripheralSetup*>(_projSetup); _p->setYaw(getParamAsFloat("Yaw")); _p->setPitch(getParamAsFloat("Pitch")); _p->setRoll(getParamAsFloat("Roll")); _p->setDeltaYaw(getParamAsFloat("Delta Yaw")); _p->setDistanceCenter(getParamAsFloat("Distance")); _p->setTowerHeight(getParamAsFloat("Tower Height")); _p->setShift(getParamAsFloat("Shift")); } tuning()->projector().setup(); updateViews(); emit projectorSetupChanged(); }
int PlayerTank::move() { update(); int intent = 0; if(!isLocked()) { if(key[KEY_UP]) { buffer = spriter->getTank(0,0+offset); rotation = 1; intent = 1; } if(key[KEY_RIGHT]) { buffer = spriter->getTank(0,2+offset); rotation = 2; intent = 2; } if(key[KEY_DOWN]) { buffer = spriter->getTank(0,4+offset); rotation = 3; intent = 3; } if(key[KEY_LEFT]) { buffer = spriter->getTank(0,6+offset); rotation = 4; intent = 4; } } if(key[KEY_SPACE]) shoot(); return intent; }
void WorldEditorSelection::addObject( SimObject* obj ) { // Return if object is already in selection. if( objInSet( obj ) ) return; // Refuse to add object if this selection is locked. if( isLocked() ) return; // Prevent adding us to ourselves. if( obj == this ) return; // If the object is itself a selection set, make sure we // don't create a cycle. WorldEditorSelection* selection = dynamic_cast< WorldEditorSelection* >( obj ); if( selection && !selection->objInSet( this ) ) return; // Refuse to add any of our parents. for( SimGroup* group = getGroup(); group != NULL; group = group->getGroup() ) if( obj == group ) return; invalidateCentroid(); Parent::addObject( obj ); if( mAutoSelect ) WorldEditor::markAsSelected( obj, true ); return; }
void RGBMatrixItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *) { QMenu menu; QFont menuFont = qApp->font(); menuFont.setPixelSize(14); menu.setFont(menuFont); menu.addAction(m_alignToCursor); if (isLocked()) { m_lockAction->setText(tr("Unlock item")); m_lockAction->setIcon(QIcon(":/unlock.png")); } else { m_lockAction->setText(tr("Lock item")); m_lockAction->setIcon(QIcon(":/lock.png")); } menu.addAction(m_lockAction); menu.exec(QCursor::pos()); }
void Conditional::wait(size_t timeout) throw (ConditionalAbortException) { #ifdef __DEVELOPMENT_ASSERTIONS__ // assert a locked Conditional assert(isLocked()); #endif if (_abort) throw ConditionalAbortException(ConditionalAbortException::COND_ABORT); if (timeout == 0) { pthread_cond_wait( &cond, &m_mutex ); if (_abort) throw ConditionalAbortException(ConditionalAbortException::COND_ABORT); } else { struct timespec ts; gettimeout(timeout, &ts); wait(&ts); if (_abort) throw ConditionalAbortException(ConditionalAbortException::COND_ABORT); } }
void Conditional::wait(struct timespec *ts) throw (ConditionalAbortException) { #ifdef __DEVELOPMENT_ASSERTIONS__ // assert a locked Conditional assert(isLocked()); #endif if (_abort) throw ConditionalAbortException(ConditionalAbortException::COND_ABORT); int ret = pthread_cond_timedwait(&cond, &m_mutex, ts); if(ret == ETIMEDOUT) { throw ConditionalAbortException(ConditionalAbortException::COND_TIMEOUT, "conditional wait timed out"); } else if (ret != 0) { throw ConditionalAbortException(ConditionalAbortException::COND_ERROR, "error on locking conditional mutex"); } if (_abort) throw ConditionalAbortException(ConditionalAbortException::COND_ABORT); }
void PurgeableVector::append(const char* data, size_t length) { ASSERT(isLocked()); if (!m_isPurgeable) { m_vector.append(data, length); return; } const size_t currentSize = m_discardable ? m_discardableSize : m_vector.size(); const size_t newBufferSize = currentSize + length; if (!reservePurgeableCapacity(newBufferSize, UseExponentialGrowth)) { moveDataFromDiscardableToVector(); m_vector.append(data, length); return; } ASSERT(m_discardableSize + length <= m_discardableCapacity); memcpy(static_cast<char*>(m_discardable->data()) + m_discardableSize, data, length); m_discardableSize += length; }
void VideoItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *) { QMenu menu; QFont menuFont = qApp->font(); menuFont.setPixelSize(14); menu.setFont(menuFont); int screenCount = m_video->getScreenCount(); if (screenCount > 0) { for (int i = 0; i < screenCount; i++) { QAction *scrAction = new QAction(tr("Screen %1").arg(i + 1), this); scrAction->setCheckable(true); if (m_video->screen() == i) scrAction->setChecked(true); scrAction->setData(i); connect(scrAction, SIGNAL(triggered()), this, SLOT(slotScreenChanged())); menu.addAction(scrAction); } } menu.addAction(m_fullscreenAction); menu.addAction(m_alignToCursor); if (isLocked()) { m_lockAction->setText(tr("Unlock item")); m_lockAction->setIcon(QIcon(":/unlock.png")); } else { m_lockAction->setText(tr("Lock item")); m_lockAction->setIcon(QIcon(":/lock.png")); } menu.addAction(m_lockAction); menu.exec(QCursor::pos()); }
void AudioItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *) { QMenu menu; QFont menuFont = qApp->font(); menuFont.setPixelSize(14); menu.setFont(menuFont); if (m_audio->getAudioDecoder() != NULL) { AudioDecoder *ad = m_audio->getAudioDecoder(); AudioParameters ap = ad->audioParameters(); if (ap.channels() == 1) m_previewLeftAction->setText(tr("Preview Mono")); menu.addAction(m_previewLeftAction); if (ap.channels() == 2) { m_previewLeftAction->setText(tr("Preview Left Channel")); menu.addAction(m_previewRightAction); menu.addAction(m_previewStereoAction); } menu.addSeparator(); } menu.addAction(m_alignToCursor); if (isLocked()) { m_lockAction->setText(tr("Unlock item")); m_lockAction->setIcon(QIcon(":/unlock.png")); } else { m_lockAction->setText(tr("Lock item")); m_lockAction->setIcon(QIcon(":/lock.png")); } menu.addAction(m_lockAction); menu.exec(QCursor::pos()); }
DbBlob *KeychainDbCommon::encode(KeychainDatabase &db) { assert(!isLocked()); // must have been unlocked by caller // export database ACL to blob form CssmData pubAcl, privAcl; db.acl().exportBlob(pubAcl, privAcl); // tell the cryptocore to form the blob DbBlob form; form.randomSignature = identifier(); form.sequence = sequence; form.params = mParams; h2ni(form.params.idleTimeout); assert(hasMaster()); DbBlob *blob = encodeCore(form, pubAcl, privAcl); // clean up and go db.acl().allocator.free(pubAcl); db.acl().allocator.free(privAcl); return blob; }
void ReadableStreamOperations::tee(ScriptState* scriptState, ScriptValue stream, ScriptValue* newStream1, ScriptValue* newStream2) { DCHECK(isReadableStream(scriptState, stream)); DCHECK(!isLocked(scriptState, stream)); v8::Local<v8::Value> args[] = {stream.v8Value()}; ScriptValue result(scriptState, V8ScriptRunner::callExtraOrCrash( scriptState, "ReadableStreamTee", args)); DCHECK(result.v8Value()->IsArray()); v8::Local<v8::Array> branches = result.v8Value().As<v8::Array>(); DCHECK_EQ(2u, branches->Length()); *newStream1 = ScriptValue( scriptState, branches->Get(scriptState->context(), 0).ToLocalChecked()); *newStream2 = ScriptValue( scriptState, branches->Get(scriptState->context(), 1).ToLocalChecked()); DCHECK(isReadableStream(scriptState, *newStream1)); DCHECK(isReadableStream(scriptState, *newStream2)); }
//___________________________________________________________________ void LineEditData::textChanged( void ) { // check whether text change was triggered manually // in which case do not start transition if( _edited ) { _edited = false; return; } if( transition().data()->isAnimated() ) { transition().data()->endAnimation(); } if( isLocked() ) { // if locked one do not start the new animation, to prevent flicker // instead, one hides the transition pixmap, trigger an update, and return. // animations are re-locked. transition().data()->hide(); lockAnimations(); _timer.start( 0, this ); return; } if( initializeAnimation() ) { lockAnimations(); animate(); } else { transition().data()->hide(); } }
/* Main program and UI creation */ int main (int argc, char *argv[]) { g_type_init(); gtk_init(&argc, &argv); bindtextdomain("tihos", PACKAGE_LOCALE_DIR); bind_textdomain_codeset("tihos", "UTF-8"); textdomain("tihos"); createUI(); updateBattery(); refreshWindowList(); /* Check if to start with screen lock */ if (argc > 1) { if (strcmp(argv[1], "--lock") == 0) { lockScreen(NULL, NULL); } } /* Key grabbing and looping depending on where we are */ while (1) { if (isLocked()) { while (gtk_events_pending()) { gtk_main_iteration(); } handleX(); } else if (isMainVisible()) { while (gtk_events_pending()) { gtk_main_iteration(); } } else { handleX(); } } }