//------------------------------------------------------------------------ // micro_queue //------------------------------------------------------------------------ void micro_queue::push( const void* item, ticket k, concurrent_queue_base& base ) { k &= -concurrent_queue_rep::n_queue; page* p = NULL; size_t index = (k/concurrent_queue_rep::n_queue & base.items_per_page-1); if ( !index ) { size_t n = sizeof(page) + base.items_per_page*base.item_size; p = static_cast<page*>(operator new( n )); p->mask = 0; p->next = NULL; } { push_finalizer finalizer( *this, k+concurrent_queue_rep::n_queue ); spin_wait_until_eq( tail_counter, k ); if ( p ) { spin_mutex::scoped_lock lock( page_mutex ); if ( page* q = tail_page ) q->next = p; else head_page = p; tail_page = p; } else { p = tail_page; } base.copy_item( *p, index, item ); // If no exception was thrown, mark item as present. p->mask |= uintptr(1)<<index; } }
void QDispatchQueue::setFinalizer( xdispatch::operation *op, const xdispatch::queue &q ) { finalizer( op, q ); }
void AcceptChangeCommand::undo() { m_changeTracker->acceptRejectChange(m_changeId, false); TextCommandBase::undo(); UndoRedoFinalizer finalizer(this); emit acceptRejectChange(); }
void ChangeListLevelCommand::redo() { if (!m_first) { KoTextCommandBase::redo(); UndoRedoFinalizer finalizer(this); for (int i = 0; i < m_blocks.size(); ++i) { m_lists.value(i)->updateStoredList(m_blocks.at(i)); QTextBlock currentBlock(m_blocks.at(i)); KoTextBlockData userData(currentBlock); userData.setCounterWidth(-1.0); } } else { for (int i = 0; i < m_blocks.size() && m_lists.value(i); ++i) { if (!m_lists.value(i)->style()->hasLevelProperties(m_levels.value(i))) { KoListLevelProperties llp = m_lists.value(i)->style()->levelProperties(m_levels.value(i)); if (llp.alignmentMode() == false) { //old list mode, see KoListLevelProperties::alignmentMode() documentation llp.setIndent((m_levels.value(i)-1) * 20); //TODO make this configurable } else { llp.setTabStopPosition(MARGIN_DEFAULT*(m_levels.value(i)+1)); llp.setMargin(MARGIN_DEFAULT*(m_levels.value(i)+1)); llp.setTextIndent(- MARGIN_DEFAULT); } llp.setDisplayLevel(llp.displayLevel() + m_coefficient); llp.setLevel(m_levels.value(i)); m_lists.value(i)->style()->setLevelProperties(llp); } m_lists.value(i)->add(m_blocks.at(i), m_levels.value(i)); } } m_first = false; }
void QDispatchQueue::setFinalizer( QRunnable *r, const xdispatch::queue &dq ) { Q_ASSERT( r ); finalizer( new RunnableOperation( r ), dq ); }
void ShowChangesCommand::undo() { KoTextCommandBase::undo(); UndoRedoFinalizer finalizer(this); foreach (KUndo2Command *shapeCommand, m_shapeCommands) shapeCommand->undo(); emit toggledShowChange(!m_showChanges); enableDisableStates(!m_showChanges); }
void rs::jsapi::Object::Finalize(JSFreeOp* fop, JSObject* obj) { auto state = Object::GetState(obj); if (state != nullptr && state->finalizer != nullptr) { state->finalizer(); } SetState(obj, nullptr); delete state; }
void flush_page_cache(gc_page_cache* cache, void (*finalizer)(gc_page* page)) { for(int i = 0; i < cache->entry_count; ++i) { if(cache->cache_entries[i]) { if(finalizer) finalizer(cache->cache_entries[i]); cache->cache_entries[i] = 0; cache->entry_ages[i] = 0; } } cache->hint_index = 0; }
int wpl_text_chunks::expression::run ( wpl_text_state *state, int index, wpl_value *final_result, wpl_io &io ) { wpl_value_output_trigger output_trigger(io); wpl_value_double_finalizer finalizer(&output_trigger, final_result); return state->run_expression (exp.get(), index, &finalizer); }
duk_ret_t ClassFinalizer( duk_context * ctx ) { size_t class_identifier; finalizer_t finalizer; void * object = Get( ctx, 0, class_identifier, finalizer ); if( finalizer ) { finalizer( object ); } return 0; }
void DeleteCommand::undo() { KoTextCommandBase::undo(); UndoRedoFinalizer finalizer(this); // Look at KoTextCommandBase documentation // KoList updateListChanges(); // KoTextRange KoTextRangeManager *rangeManager = KoTextDocument(m_document).textRangeManager(); foreach (KoTextRange *range, m_rangesToRemove) { rangeManager->insert(range); }
void ChangeListLevelCommand::undo() { KoTextCommandBase::undo(); UndoRedoFinalizer finalizer(this); for (int i = 0; i < m_blocks.size(); ++i) { if (m_blocks.at(i).textList()) m_lists.value(i)->updateStoredList(m_blocks.at(i)); QTextBlock currentBlock(m_blocks.at(i)); KoTextBlockData userData(currentBlock); userData.setCounterWidth(-1.0); } }
void pone_opaque_free(pone_world* world, pone_val* v) { assert(pone_type(v) == PONE_OPAQUE); v->as.opaque.body->refcnt--; if (v->as.opaque.body->refcnt == 0) { pone_finalizer_t finalizer = v->as.opaque.body->finalizer; // finalizer is optional. it may null value. if (finalizer) { finalizer(world, v); } } pone_free(world, v->as.opaque.body); }
void ShowChangesCommand::redo() { if (!m_first) { KoTextCommandBase::redo(); UndoRedoFinalizer finalizer(this); foreach (KUndo2Command *shapeCommand, m_shapeCommands) shapeCommand->redo(); emit toggledShowChange(m_showChanges); enableDisableStates(m_showChanges); } else { m_first = false; enableDisableChanges(); } }
void omrthread_tls_finalizeNoLock(omrthread_t thread) { intptr_t index = 0; omrthread_library_t lib = thread->library; for (index = 0; index < J9THREAD_MAX_TLS_KEYS; index++) { if (NULL != thread->tls[index]) { void *value = thread->tls[index]; omrthread_tls_finalizer_t finalizer = lib->tls_finalizers[index]; if (NULL != value) { finalizer(value); } } } }
bool micro_queue::pop( void* dst, ticket k, concurrent_queue_base& base ) { k &= -concurrent_queue_rep::n_queue; spin_wait_until_eq( head_counter, k ); spin_wait_while_eq( tail_counter, k ); page& p = *head_page; __TBB_ASSERT( &p, NULL ); size_t index = (k/concurrent_queue_rep::n_queue & base.items_per_page-1); bool success = false; { pop_finalizer finalizer( *this, k+concurrent_queue_rep::n_queue, index==base.items_per_page-1 ? &p : NULL ); if ( p.mask & uintptr(1)<<index ) { success = true; base.assign_and_destroy_item( dst, p, index ); } } return success; }
void MainWindow::onNewGame() { m_needDestroy = false; m_gameConfiguring = true; std::shared_ptr<void> finalizer(nullptr, [&](void*) { m_gameConfiguring = false; }); NewGameDialog dialog; if (dialog.exec() != QDialog::Accepted) return; const GameConfig& config = dialog.gameConfig(); if (!config.isInititialized()) return; auto rival = std::move(dialog.rival()); connect(Kg::difficulty(), SIGNAL(currentLevelChanged(const KgDifficultyLevel*)), rival.get(), SLOT(onDifficultyChanged(const KgDifficultyLevel*))); m_menu.m_undoAction->setEnabled(rival->canUndo()); connect(rival.get(), SIGNAL(needDestroy()), this, SLOT(onNeedDestroy())); m_model = std::unique_ptr<BoardModel>(new BoardModel(config, createStepQueue(config))); connect(m_menu.m_undoAction, SIGNAL(triggered(bool)), m_model.get(), SLOT(undo())); connect(m_model.get(), SIGNAL(statusUpdated(const QString&)), statusBar(), SLOT(showMessage(const QString&))); { std::unique_ptr<IBoardView> view(new BoardView(this)); connect(this, SIGNAL(preferencesUpdated()), view->getObject(), SLOT(update())); setCentralWidget(qobject_cast<QWidget*>(view->getObject())); m_model->setView(std::move(view)); } m_model->setRival(std::move(rival)); m_menu.m_endAction->setEnabled(true); if (m_needDestroy) endGame(); }
void AcceptChangeCommand::redo() { if (m_first) { m_first = false; QTextCursor cursor(m_document); if (m_changeTracker->elementById(m_changeId)->changeType() != KOdfGenericChange::DeleteChange) { QList<QPair<int, int> >::const_iterator it; for (it = m_changeRanges.constBegin(); it != m_changeRanges.constEnd(); it++) { cursor.setPosition((*it).first); cursor.setPosition((*it).second, QTextCursor::KeepAnchor); QTextCharFormat format = cursor.charFormat(); int changeId = format.property(KCharacterStyle::ChangeTrackerId).toInt(); if (changeId == m_changeId) { if (int parentChangeId = m_changeTracker->parent(m_changeId)) { format.setProperty(KCharacterStyle::ChangeTrackerId, parentChangeId); } else { format.clearProperty(KCharacterStyle::ChangeTrackerId); } cursor.setCharFormat(format); } } } else { QList<QPair<int, int> >::const_iterator it; QStack<QPair<int, int> > deleteRanges; for (it = m_changeRanges.constBegin(); it != m_changeRanges.constEnd(); it++) { deleteRanges.push(QPair<int, int>((*it).first, (*it).second)); } while (!deleteRanges.isEmpty()) { QPair<int, int> range = deleteRanges.pop(); cursor.setPosition(range.first); cursor.setPosition(range.second, QTextCursor::KeepAnchor); cursor.deleteChar(); } } m_changeTracker->acceptRejectChange(m_changeId, true); } else { m_changeTracker->acceptRejectChange(m_changeId, true); TextCommandBase::redo(); UndoRedoFinalizer finalizer(this); } emit acceptRejectChange(); }
bool ScenarioLoader::load( const io::FilePath& filename, Scenario& scenario ) { // try to load file based on file extension Impl::LoaderIterator it = _d->loaders.begin(); for( ; it != _d->loaders.end(); ++it) { if( (*it)->isLoadableFileExtension( filename.toString() ) /*|| (*it)->isLoadableFileFormat(file) */ ) { bool loadok = (*it)->load( filename.toString(), scenario ); if( loadok ) { ScenarioLoadFinalizer finalizer( scenario ); finalizer.check(); } return loadok; } } return false; // failed to load }
/** * Run finalizers on any non-NULL TLS values for the current thread * * @param[in] thread current thread * @return none */ void omrthread_tls_finalize(omrthread_t thread) { intptr_t index; omrthread_library_t lib = thread->library; for (index = 0; index < J9THREAD_MAX_TLS_KEYS; index++) { if (thread->tls[index] != NULL) { void *value; omrthread_tls_finalizer_t finalizer; /* read the value and finalizer together under mutex to be sure that they belong together */ J9OSMUTEX_ENTER(lib->tls_mutex); value = thread->tls[index]; finalizer = lib->tls_finalizers[index]; J9OSMUTEX_EXIT(lib->tls_mutex); if (value) { finalizer(value); } } } }
/* tail an oplog. ok to return, will be re-called. */ void SyncTail::oplogApplication() { ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); ApplyBatchFinalizer finalizer(replCoord); OperationContextImpl txn; OpTime originalEndOpTime(getMinValid(&txn).end); while (!inShutdown()) { OpQueue ops; Timer batchTimer; int lastTimeChecked = 0; do { int now = batchTimer.seconds(); // apply replication batch limits if (!ops.empty()) { if (now > replBatchLimitSeconds) break; if (ops.getDeque().size() > replBatchLimitOperations) break; } // occasionally check some things // (always checked in the first iteration of this do-while loop, because // ops is empty) if (ops.empty() || now > lastTimeChecked) { BackgroundSync* bgsync = BackgroundSync::get(); if (bgsync->getInitialSyncRequestedFlag()) { // got a resync command return; } lastTimeChecked = now; // can we become secondary? // we have to check this before calling mgr, as we must be a secondary to // become primary tryToGoLiveAsASecondary(&txn, replCoord); } const int slaveDelaySecs = durationCount<Seconds>(replCoord->getSlaveDelaySecs()); if (!ops.empty() && slaveDelaySecs > 0) { const BSONObj lastOp = ops.back(); const unsigned int opTimestampSecs = lastOp["ts"].timestamp().getSecs(); // Stop the batch as the lastOp is too new to be applied. If we continue // on, we can get ops that are way ahead of the delay and this will // make this thread sleep longer when handleSlaveDelay is called // and apply ops much sooner than we like. if (opTimestampSecs > static_cast<unsigned int>(time(0) - slaveDelaySecs)) { break; } } if (MONGO_FAIL_POINT(rsSyncApplyStop)) { break; } // keep fetching more ops as long as we haven't filled up a full batch yet } while (!tryPopAndWaitForMore(&txn, &ops, replCoord) && // tryPopAndWaitForMore returns // true when we need to end a // batch early (ops.getSize() < replBatchLimitBytes) && !inShutdown()); // For pausing replication in tests while (MONGO_FAIL_POINT(rsSyncApplyStop)) { sleepmillis(0); if (inShutdown()) return; } if (ops.empty()) { continue; } const BSONObj lastOp = ops.back(); handleSlaveDelay(lastOp); // Set minValid to the last OpTime that needs to be applied, in this batch or from the // (last) failed batch, whichever is larger. // This will cause this node to go into RECOVERING state // if we should crash and restart before updating finishing. const OpTime start(getLastSetTimestamp(), OpTime::kUninitializedTerm); // Take the max of the first endOptime (if we recovered) and the end of our batch. const auto lastOpTime = fassertStatusOK(28773, OpTime::parseFromOplogEntry(lastOp)); // Setting end to the max of originalEndOpTime and lastOpTime (the end of the batch) // ensures that we keep pushing out the point where we can become consistent // and allow reads. If we recover and end up doing smaller batches we must pass the // originalEndOpTime before we are good. // // For example: // batch apply, 20-40, end = 40 // batch failure, // restart // batch apply, 20-25, end = max(25, 40) = 40 // batch apply, 25-45, end = 45 const OpTime end(std::max(originalEndOpTime, lastOpTime)); // This write will not journal/checkpoint. setMinValid(&txn, {start, end}); OpTime finalOpTime = multiApply(&txn, ops); setNewTimestamp(finalOpTime.getTimestamp()); setMinValid(&txn, end, DurableRequirement::None); finalizer.record(finalOpTime); } }
static void pointer_finalizer_trampoline (void *ptr, void *data) { scm_t_pointer_finalizer finalizer = data; finalizer (SCM_POINTER_VALUE (SCM_PACK_POINTER (ptr))); }
// C++14 lambda test // RUN: %clang_cc1 -fopenmp-implicit-declare-target -x c++ -std=c++14 -DCK4 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc // RUN: %clang_cc1 -fopenmp-implicit-declare-target -x c++ -std=c++14 -DCK4 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CK4 --check-prefix CK4-64 #ifdef CK4 template<typename Body, typename... Ts> auto finalizer(Body &&b, Ts&&... args) { return 20; } auto make_funky = [](auto &&f) { return [=](auto&& ...args) { return finalizer(f, args...); }; }; template <typename Body, typename...Args> decltype(auto) do_funky_back(Body&&b, Args&&... args) { return b((args)...); } auto foo = make_funky([](auto&&...args){ return do_funky_back(args...); }); void fooz (int argc, char* argv[]) { int a = 0;
/* tail an oplog. ok to return, will be re-called. */ void SyncTail::oplogApplication() { OpQueueBatcher batcher(this); OperationContextImpl txn; auto replCoord = ReplicationCoordinator::get(&txn); ApplyBatchFinalizer finalizer(replCoord); auto minValidBoundaries = getMinValid(&txn); OpTime originalEndOpTime(minValidBoundaries.end); OpTime lastWriteOpTime{replCoord->getMyLastOptime()}; while (!inShutdown()) { OpQueue ops; do { if (BackgroundSync::get()->getInitialSyncRequestedFlag()) { // got a resync command return; } tryToGoLiveAsASecondary(&txn, replCoord, minValidBoundaries, lastWriteOpTime); // Blocks up to a second waiting for a batch to be ready to apply. If one doesn't become // ready in time, we'll loop again so we can do the above checks periodically. ops = batcher.getNextBatch(Seconds(1)); } while (!inShutdown() && ops.empty()); if (inShutdown()) return; invariant(!ops.empty()); const BSONObj lastOp = ops.back().raw; if (lastOp.isEmpty()) { // This means that the network thread has coalesced and we have processed all of its // data. invariant(ops.getDeque().size() == 1); if (replCoord->isWaitingForApplierToDrain()) { replCoord->signalDrainComplete(&txn); } continue; // This wasn't a real op. Don't try to apply it. } handleSlaveDelay(lastOp); // Set minValid to the last OpTime that needs to be applied, in this batch or from the // (last) failed batch, whichever is larger. // This will cause this node to go into RECOVERING state // if we should crash and restart before updating finishing. const OpTime start(getLastSetTimestamp(), OpTime::kUninitializedTerm); // Take the max of the first endOptime (if we recovered) and the end of our batch. const auto lastOpTime = fassertStatusOK(28773, OpTime::parseFromOplogEntry(lastOp)); // Setting end to the max of originalEndOpTime and lastOpTime (the end of the batch) // ensures that we keep pushing out the point where we can become consistent // and allow reads. If we recover and end up doing smaller batches we must pass the // originalEndOpTime before we are good. // // For example: // batch apply, 20-40, end = 40 // batch failure, // restart // batch apply, 20-25, end = max(25, 40) = 40 // batch apply, 25-45, end = 45 const OpTime end(std::max(originalEndOpTime, lastOpTime)); // This write will not journal/checkpoint. setMinValid(&txn, {start, end}); lastWriteOpTime = multiApply(&txn, ops); setNewTimestamp(lastWriteOpTime.getTimestamp()); setMinValid(&txn, end, DurableRequirement::None); minValidBoundaries.start = {}; minValidBoundaries.end = end; finalizer.record(lastWriteOpTime); } }