void GameController::CoordinateReleased() { for(int i=0;i<getLevel();++i) for(int j=0;j<getLevel();++j) setBlockColor(QPoint(i,j),GameData::BgColor); for(int i=0;i<getColorNumber()*2;++i) setBlockColor(gameSetting->Points[i],GameData::ColorSet[i/2]); for(int i=0;i<pipeManager->size();++i) { Pipe* pipe = pipeManager->at(i); if(pipeManager->currentPipe!=pipe) { while(!pipe->empty()) { QPoint _coordinate(pipe->back()); STATE _state = getBlockState(_coordinate); if((_state&WAY)==0||(_state&BREAK)!=0||(_state&CURRENT)!=0) pipe->pop_back(); else break; } } for(int j=0;j<pipe->size();++j) setBlockColor(pipe->at(j),pipe->Color); } for(int i=0;i<this->getLevel();++i) for(int j=0;j<this->getLevel();++j) setBlockState(QPoint(i,j),~(CURRENT|BREAK)); ++gameSetting->moves; emit UpdatePipeDisplay(); emit UpdateBlockDisplay(); if(CheckWin()) emit CompleteGame(); }
void GameController::CoordinateSelected(const QPoint &_coordinate) { this->pipeManager->currentPipe = this->pipeManager->getPipe(this->getBlockColor(_coordinate)); Pipe* pipe = pipeManager->currentPipe; while(!pipe->empty() && (pipe->back()!=_coordinate||(getBlockState(_coordinate)&ORIGIN)!=0)) { setBlockState(pipe->back(),~(WAY|CURRENT)); pipe->pop_back(); } if(pipe->empty()) { setBlockState(_coordinate,WAY|CURRENT); pipe->push_back(_coordinate); } for(int i=0;i<pipe->size();++i) setBlockState(pipe->at(i),CURRENT); emit UpdatePipeDisplay(); }
/* * Wait on the condvar with a given relative timeout in ms (which we * have to convert into a absolute timespec now) */ jboolean jcondvar_wait (jcondvar* cv, jmutex *mux, jlong timeout ) { jthread_t cur = jthread_current(); int status = 0; /* * If a thread trying to get a heavy lock is interrupted, we may get here * with the interrupted flag set (because the thread didn't get the heavy * lock and has to wait again). Therefore, we must not clear the interrupted * flag here. */ if ( timeout == NOTIMEOUT ) { /* we handle this as "wait forever" */ status = ThreadCondWait(cur, cv, mux); } else { sigset_t oldmask; struct timespec abst; struct timeval now; /* timeout is in millisecs, timeval in microsecs, and timespec in nanosecs */ gettimeofday( &now, NULL); abst.tv_sec = now.tv_sec + (timeout / 1000); if( abst.tv_sec < now.tv_sec ) { /* huge timeout value, we handle this as "wait forever" */ status = ThreadCondWait(cur, cv, mux); } else { abst.tv_nsec = (now.tv_usec * 1000) + (timeout % 1000) * 1000000; if (abst.tv_nsec > 1000000000) { abst.tv_sec += 1; abst.tv_nsec -= 1000000000; } setBlockState(cur, BS_CV_TO, (void*)&status, &oldmask); status = pthread_cond_timedwait( cv, mux, &abst); clearBlockState(cur, BS_CV_TO, &oldmask); } } /* * Since we interrupt a thread blocked on a condition variable by signaling that * condition variable, we cannot set the interrupted flag based on the value of * 'signal'. Therefore, we have to rely on the interrupting thread to set the * flag. */ return (status == 0); }
void jmutex_lock(jmutex* lk ) { jthread_t cur = jthread_current (); sigset_t oldmask; setBlockState(cur, BS_MUTEX, (void*)&cur, &oldmask); pthread_mutex_lock( lk ); clearBlockState(cur, BS_MUTEX, &oldmask); }
static inline int ThreadCondWait(jthread_t cur, jcondvar *cv, jmutex *mux) { int status = 0; sigset_t oldmask; setBlockState(cur, BS_CV, (void*)&status, &oldmask); status = pthread_cond_wait( cv, mux ); clearBlockState(cur, BS_CV, &oldmask); return status; }
void CodeEditor::contentsChange(int pos, int, int) { QTextBlock block = textCursor().block(); // сдвиг блока клавишей Return // состояние предыдущего блока может быть не верным if (block.userState() == Empty) block.setUserState(block.previous().userState() | Rehighligh); block = document()->findBlock(pos); int startBlockNum = block.blockNumber(); bool forceUnfold = false; while (block.isValid()) { int previousState = block.userState(); int state = setBlockState(block); if (!(previousState & Error) && !(state & Error) && previousState & Comment && state & Comment) { QTextBlock next = block.next(); int nextBlockState = next.userState(); setBlockState(next); next.setUserState(nextBlockState); // в начальное состояние // правильное состояние комментария известно // только после обработки последующей строки state = block.userState(); } if (state != previousState) { if (!forceUnfold) { // разворачиваем предыдущие блоки QTextBlock previous = block.previous(); while (previous.isValid()) { int state = previous.userState(); if (!(state & Error) && state & Folded) previous.setUserState(state & ~Folded); if (state & Error || !(state & Nested) || previous.isVisible()) break; previous.setVisible(true); previous = previous.previous(); } } forceUnfold = true; } else if (block.blockNumber() > startBlockNum && // не начальный блок state & Begin && !(state & Nested)) { // (state & Begin ...) пропускаем End главного блока break; // без state & Error, иначе срабатывает между блоками } // при первом обновлении if (forceUnfold) { // разворачиваем последующие блоки if (!(state & Error) && state & Folded) state &= ~Folded; block.setVisible(true); } block.setUserState(state | Rehighligh); block = block.next(); } }
void GameController::CoordinateChanged(const QPoint &_coordinate) { if(this->pipeManager->currentPipe==0) return; QPoint lastcoordinate = this->pipeManager->currentPipe->back(); QColor _coordinateColor = getBlockColor(_coordinate); STATE _coordinateState = getBlockState(_coordinate); int distance = Distance(lastcoordinate,_coordinate); if((_coordinateState&CURRENT)==0&&(getBlockState(lastcoordinate)&ORIGIN)!=0&&getBlockColor(lastcoordinate)==this->pipeManager->currentPipe->Color&&this->pipeManager->currentPipe->size()>1) return; if(distance!=1) { if(distance<=5&&(_coordinateState&ORIGIN)==0) AutoSearchPath(_coordinate); return; } if((_coordinateState&WAY)==0) { if((_coordinateState&ORIGIN)==0) { setBlockState(_coordinate,WAY|CURRENT); pipeManager->currentPipe->push_back(_coordinate); emit ForwardPipe(); emit UpdatePipeDisplay(); } else { if(_coordinateColor==pipeManager->currentPipe->Color) { setBlockState(_coordinate,WAY|CURRENT); pipeManager->currentPipe->push_back(_coordinate); emit CompletePipe(pipeManager->currentPipe); emit UpdatePipeDisplay(); } } } else { if((_coordinateState&CURRENT)!=0) { while(pipeManager->currentPipe->back()!=_coordinate) { QPoint backpoint = pipeManager->currentPipe->back(); QColor backpointColor = getBlockColor(backpoint); setBlockState(backpoint,~CURRENT); if(backpointColor==GameData::BgColor || backpointColor==pipeManager->currentPipe->Color) setBlockState(backpoint,~WAY); else { setBlockState(backpoint,~BREAK); Pipe* pipe = pipeManager->getPipe(backpointColor); bool unable = false; for(int i=0;i<pipe->size();++i) { STATE _state = getBlockState(pipe->at(i)); if((_state&BREAK)!=0) unable = true; if(unable && (_state&BREAK)==0) setBlockState(pipe->at(i),~WAY); else setBlockState(pipe->at(i),WAY); } } pipeManager->currentPipe->pop_back(); } emit BackwardPipe(); emit UpdatePipeDisplay(); } else { if((_coordinateState&ORIGIN)!=0) return; Pipe* pipe = pipeManager->getPipe(_coordinateColor); setBlockState(_coordinate,WAY|CURRENT|BREAK); pipeManager->currentPipe->push_back(_coordinate); bool unable = false; for(int i=0;i<pipe->size();++i) { STATE _state = getBlockState(pipe->at(i)); if((_state&BREAK)!=0) unable = true; if(unable && (_state&BREAK)==0) setBlockState(pipe->at(i),~WAY); else setBlockState(pipe->at(i),WAY); } emit BreakPipe(pipe); emit UpdatePipeDisplay(); } } }
void KaffePThread_setBlockingCall(void *sigdata) { jthread_t cur = jthread_current(); setBlockState(cur, BS_SYSCALL, (void*)&cur, (sigset_t*)sigdata); }