Ejemplo n.º 1
0
QSharedPointer<Action> BaseModel::createAction(const QString& uuid)
{
    if (!m_pvt->m_achievements.contains(uuid)) {
        qDebug() << "no such achievement: " << uuid;
        return QSharedPointer<Action>();
    }

    QSharedPointer<Achievement> achievementPtr = m_pvt->m_achievements[uuid];
    QSharedPointer<Action> actionPtr(new Action(tr("[no name action]"), achievementPtr)); //= achivementPtr->addAction(tr("no name action"));
    achievementPtr->addAction(actionPtr);

    m_pvt->m_actions[actionPtr->uuid().toString()] = actionPtr;
    emit actionCreated(actionPtr);
    return actionPtr;
}
Ejemplo n.º 2
0
KAccelAction* KAccelActions::insert( const QString& sName, const QString& sLabel )
{
	if( actionPtr( sName ) ) {
		kdWarning(125) << "KAccelActions::insertLabel( " << sName << ", " << sLabel << " ): action with same name already present." << endl;
		return 0;
	}

	KAccelAction* pAction = new KAccelAction;
	pAction->m_sName = sName;
	pAction->m_sLabel = sLabel;
	pAction->m_bConfigurable = false;
	pAction->m_bEnabled = false;

	insertPtr( pAction );
	return pAction;
}
Ejemplo n.º 3
0
bool KAccelBase::setShortcut(const QString &sAction, const KShortcut &cut)
{
    KAccelAction *pAction = actionPtr(sAction);
    if(pAction)
    {
        if(m_bAutoUpdate)
            removeConnection(pAction);

        pAction->setShortcut(cut);

        if(m_bAutoUpdate && !pAction->shortcut().isNull())
            insertConnection(pAction);
        return true;
    }
    else
        return false;
}
Ejemplo n.º 4
0
KAccelAction* KAccelActions::insert( const QString& sAction, const QString& sLabel, const QString& sWhatsThis,
			const KShortcut& rgCutDefaults3, const KShortcut& rgCutDefaults4,
			const QObject* pObjSlot, const char* psMethodSlot,
			bool bConfigurable, bool bEnabled )
{
	//kdDebug(125) << "KAccelActions::insert()2 begin" << endl;
	if( actionPtr( sAction ) ) {
		kdWarning(125) << "KAccelActions::insert( " << sAction << " ): action with same name already present." << endl;
		return 0;
	}

	KAccelAction* pAction = new KAccelAction(
		sAction, sLabel, sWhatsThis,
		rgCutDefaults3, rgCutDefaults4,
		pObjSlot, psMethodSlot,
		bConfigurable, bEnabled );
	insertPtr( pAction );

	//kdDebug(125) << "KAccelActions::insert()2 end" << endl;
	return pAction;
}
Ejemplo n.º 5
0
bool KAccelBase::setActionEnabled(const QString &sAction, bool bEnable)
{
    KAccelAction *pAction = actionPtr(sAction);
    if(pAction)
    {
        if(pAction->m_bEnabled != bEnable)
        {
            kdDebug(125) << "KAccelBase::setActionEnabled( " << sAction << ", " << bEnable << " )" << endl;
            pAction->m_bEnabled = bEnable;
            if(m_bAutoUpdate)
            {
                // FIXME: the action may already have it's connections inserted!
                if(bEnable)
                    insertConnection(pAction);
                else if(pAction->isConnected())
                    removeConnection(pAction);
            }
        }
        return true;
    }
    return false;
}
Ejemplo n.º 6
0
const KAccelAction& KAccelActions::operator []( uint i ) const
{
	return *actionPtr( i );
}
Ejemplo n.º 7
0
Archivo: plr.c Proyecto: sbrocket/plr
int plr_waitBarrier(int (*actionPtr)(void), waitActionType_t actionType) {
  pthread_mutex_lock(&plrShm->lock);
  
  // Ignore calls to plr_wait that come from the wrong pid, seems to
  // occur when also instrumenting binary with Pin
  if (myProcShm->pid != getpid()) {
    pthread_mutex_unlock(&plrShm->lock);
    return 0;
  }
  
  // Mark this process as waiting at barrier
  int waitIdx = plrShm->curWaitIdx;
  assert(plrShm->condWaitCnt[waitIdx] <= plrShm->nProc);
  myProcShm->waitIdx = waitIdx;
  plrShm->condWaitCnt[waitIdx]++;
  
  // If this isn't the first process to wait, wake up all other waiting
  // processes so their timers restart (to avoid early watchdog timeout)
  if (plrShm->condWaitCnt[waitIdx] > 1 && plrShm->condWaitCnt[waitIdx] < plrShm->nProc) {
    for (int i = 0; i < plrShm->nProc; ++i) {
      // pthread_cond_signal does nothing if no threads waiting on it,
      // so safe to call on all procs, waiting or not
      pthread_cond_signal(&allProcShm[i].cond[waitIdx]);
    }
  }
  
  // Wait until all processes have reached this barrier
  int watchdogExpired = 0;
  while (1) {
    // Check barrier exit conditions
    if (myProcShm->waitIdx < 0) {
      // Wait flag already cleared, break out of wait loop
      break;
    }
    if (myProcShm->waitIdx >= 0 && plrShm->condWaitCnt[waitIdx] == plrShm->nProc) {
      // Exit condition is met but wait flag has not been removed
      // Call barrier action through provided function ptr now that all
      // processes are synchronized & waiting at the barrier
      int actionSuccess = 0;
      if (actionPtr) {
        int runAction = 0;
        
        switch (actionType) {
        case WAIT_ACTION_ANY:
          runAction = 1;
          break;
        case WAIT_ACTION_MASTER:
          if (plr_isMasterProcess()) {
            runAction = 1;
          } else {
            // Wake up master process so it can run action
            pthread_cond_signal(&allProcShm[0].cond[waitIdx]);
          }
          break;
        case WAIT_ACTION_SLAVE:
          if (plr_isMasterProcess()) {
            // Wake up a slave process so it can run action
            pthread_cond_signal(&allProcShm[1].cond[waitIdx]);
          } else {
            runAction = 1;
          }
        }
        
        if (runAction) {
          int ret = actionPtr();
          if (ret < 0) {
            myProcShm->waitIdx = -1;
            plrShm->condWaitCnt[waitIdx]--;
            pthread_mutex_unlock(&plrShm->lock);
            exit(1);
          } else if (ret == 0) {
            actionSuccess = 1;
          } else {
            // Signal another process to wake up & run action
            for (int i = 0; i < plrShm->nProc; ++i) {
              if (myProcShm != &allProcShm[i]) {
                pthread_cond_signal(&allProcShm[i].cond[waitIdx]);
                break;
              }
            }
          }
        }
      } else {
        // No action function ptr provided, default success once exit condition met
        actionSuccess = 1;
      }
      
      // If barrier action succeeds, wake up all other processes & leave barrier
      if (actionSuccess) {
        if (myProcShm->waitIdx >= 0) {
          // Shift curWaitIdx to other value so subsequent plr_wait calls use the
          // other condition variable
          plrShm->curWaitIdx = (plrShm->curWaitIdx) ? 0 : 1;
          
          // Reset all wait flags and wake up all other processes
          //printf("[%d] Signaling all processes to wake up for idx %d\n", getpid(), waitIdx);
          for (int i = 0; i < plrShm->nProc; ++i) {
            pthread_cond_signal(&allProcShm[i].cond[waitIdx]);
            allProcShm[i].waitIdx = -1;
          }
        }
        
        // Break out of wait loop
        break;
      }
    }
    
    // Check if watchdog expired
    if (watchdogExpired) {
      int ret = plr_watchdogExpired();
      if (ret < 0) {
        myProcShm->waitIdx = -1;
        plrShm->condWaitCnt[waitIdx]--;
        pthread_mutex_unlock(&plrShm->lock);
        exit(1);
      } else if (ret == 1) {
        // Forked new process to replace stuck one, check barrier exit condition again
        continue;
      }
    }
    
    // Must use CLOCK_REALTIME, _timedwait needs abstime since epoch
    struct timespec absWait;
    clock_gettime(CLOCK_REALTIME, &absWait);
    absWait = tspecAddMs(absWait, plrShm->watchdogTimeout);
        
    // Using _timedwait as a watchdog timer, to avoid deadlock in case one of the
    // redundant processes has died or is stuck
    // NOTE: This ignores the case of pthread_cond_timedwait returning EINTR, in
    // which case less time than specified has elapsed. This can result in a longer
    // than desired wait time because timer may just restart.

    int ret = pthread_cond_timedwait(&myProcShm->cond[waitIdx], &plrShm->lock, &absWait);
    if (ret == ETIMEDOUT) {
      // Loop again to make sure timer didn't expire while last proc was waiting
      watchdogExpired = 1; 
    } else if (ret != 0) {
      plrlog(LOG_ERROR, "[%d] pthread_cond_timedwait returned %d\n", getpid(), ret);
    }
  }
  
  // Decrement waiting process counter
  plrShm->condWaitCnt[waitIdx]--;
  
  pthread_mutex_unlock(&plrShm->lock);
  return 0;
}
Ejemplo n.º 8
0
KAccelAction *KAccelBase::actionPtr(const KKey &key)
{
    KKeyServer::Key k2;
    k2.init(key, !m_bNativeKeys);
    return actionPtr(k2);
}