예제 #1
0
void NVEventQueue::Shutdown()
{
  pthread_mutex_destroy(&m_accessLock);

  // free everyone...
  unlockAll(&m_consumerSync);
  unlockAll(&m_blockerSync);
  syncDestroy(&m_consumerSync);
  syncDestroy(&m_blockerSync);
}
예제 #2
0
void Node::removeSiblingLocksBackoff()
{
    lockAll();
    
    removeFixupParent();
    removeFixupSibsThreaded();
    
    unlockAll();
    removeFixupSelf();
}
예제 #3
0
static void NVEventShutdown()
{
    JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv();

    if (!jniEnv || !s_globalThiz)
    {
        __android_log_print(ANDROID_LOG_DEBUG, MODULE,  "Error: DestroyingRegisteredObjectInstance no TLS data!");
    }

    jniEnv->DeleteGlobalRef(s_globalThiz);
	s_globalThiz = NULL;

    __android_log_print(ANDROID_LOG_DEBUG, MODULE,  "Released global thiz!");

	pthread_mutex_destroy(&(s_eventQueue.m_mutex));

	// free everyone...
	unlockAll(&s_eventQueue.m_nativeSync);
	unlockAll(&s_eventQueue.m_javaSync);
	syncDestroy(&(s_eventQueue.m_nativeSync));
	syncDestroy(&(s_eventQueue.m_javaSync));
}
예제 #4
0
static void* NVEventMainLoopThreadFunc(void*)
{
	NVEventAppMain(0, NULL);
    __android_log_print(ANDROID_LOG_DEBUG, MODULE,  "NvEvent native app Main returned");

	// signal the condition variable to unblock
	// java from waiting on pause or quit
	unlockAll(&(s_eventQueue.m_javaSync));

    s_alreadyFinishing = true;

	JNIEnv* env = NVThreadGetCurrentJNIEnv(); 
    env->CallVoidMethod(s_globalThiz, s_finish);

	return NULL;
}
예제 #5
0
void Monitor::wait()
{
    assertex(owner==GetCurrentThreadId());
    waiting++;
    void *cur = last;
    last = &cur;
    while (1) {
        int locked = unlockAll();
        sem->wait();
        lockAll(locked);
        if (cur==NULL) { // i.e. first in
            void **p=(void **)&last;
            while (*p!=&cur)
                p = (void **)*p;
            *p = NULL; // reset so next picks up
            break;
        }
        sem->signal();
    }
}
예제 #6
0
static void NVEventQuitAndWait()
{
    if (!s_alreadyFinishing)
    {
	    __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Posting quit event");

		// flush ALL events
		s_eventQueue.m_headIndex = s_eventQueue.m_nextInsertIndex;

	    NVEvent ev;
	    ev.m_type = NV_EVENT_QUIT;
	    NVEventInsertNewest(&s_eventQueue, &ev);

		// ensure that the native side
		// isn't blocked waiting for an event -- since we've flushed
		// all the events save quit, we must artificially unblock native
		unlockAll(&(s_eventQueue.m_nativeSync));

	    __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Waiting for main loop exit");
	    pthread_join(s_mainThread, NULL);
	    __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Main loop exited");
    }
}
예제 #7
0
void NVEventQueue::UnblockProducer()
{
  unlockAll(&m_blockerSync);
}
예제 #8
0
void NVEventQueue::UnblockConsumer()
{
  unlockAll(&m_consumerSync);
}
예제 #9
0
ThrDevs::~ThrDevs(){
	unlockAll();
	delete pvLocked;
};
예제 #10
0
MountProtector::~MountProtector() {
    unlockAll();
}
예제 #11
0
파일: mainwindow.cpp 프로젝트: KDE/knetwalk
void MainWindow::setupActions()
{
    // Game
    KStandardGameAction::gameNew(this, SLOT(startNewGame()),
                                 actionCollection());

    m_pauseAction = KStandardGameAction::pause(this, SLOT(pauseGame(bool)),
                                               actionCollection());
    connect(Kg::difficulty(), &KgDifficulty::gameRunningChanged, m_pauseAction,
            &QAction::setEnabled);

    QAction *action = KStandardGameAction::solve(m_view, SLOT(solve()), actionCollection());
    connect(Kg::difficulty(), &KgDifficulty::gameRunningChanged, action, &QAction::setEnabled);

    KStandardGameAction::highscores(this, SLOT(showHighscores()),
                                    actionCollection());

    KStandardGameAction::quit(this, SLOT(close()), actionCollection());

    // Settings
    KStandardAction::preferences(this, SLOT(configureSettings()), actionCollection());

    action = new QAction(i18n("&Unlock All"), this);
    connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(unlockAll()));
    connect(Kg::difficulty(), &KgDifficulty::gameRunningChanged, action, &QAction::setEnabled);
    actionCollection()->addAction( QStringLiteral( "unlock_all" ), action);

    action = new QAction(i18n("Keyboard: Field right"), this);
    actionCollection()->setDefaultShortcut(action, Qt::Key_Right);
    connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(kbGoRight()));
    actionCollection()->addAction( QStringLiteral( "kb_go_right" ), action);

    action = new QAction(i18n("Keyboard: Field left"),this);
    actionCollection()->setDefaultShortcut(action, Qt::Key_Left);
    connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(kbGoLeft()));
    actionCollection()->addAction( QStringLiteral( "kb_go_left" ), action);

    action = new QAction(i18n("Keyboard: Field up"),this);
    actionCollection()->setDefaultShortcut(action, Qt::Key_Up);
    connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(kbGoUp()));
    actionCollection()->addAction( QStringLiteral( "kb_go_up" ), action);

    action = new QAction(i18n("Keyboard: Field down"),this);
    actionCollection()->setDefaultShortcut(action, Qt::Key_Down);
    connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(kbGoDown()));
    actionCollection()->addAction( QStringLiteral( "kb_go_down" ), action);

    action = new QAction(i18n("Keyboard: Turn clockwise"),this);
    actionCollection()->setDefaultShortcut(action, Qt::Key_Return);
    connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(rotateClockwise()));
    actionCollection()->addAction( QStringLiteral( "kb_turn_clockwise" ), action);

    action = new QAction(i18n("Keyboard: Turn counterclockwise"),this);
    actionCollection()->setDefaultShortcut(action, Qt::CTRL + Qt::Key_Return);
    connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(rotateCounterclockwise()));
    actionCollection()->addAction( QStringLiteral( "kb_turn_counterclockwise" ), action);

    action = new QAction(i18n("Keyboard: Toggle lock"),this);
    actionCollection()->setDefaultShortcut(action, Qt::Key_Space);
    connect(action, SIGNAL(triggered()), m_view->rootObject(), SLOT(toggleLock()));
    actionCollection()->addAction( QStringLiteral( "kb_lock" ), action);
}
void ReplicationCoordinatorExternalStateImpl::shardingOnTransitionToPrimaryHook(
    OperationContext* txn) {
    auto status = ShardingStateRecovery::recover(txn);

    if (ErrorCodes::isShutdownError(status.code())) {
        // Note: callers of this method don't expect exceptions, so throw only unexpected fatal
        // errors.
        return;
    }

    if (!status.isOK()) {
        fassertFailedWithStatus(40107, status);
    }

    if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
        status = Grid::get(txn)->catalogManager()->initializeConfigDatabaseIfNeeded(txn);
        if (!status.isOK() && status != ErrorCodes::AlreadyInitialized) {
            if (ErrorCodes::isShutdownError(status.code())) {
                // Don't fassert if we're mid-shutdown, let the shutdown happen gracefully.
                return;
            }

            fassertFailedWithStatus(40184,
                                    Status(status.code(),
                                           str::stream()
                                               << "Failed to initialize config database on config "
                                                  "server's first transition to primary"
                                               << causedBy(status)));
        }

        if (status.isOK()) {
            // Load the clusterId into memory. Use local readConcern, since we can't use majority
            // readConcern in drain mode because the global lock prevents replication. This is
            // safe, since if the clusterId write is rolled back, any writes that depend on it will
            // also be rolled back.
            // Since we *just* wrote the cluster ID to the config.version document (via
            // ShardingCatalogManager::initializeConfigDatabaseIfNeeded), this should always
            // succeed.
            status = ClusterIdentityLoader::get(txn)->loadClusterId(
                txn, repl::ReadConcernLevel::kLocalReadConcern);

            if (ErrorCodes::isShutdownError(status.code())) {
                // Don't fassert if we're mid-shutdown, let the shutdown happen gracefully.
                return;
            }

            fassertStatusOK(40217, status);
        }

        // For upgrade from 3.2 to 3.4, check if any shards in config.shards are not yet marked as
        // shard aware, and attempt to initialize sharding awareness on them.
        auto shardAwareInitializationStatus =
            Grid::get(txn)->catalogManager()->initializeShardingAwarenessOnUnawareShards(txn);
        if (!shardAwareInitializationStatus.isOK()) {
            warning() << "Error while attempting to initialize sharding awareness on sharding "
                         "unaware shards "
                      << causedBy(shardAwareInitializationStatus);
        }

        // Free any leftover locks from previous instantiations
        auto distLockManager = Grid::get(txn)->catalogClient(txn)->getDistLockManager();
        distLockManager->unlockAll(txn, distLockManager->getProcessID());

        // If this is a config server node becoming a primary, start the balancer
        auto balancer = Balancer::get(txn);

        // We need to join the balancer here, because it might have been running at a previous time
        // when this node was a primary.
        balancer->joinThread();
        balancer->startThread(txn);
    } else if (ShardingState::get(txn)->enabled()) {
        const auto configsvrConnStr =
            Grid::get(txn)->shardRegistry()->getConfigShard()->getConnString();
        auto status = ShardingState::get(txn)->updateShardIdentityConfigString(
            txn, configsvrConnStr.toString());
        if (!status.isOK()) {
            warning() << "error encountered while trying to update config connection string to "
                      << configsvrConnStr << causedBy(status);
        }
    }

    // There is a slight chance that some stale metadata might have been loaded before the latest
    // optime has been recovered, so throw out everything that we have up to now
    ShardingState::get(txn)->clearCollectionMetadata();
}
void ReplicationCoordinatorExternalStateImpl::_shardingOnTransitionToPrimaryHook(
    OperationContext* opCtx) {
    auto status = ShardingStateRecovery::recover(opCtx);

    if (ErrorCodes::isShutdownError(status.code())) {
        // Note: callers of this method don't expect exceptions, so throw only unexpected fatal
        // errors.
        return;
    }

    fassertStatusOK(40107, status);

    if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
        status = ShardingCatalogManager::get(opCtx)->initializeConfigDatabaseIfNeeded(opCtx);
        if (!status.isOK() && status != ErrorCodes::AlreadyInitialized) {
            if (ErrorCodes::isShutdownError(status.code())) {
                // Don't fassert if we're mid-shutdown, let the shutdown happen gracefully.
                return;
            }

            fassertFailedWithStatus(
                40184,
                status.withContext("Failed to initialize config database on config server's "
                                   "first transition to primary"));
        }

        if (status.isOK()) {
            // Load the clusterId into memory. Use local readConcern, since we can't use majority
            // readConcern in drain mode because the global lock prevents replication. This is
            // safe, since if the clusterId write is rolled back, any writes that depend on it will
            // also be rolled back.
            // Since we *just* wrote the cluster ID to the config.version document (via
            // ShardingCatalogManager::initializeConfigDatabaseIfNeeded), this should always
            // succeed.
            status = ClusterIdentityLoader::get(opCtx)->loadClusterId(
                opCtx, repl::ReadConcernLevel::kLocalReadConcern);

            if (ErrorCodes::isShutdownError(status.code())) {
                // Don't fassert if we're mid-shutdown, let the shutdown happen gracefully.
                return;
            }

            fassertStatusOK(40217, status);
        }

        // Free any leftover locks from previous instantiations.
        auto distLockManager = Grid::get(opCtx)->catalogClient()->getDistLockManager();
        distLockManager->unlockAll(opCtx, distLockManager->getProcessID());

        // If this is a config server node becoming a primary, start the balancer
        Balancer::get(opCtx)->initiateBalancer(opCtx);

        if (auto validator = LogicalTimeValidator::get(_service)) {
            validator->enableKeyGenerator(opCtx, true);
        }
    } else if (ShardingState::get(opCtx)->enabled()) {
        invariant(serverGlobalParams.clusterRole == ClusterRole::ShardServer);

        const auto configsvrConnStr =
            Grid::get(opCtx)->shardRegistry()->getConfigShard()->getConnString();
        auto status = ShardingState::get(opCtx)->updateShardIdentityConfigString(
            opCtx, configsvrConnStr.toString());
        if (!status.isOK()) {
            warning() << "error encountered while trying to update config connection string to "
                      << configsvrConnStr << causedBy(status);
        }

        CatalogCacheLoader::get(_service).onStepUp();
        ShardingState::get(_service)->initiateChunkSplitter();
    } else {  // unsharded
        if (auto validator = LogicalTimeValidator::get(_service)) {
            validator->enableKeyGenerator(opCtx, true);
        }
    }

    SessionCatalog::get(_service)->onStepUp(opCtx);
}