void Thread::StartThread() { if (thread) return; threadHoldEvent = CreateNewEvent(EventWaitSignal); threadHoldEventAcked = CreateNewEvent(EventWaitSignal); threadResumeEvent = CreateNewEvent(EventWaitSignal); threadEnabled = true; pthread_attr_t type; pthread_attr_init(&type); pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE); if (pthread_create(&thread, &type, ThreadEntryPoint, this)) throw NetException("Failed to create thread!"); else LOG(LogInfo, "Thread::Run(): Thread created."); SetName("kNet Thread"); }
bool ReadyEvent::SetEvent(int eventId, bool isReady) { bool objectExists; unsigned eventIndex = readyEventNodeList.GetIndexFromKey(eventId, &objectExists); if (objectExists == false) { // Totally new event CreateNewEvent(eventId, isReady); } else return SetEventByIndex(eventIndex, isReady); return true; }
bool ReadyEvent::ForceCompletion(int eventId) { bool objectExists; unsigned eventIndex = readyEventNodeList.GetIndexFromKey(eventId, &objectExists); if (objectExists == false) { // Totally new event CreateNewEvent(eventId, true); eventIndex = readyEventNodeList.GetIndexFromKey(eventId, &objectExists); } ReadyEventNode *ren = readyEventNodeList[eventIndex]; ren->eventStatus = ID_READY_EVENT_FORCE_ALL_SET; UpdateReadyStatus(eventIndex); return true; }
// TOGO for context menu in sequenceview and channel items GSynchEvent* GSequence::CreateNewEvent( GSynchEvent* pParentEvent /*= 0*/, GChannel* pAssignedChannelForGraphics /*= 0*/ ) { if(pParentEvent && pAssignedChannelForGraphics) return new GChannelSynchEvent(pParentEvent, pAssignedChannelForGraphics); if(pParentEvent && !pAssignedChannelForGraphics) return new GSynchEvent(pParentEvent); // if an event and a channel is selected in the GSequenceScene, let's use those to make a new event assigned to the channel QList<QGraphicsItem*> listGraphicsItemSelected = ChannelScene()->selectedItems() + EventTreeScene()->selectedItems(); QList<GSynchEvent*> listEventItem = GSequence::GetEvents(listGraphicsItemSelected); QList<GChannel*> listChannelItem = GSequence::GetChannels(listGraphicsItemSelected); // if no event and no channel defined if(!pParentEvent && !pAssignedChannelForGraphics) { // if there are exactly 1 event and 1 channel selected, we use those for parenting the event if(listEventItem.count() == 1 && listChannelItem.count() == 1) return CreateNewEvent(listEventItem.at(0), listChannelItem.at(0)); // if there are exactly 1 event we use it else if(listEventItem.count() == 1) return CreateNewEvent(listEventItem.at(0)); } // if no event but a channel defined if(!pParentEvent && pAssignedChannelForGraphics) { // if there are exactly 1 event and 1 channel selected, we use those for parenting the event if(listEventItem.count() == 1 && listChannelItem.count() == 1 && listChannelItem.at(0) == pAssignedChannelForGraphics) return CreateNewEvent(listEventItem.at(0), pAssignedChannelForGraphics); // if there are exactly 1 event we use it else if(listEventItem.count() == 1 && listChannelItem.count() == 0) return CreateNewEvent(listEventItem.at(0), pAssignedChannelForGraphics); } // otherwise, create an event child of the m_pRootTimeEvent return CreateNewEvent(m_pRootTimeEvent, pAssignedChannelForGraphics); }
bool ReadyEvent::AddToWaitList(int eventId, SystemAddress address) { bool eventExists; unsigned eventIndex = readyEventNodeList.GetIndexFromKey(eventId, &eventExists); if (eventExists == false) eventIndex = CreateNewEvent(eventId, false); // Don't do this, otherwise if we are trying to start a 3 player game, it will not allow the 3rd player to hit ready if the first two players have already done so //if (IsLocked(eventIndex)) // return false; // Not in the list, but event is already completed, or is starting to complete, and adding more waiters would fail this. unsigned i; unsigned numAdded = 0; if (address == UNASSIGNED_SYSTEM_ADDRESS) { for (i = 0; i < rakPeerInterface->GetMaximumNumberOfPeers(); i++) { SystemAddress internalAddress = rakPeerInterface->GetSystemAddressFromIndex(i); if (internalAddress != UNASSIGNED_SYSTEM_ADDRESS) numAdded += AddToWaitListInternal(eventIndex, internalAddress); } } else numAdded = AddToWaitListInternal(eventIndex, address); if (numAdded > 0) UpdateReadyStatus(eventIndex); return numAdded > 0; }