Esempio n. 1
0
bool QEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags)
{
    Q_D(QEventDispatcherGlib);

    const bool canWait = (flags & QEventLoop::WaitForMoreEvents);
    if (canWait)
        emit aboutToBlock();
    else
        emit awake();

    // tell postEventSourcePrepare() and timerSource about any new flags
    QEventLoop::ProcessEventsFlags savedFlags = d->timerSource->processEventsFlags;
    d->timerSource->processEventsFlags = flags;
    
    bool result = g_main_context_iteration(d->mainContext, canWait);
    while (!result && canWait)
        result = g_main_context_iteration(d->mainContext, canWait);
    
    d->timerSource->processEventsFlags = savedFlags;

    if (canWait)
        emit awake();

    return result;
}
Esempio n. 2
0
bool QEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags)
{
    Q_D(QEventDispatcherGlib);

    const bool canWait = (flags & QEventLoop::WaitForMoreEvents);
    if (canWait)
        emit aboutToBlock();
    else
        emit awake();

    // tell postEventSourcePrepare() and timerSource about any new flags
    QEventLoop::ProcessEventsFlags savedFlags = d->timerSource->processEventsFlags;
    d->timerSource->processEventsFlags = flags;

    if (!(flags & QEventLoop::EventLoopExec)) {
        // force timers to be sent at normal priority
        d->timerSource->runWithIdlePriority = false;
    }

    bool result = g_main_context_iteration(d->mainContext, canWait);
    while (!result && canWait)
        result = g_main_context_iteration(d->mainContext, canWait);

    d->timerSource->processEventsFlags = savedFlags;

    if (canWait)
        emit awake();

    return result;
}
Esempio n. 3
0
void Clock::sleep()
{
  if(!sleepOk) sleep_time = 0; else if(!sleepWasOk) awake();
  sleepWasOk = sleepOk;
  if(sleepOk && sleep_time >= (uint16_t) conf.sysOffTime * 10)
  {
//    lcd.off();
/*    attachInterrupt(1,wakeupFunction,LOW);
    sleep_mode();
    detachInterrupt(1);*/
    hardware_off();
    awake();
    wasSleeping = 1;
  }
  else if(backlightVal == 0 && light_time >= (uint16_t) conf.lcdBacklightTime * 10)
  {
    backlightVal = lcd.getBacklight();
    lcd.backlight(0);
  }
  if(hardware_flashlightIsOn())
  {
    if(flashlight_time >= (uint16_t) conf.flashlightOffTime * 10)
    {
      hardware_flashlight(0);
    }
  }
  else
  {
    flashlight_time = 0;
  }
}
Esempio n. 4
0
File: input.c Progetto: eknl/gt3b
static void read_ADC(void) {
    u16 *buf = adc_buffer[adc_buffer_pos];
    u8  dead;

    ADC_NEWVAL(0);
    ADC_NEWVAL(1);
    ADC_NEWVAL(2);
    adc_battery_last = ADC_DB3R;

    adc_buffer_pos++;
    adc_buffer_pos &= 3;

    BRES(ADC_CSR, 7);		// remove EOC flag
    BSET(ADC_CR1, 0);		// start new conversion

    // average battery voltage and check battery low
    // ignore very low, which means that it is supplied from SWIM connector
    adc_battery_filt = adc_battery_filt * (ADC_BAT_FILT - 1); // splitted - compiler hack
    adc_battery_filt = (adc_battery_filt + (ADC_BAT_FILT / 2)) / ADC_BAT_FILT
		       + adc_battery_last;
    adc_battery = (u16)((adc_battery_filt + (ADC_BAT_FILT / 2)) / ADC_BAT_FILT);
    // start checking battery after 5s from power on
    if (time_sec >= 5) {
	// wakeup task only when something changed
	if (adc_battery > 50 && adc_battery < battery_low_raw) {
	    // bat low
	    if (!menu_battery_low) {
		menu_battery_low = 1;
		awake(MENU);
	    }
	}
	else {
	    // bat OK, but apply some hysteresis to not switch quickly ON/OFF
	    if (menu_battery_low && adc_battery > battery_low_raw + 100) {
		menu_battery_low = 0;
		awake(MENU);
	    }
	}
    }

    // wakeup MENU task when showing battery or at calibrate
    if (menu_wants_adc)
	awake(MENU);

    // reset inactivity timer when some steering or throttle applied
    dead = cg.steering_dead_zone;
    if (dead < 20)  dead = 20;  // use some minimal dead zone for this check
    if (adc_steering_last < (cg.calib_steering_mid - dead) ||
        adc_steering_last > (cg.calib_steering_mid + dead))
	    reset_inactivity_timer();
    else {
	dead = cg.throttle_dead_zone;
	if (dead < 20)  dead = 20;  // use some minimal dead zone for this check
	if (adc_throttle_last < (cg.calib_throttle_mid - dead) ||
	    adc_throttle_last > (cg.calib_throttle_mid + dead))
		reset_inactivity_timer();
    }
}
Esempio n. 5
0
MockClient::MockClient()
    : display(wl_display_connect(0))
    , compositor(0)
    , output(0)
    , registry(0)
{
    if (!display)
        qFatal("MockClient(): wl_display_connect() failed");

    registry = wl_display_get_registry(display);
    wl_registry_add_listener(registry, &registryListener, this);

    fd = wl_display_get_fd(display);

    QSocketNotifier *readNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
    connect(readNotifier, SIGNAL(activated(int)), this, SLOT(readEvents()));

    QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::eventDispatcher;
    connect(dispatcher, SIGNAL(awake()), this, SLOT(flushDisplay()));

    QElapsedTimer timeout;
    timeout.start();
    do {
        QCoreApplication::processEvents();
    } while (!(compositor && output) && timeout.elapsed() < 1000);

    if (!compositor || !output)
        qFatal("MockClient(): failed to receive globals from display");
}
Esempio n. 6
0
File: ppm.c Progetto: eknl/gt3b
/*
    TIM3 overflow interrupt
    set next prescaler, output compare and overflow values to
      preload registers
*/
@interrupt void ppm_interrupt(void) {
    BRES(TIM3_SR1, 0);	// erase interrupt flag

    if (ppm_channel2) {
	if (ppm_channel2 == 2) {
	    // will be setting channel1 servo, so we are now generating
	    // SYNC signal in HW
	    // wakeup CALC task to compute new PPM values
	    // values for ARR registers will be updated after calculate done
	    // (and when we are still generating SYNC pulse)
	    awake(CALC);
	}
	// set servo channel
	TIM3_PSCR = PPM_PSC_SERVO;
	TIM3_CCR2H = hi8(PPM_300US_SERVO);
	TIM3_CCR2L = lo8(PPM_300US_SERVO);
	TIM3_ARRH = ppm_values[ppm_channel2];
	ppm_channel2++;
	TIM3_ARRL = ppm_values[ppm_channel2];
	if (++ppm_channel2 > channels2) {
	    // next to SYNC pulse
	    ppm_channel2 = 0;
	}
	return;
    }

    // set SYNC signal
    TIM3_PSCR = PPM_PSC_SYNC;
    TIM3_CCR2H = hi8(PPM_300US_SYNC);
    TIM3_CCR2L = lo8(PPM_300US_SYNC);
    TIM3_ARRH = ppm_values[0];
    TIM3_ARRL = ppm_values[1];
    ppm_channel2 = 2;  // to first channel (step 2 bytes)
}
void EnemyBehaviourSpiderLarge(Character *self, TimeInterval dt)
{
    EnemyState state = EnemyGetState(self);
    
    switch (state)
    {
        case EnemyStateSleep:
        {
            EnemyUpdatePlayerPos(self);
            if (self->canSeePlayer)
            {
                awake(self);
            }
            break;
        }
        case EnemyStateAwaken:
        {
            self->stateTime += dt;
            if (self->stateTime > 500)
            {
                rise(self);
            }
            break;
        }
        case EnemyStateRise:
        {
            break;
        }
        default:
        {
            EnemyDefaultBehaviour(self, dt);
            break;
        }
    }
}
Esempio n. 8
0
error_code _sys_lwmutex_unlock(ppu_thread& ppu, u32 lwmutex_id)
{
	sys_lwmutex.trace("_sys_lwmutex_unlock(lwmutex_id=0x%x)", lwmutex_id);

	const auto mutex = idm::check<lv2_obj, lv2_lwmutex>(lwmutex_id, [&](lv2_lwmutex& mutex) -> cpu_thread*
	{
		std::lock_guard lock(mutex.mutex);

		if (const auto cpu = mutex.schedule<ppu_thread>(mutex.sq, mutex.protocol))
		{
			return cpu;
		}

		mutex.signaled = 1;
		return nullptr;
	});

	if (!mutex)
	{
		return CELL_ESRCH;
	}

	if (mutex.ret)
	{
		mutex->awake(*mutex.ret);
	}

	return CELL_OK;
}
Esempio n. 9
0
error_code sys_mutex_unlock(ppu_thread& ppu, u32 mutex_id)
{
	sys_mutex.trace("sys_mutex_unlock(mutex_id=0x%x)", mutex_id);

	const auto mutex = idm::check<lv2_obj, lv2_mutex>(mutex_id, [&](lv2_mutex& mutex)
	{
		return mutex.try_unlock(ppu.id);
	});

	if (!mutex)
	{
		return CELL_ESRCH;
	}

	if (mutex.ret == CELL_EBUSY)
	{
		std::lock_guard lock(mutex->mutex);

		if (auto cpu = mutex->reown<ppu_thread>())
		{
			mutex->awake(*cpu);
		}
	}
	else if (mutex.ret)
	{
		return mutex.ret;
	}

	return CELL_OK;
}
Esempio n. 10
0
File: input.c Progetto: eknl/gt3b
static void input_loop(void) {

    // read initial ADC values
    BSET(ADC_CR1, 0);			// start conversion
    while (!BCHK(ADC_CSR, 7))  pause();	// wait for end of conversion
    read_ADC();

    // put initial values to all buffers
    ADC_BUFINIT(0);
    ADC_BUFINIT(1);
    ADC_BUFINIT(2);
    adc_battery = adc_battery_last;
    adc_battery_filt = (u32)adc_battery * ADC_BAT_FILT;

    // task CALC must be awaked to compute values before PPM will take on
    awake(CALC);
    input_initialized = 1;

    while (1) {
	// read ADC only when EOC flag (only for first it will not be ready)
	if (BCHK(ADC_CSR, 7))
	    read_ADC();
	read_keys();
	stop();
    }
}
Esempio n. 11
0
void Box2DBody::setAwake(bool _awake)
{
    if (awake() == _awake)
        return;

    if (mBody)
        mBody->SetAwake(_awake);
    else
        mBodyDef.awake = _awake;
}
bool AbstractMediaStream2::event(QEvent *e)
{
    if (e->type() == QEvent::ThreadChange) {
        Q_D(AbstractMediaStream2);
        if (d->eventDispatcher) {
            pWarning() << "Do not call moveToThread on an AbstractMediaStream2 object when it is in use.";
            QObject::disconnect(d->eventDispatcher, SIGNAL(awake()), this, SLOT(_k_handleStreamEvent()));
            d->eventDispatcher = 0;
        }
    }
    return AbstractMediaStream::event(e);
}
Esempio n. 13
0
error_code sys_event_queue_destroy(ppu_thread& ppu, u32 equeue_id, s32 mode)
{
	sys_event.warning("sys_event_queue_destroy(equeue_id=0x%x, mode=%d)", equeue_id, mode);

	if (mode && mode != SYS_EVENT_QUEUE_DESTROY_FORCE)
	{
		return CELL_EINVAL;
	}

	const auto queue = idm::withdraw<lv2_obj, lv2_event_queue>(equeue_id, [&](lv2_event_queue& queue) -> CellError
	{
		semaphore_lock lock(queue.mutex);

		if (!mode && !queue.sq.empty())
		{
			return CELL_EBUSY;
		}

		return {};
	});

	if (!queue)
	{
		return CELL_ESRCH;
	}

	if (queue.ret)
	{
		return queue.ret;
	}

	if (mode == SYS_EVENT_QUEUE_DESTROY_FORCE)
	{
		semaphore_lock lock(queue->mutex);

		for (auto cpu : queue->sq)
		{
			if (queue->type == SYS_PPU_QUEUE)
			{
				static_cast<ppu_thread&>(*cpu).gpr[3] = CELL_ECANCELED;
				queue->awake(*cpu);
			}
			else
			{
				static_cast<SPUThread&>(*cpu).ch_in_mbox.set_values(1, CELL_ECANCELED);
				cpu->state += cpu_flag::signal;
				cpu->notify();
			}
		}
	}

	return CELL_OK;
}
Esempio n. 14
0
void
reset_func (piece_info_t *obj)
{
	city_info_t *cityp;

	cityp = find_city (obj->loc);

	if (cityp != NULL)
	if (cityp->func[obj->type] != NOFUNC) {
		obj->func = cityp->func[obj->type];
		awake (obj);
	}
}
void AbstractMediaStream2Private::dataReady()
{
    Q_Q(AbstractMediaStream2);
    if (!eventDispatcher) {
        eventDispatcher = QAbstractEventDispatcher::instance(q->thread());
        if (!eventDispatcher) {
            pError() << "AbstractMediaStream2 needs to run in a thread with QEventLoop";
            return;
        } else {
            QObject::connect(eventDispatcher, SIGNAL(awake()), q, SLOT(_k_handleStreamEvent()), Qt::DirectConnection);
        }
    }
    eventDispatcher->wakeUp();
}
Esempio n. 16
0
static void awake_dit(plan *ego_, int flg)
{
     P_dit *ego = (P_dit *) ego_;

     AWAKE(ego->cld, flg);
     if (flg)
	  ego->W = mktwiddle(ego->m, ego->super.n, ego->super.g);
     else {
	  free_twiddle(ego->W);
	  ego->W = 0;
     }

     awake(ego_, flg);
}
int QAbstractEventDispatcher::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: aboutToBlock(); break;
        case 1: awake(); break;
        default: ;
        }
        _id -= 2;
    }
    return _id;
}
Esempio n. 18
0
bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags)
{
    Q_D(QEventDispatcherUNIX);
    d->interrupt = false;

    // we are awake, broadcast it
    emit awake();
    QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData);

    int nevents = 0;
    const bool canWait = (d->threadData->canWait
                          && !d->interrupt
                          && (flags & QEventLoop::WaitForMoreEvents));

    if (canWait)
        emit aboutToBlock();

    if (!d->interrupt) {
        // return the maximum time we can wait for an event.
        timeval *tm = 0;
        timeval wait_tm = { 0l, 0l };
        if (!(flags & QEventLoop::X11ExcludeTimers)) {
            if (d->timerList.timerWait(wait_tm))
                tm = &wait_tm;
        }

        if (!canWait) {
            if (!tm)
                tm = &wait_tm;

            // no time to wait
            tm->tv_sec  = 0l;
            tm->tv_usec = 0l;
        }

        nevents = d->doSelect(flags, tm);

        // activate timers
        if (! (flags & QEventLoop::X11ExcludeTimers)) {
            nevents += activateTimers();
        }
    }
    // return true if we handled events, false otherwise
    return (nevents > 0);
}
Esempio n. 19
0
bool lv2_event_queue::send(lv2_event event)
{
	semaphore_lock lock(mutex);

	if (sq.empty())
	{
		if (events.size() < this->size)
		{
			// Save event
			events.emplace_back(event);
			return true;
		}

		return false;
	}

	if (type == SYS_PPU_QUEUE)
	{
		// Store event in registers
		auto& ppu = static_cast<ppu_thread&>(*schedule<ppu_thread>(sq, protocol));

		std::tie(ppu.gpr[4], ppu.gpr[5], ppu.gpr[6], ppu.gpr[7]) = event;

		awake(ppu);
	}
	else
	{
		// Store event in In_MBox
		auto& spu = static_cast<SPUThread&>(*sq.front());

		// TODO: use protocol?
		sq.pop_front();

		const u32 data1 = static_cast<u32>(std::get<1>(event));
		const u32 data2 = static_cast<u32>(std::get<2>(event));
		const u32 data3 = static_cast<u32>(std::get<3>(event));
		spu.ch_in_mbox.set_values(4, CELL_OK, data1, data2, data3);

		spu.state += cpu_flag::signal;
		spu.notify();
	}

	return true;
}
int PropertiesManager::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 3)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 3;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< int*>(_v) = intermittentPeriod(); break;
        case 1: *reinterpret_cast< bool*>(_v) = autoStart(); break;
        case 2: *reinterpret_cast< bool*>(_v) = awake(); break;
        }
        _id -= 3;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setIntermittentPeriod(*reinterpret_cast< int*>(_v)); break;
        case 1: setAutoStart(*reinterpret_cast< bool*>(_v)); break;
        case 2: setAwake(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 3;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 3;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
main()
{
	char stealfood(char x[]);
	char discovery(char x[]);
	char trace(char x[]);
	char run(char x[]);
	char awake(char x[]);
	char yad(char x[]);
	char a[]={"р╩ж╩юойСм╣Ёт╤╚нВё╛"};
	char b[]={"ц╗╥╒ожакюойСё╛"};
	char c[]={"ц╗в╥юойСё╛"};
	char d[]={"юойС╥иеэё╛"};
	char e[]={"╬╙пяакп║╧╥ё╛"};
	char f[]={"п║╧╥╥м║ё"};
	stealfood(a);
	discovery(b);
	trace(c);
	run(d);
	awake(e);
	yad(f);


getchar();
}
Esempio n. 22
0
error_code _sys_lwcond_signal(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u32 ppu_thread_id, u32 mode)
{
	sys_lwcond.trace("_sys_lwcond_signal(lwcond_id=0x%x, lwmutex_id=0x%x, ppu_thread_id=0x%x, mode=%d)", lwcond_id, lwmutex_id, ppu_thread_id, mode);

	// Mode 1: lwmutex was initially owned by the calling thread
	// Mode 2: lwmutex was not owned by the calling thread and waiter hasn't been increased
	// Mode 3: lwmutex was forcefully owned by the calling thread

	if (mode < 1 || mode > 3)
	{
		fmt::throw_exception("Unknown mode (%d)" HERE, mode);
	}

	lv2_lwmutex* mutex = nullptr;

	const auto cond = idm::check<lv2_obj, lv2_lwcond>(lwcond_id, [&](lv2_lwcond& cond) -> cpu_thread*
	{
		mutex = idm::check_unlocked<lv2_obj, lv2_lwmutex>(lwmutex_id);

		if (cond.waiters)
		{
			std::lock_guard lock(cond.mutex);

			cpu_thread* result = nullptr;

			if (ppu_thread_id != -1)
			{
				for (auto cpu : cond.sq)
				{
					if (cpu->id == ppu_thread_id)
					{
						verify(HERE), cond.unqueue(cond.sq, cpu);
						result = cpu;
						break;
					}
				}
			}
			else
			{
				result = cond.schedule<ppu_thread>(cond.sq, cond.control->lwmutex->attribute & SYS_SYNC_ATTR_PROTOCOL_MASK);
			}

			if (result)
			{
				cond.waiters--;

				if (mode == 2)
				{
					static_cast<ppu_thread*>(result)->gpr[3] = CELL_EBUSY;
				}

				if (mode == 1)
				{
					verify(HERE), !mutex->signaled;
					std::lock_guard lock(mutex->mutex);
					mutex->sq.emplace_back(result);
					result = nullptr;
					mode = 2; // Enforce CELL_OK
				}

				return result;
			}
		}

		return nullptr;
	});

	if ((lwmutex_id && !mutex) || !cond)
	{
		return CELL_ESRCH;
	}

	if (cond.ret)
	{
		cond->awake(*cond.ret);
	}
	else if (mode == 2)
	{
		return CELL_OK;
	}
	else if (mode == 1 || ppu_thread_id == -1)
	{
		return not_an_error(CELL_EPERM);
	}
	else
	{
		return not_an_error(CELL_ENOENT);
	}

	return CELL_OK;
}
Esempio n. 23
0
void
piece_move (piece_info_t *obj)
{
	int changed_loc;
	int speed, max_hits;
	int saved_moves;
	int need_input;
	long saved_loc;
	city_info_t *cityp;

	/* set func for piece if on city */
	cityp = find_city (obj->loc);
	if (cityp != NULL)
		if (cityp->func[obj->type] != NOFUNC)
			obj->func = cityp->func[obj->type];

	changed_loc = FALSE; /* not changed yet */
	speed = piece_attr[obj->type].speed;
	max_hits = piece_attr[obj->type].max_hits;
	need_input = FALSE; /* don't require user input yet */

	while (obj->moved < obj_moves (obj)) {
		saved_moves = obj->moved; /* save moves made */
		saved_loc = obj->loc; /* remember starting location */

		if (awake (obj) || need_input){ /* need user input? */
			ask_user (obj);
			display_loc_u (obj->loc); /* let user see result */
			need_input = FALSE; /* we got it */
		}

		if (obj->moved == saved_moves) /* user set function? */
		switch (obj->func) { /* handle preprogrammed function */
		case NOFUNC:    break;
		case RANDOM:    move_random (obj); break;
		case SENTRY:    obj->moved = speed; break;
		case FILL:      move_fill (obj); break;
		case LAND:      move_land (obj); break;
		case EXPLORE:   move_explore (obj); break;
		case ARMYLOAD:  move_armyload (obj); break;
		case ARMYATTACK:move_armyattack (obj); break;
		case TTLOAD:    move_ttload (obj); break;
		case REPAIR:    move_repair (obj); break;
		case WFTRANSPORT: move_transport (obj); break;

		case MOVE_N:
		case MOVE_NE:
		case MOVE_E:
		case MOVE_SE:
		case MOVE_S:
		case MOVE_SW:
		case MOVE_W:
		case MOVE_NW:
			move_dir (obj); break;

		default: move_path (obj); break;
		}

		if (obj->moved == saved_moves) need_input = TRUE;

		/*
		 * handle fighters specially.  If in a city or carrier, turn
		 * is over and reset range to max.  Otherwise, if
		 * range = 0, fighter crashes and burns and turn is over.
		 */

		if (obj->type == FIGHTER && obj->hits > 0) {
			if ((user_map[obj->loc].contents == 'O'
			  || user_map[obj->loc].contents == 'C')
			&& obj->moved > 0) {
				obj->range = piece_attr[FIGHTER].range;
				obj->moved = speed;
				obj->func = NOFUNC;
				info("Landing confirmed.");
			}
			else if (obj->range == 0) {
				info("Fighter at %d crashed and burned.", obj->loc);
				kill_obj (obj, obj->loc);
			}
		}

		if (saved_loc != obj->loc) changed_loc = TRUE;
	}
	/* if a boat is in port, damaged, and never moved, fix some damage */
	if (obj->hits > 0 /* still alive? */
		&& !changed_loc /* object never changed location? */
		&& obj->type != ARMY && obj->type != FIGHTER /* it is a boat? */
		&& obj->hits < max_hits /* it is damaged? */
		&& user_map[obj->loc].contents == 'O') /* it is in port? */
	obj->hits++; /* fix some damage */
}
Esempio n. 24
0
File: lcd.c Progetto: Micha500/gt3b
// set all LCD segments ON
void lcd_set_full_on(void) {
    lcd_set_flag = 1;
    awake(LCD);
    pause();
}
Esempio n. 25
0
File: lcd.c Progetto: Micha500/gt3b
// clear entire LCD
void lcd_clear(void) {
    lcd_clr_flag = 1;
    awake(LCD);
    pause();
}
Esempio n. 26
0
File: lcd.c Progetto: Micha500/gt3b
// send modified data to LCD controller
void lcd_update(void) {
    lcd_update_flag = 1;
    awake(LCD);
}
Esempio n. 27
0
error_code _sys_lwcond_queue_wait(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u64 timeout)
{
	sys_lwcond.trace("_sys_lwcond_queue_wait(lwcond_id=0x%x, lwmutex_id=0x%x, timeout=0x%llx)", lwcond_id, lwmutex_id, timeout);

	std::shared_ptr<lv2_lwmutex> mutex;

	const auto cond = idm::get<lv2_obj, lv2_lwcond>(lwcond_id, [&](lv2_lwcond& cond) -> cpu_thread*
	{
		mutex = idm::get_unlocked<lv2_obj, lv2_lwmutex>(lwmutex_id);

		if (!mutex)
		{
			return nullptr;
		}

		std::lock_guard lock(cond.mutex);

		// Add a waiter
		cond.waiters++;
		cond.sq.emplace_back(&ppu);
		cond.sleep(ppu, timeout);

		std::lock_guard lock2(mutex->mutex);

		// Process lwmutex sleep queue
		if (const auto cpu = mutex->schedule<ppu_thread>(mutex->sq, mutex->protocol))
		{
			return cpu;
		}

		mutex->signaled++;
		return nullptr;
	});

	if (!cond || !mutex)
	{
		return CELL_ESRCH;
	}

	if (cond.ret)
	{
		cond->awake(*cond.ret);
	}

	ppu.gpr[3] = CELL_OK;

	while (!ppu.state.test_and_reset(cpu_flag::signal))
	{
		if (ppu.is_stopped())
		{
			return 0;
		}

		if (timeout)
		{
			const u64 passed = get_system_time() - ppu.start_time;

			if (passed >= timeout)
			{
				std::lock_guard lock(cond->mutex);

				if (!cond->unqueue(cond->sq, &ppu))
				{
					timeout = 0;
					continue;
				}

				cond->waiters--;

				if (mutex->signaled.try_dec())
				{
					ppu.gpr[3] = CELL_EDEADLK;
					break;
				}

				ppu.gpr[3] = CELL_ETIMEDOUT;
				break;
			}

			thread_ctrl::wait_for(timeout - passed);
		}
		else
		{
			thread_ctrl::wait();
		}
	}

	// Return cause
	return not_an_error(ppu.gpr[3]);
}
Esempio n. 28
0
bool QEventLoop::processEvents( ProcessEventsFlags flags )
{
    // process events from the X server
    XEvent event;
    int	   nevents = 0;

#if defined(QT_THREAD_SUPPORT)
    QMutexLocker locker( QApplication::qt_mutex );
#endif

    // handle gui and posted events
    if ( qt_is_gui_used ) {
	QApplication::sendPostedEvents();

	// Two loops so that posted events accumulate
	while ( XPending( QPaintDevice::x11AppDisplay() ) ) {
	    // also flushes output buffer
	    while ( XPending( QPaintDevice::x11AppDisplay() ) ) {
		if ( d->shortcut ) {
		    return FALSE;
		}

		XNextEvent( QPaintDevice::x11AppDisplay(), &event );

		if ( flags & ExcludeUserInput ) {
		    switch ( event.type ) {
		    case ButtonPress:
		    case ButtonRelease:
		    case MotionNotify:
		    case XKeyPress:
		    case XKeyRelease:
		    case EnterNotify:
		    case LeaveNotify:
			continue;

		    case ClientMessage:
			{
			    // from qapplication_x11.cpp
			    extern Atom qt_wm_protocols;
			    extern Atom qt_wm_take_focus;
			    extern Atom qt_qt_scrolldone;

			    // only keep the wm_take_focus and
			    // qt_qt_scrolldone protocols, discard all
			    // other client messages
			    if ( event.xclient.format != 32 )
				continue;

			    if ( event.xclient.message_type == qt_wm_protocols ||
				 (Atom) event.xclient.data.l[0] == qt_wm_take_focus )
				break;
			    if ( event.xclient.message_type == qt_qt_scrolldone )
				break;
			}

		    default: break;
		    }
		}

		nevents++;
		if ( qApp->x11ProcessEvent( &event ) == 1 )
		    return TRUE;
	    }
	}
    }

    if ( d->shortcut ) {
	return FALSE;
    }

    QApplication::sendPostedEvents();

    const uint exclude_all = ExcludeSocketNotifiers | 0x08;
    // 0x08 == ExcludeTimers for X11 only
    if ( nevents > 0 && ( flags & exclude_all ) == exclude_all &&
	 ( flags & WaitForMore ) ) {
	return TRUE;
    }

    // don't block if exitLoop() or exit()/quit() has been called.
    bool canWait = d->exitloop || d->quitnow ? FALSE : (flags & WaitForMore);

    // Process timers and socket notifiers - the common UNIX stuff

    // return the maximum time we can wait for an event.
    static timeval zerotm;
    timeval *tm = 0;
    if ( ! ( flags & 0x08 ) ) {			// 0x08 == ExcludeTimers for X11 only
	tm = qt_wait_timer();			// wait for timer or X event
	if ( !canWait ) {
	    if ( !tm )
		tm = &zerotm;
	    tm->tv_sec  = 0;			// no time to wait
	    tm->tv_usec = 0;
	}
    }

    int highest = 0;
    if ( ! ( flags & ExcludeSocketNotifiers ) ) {
	// return the highest fd we can wait for input on
	if ( d->sn_highest >= 0 ) {			// has socket notifier(s)
	    if ( d->sn_vec[0].list && ! d->sn_vec[0].list->isEmpty() )
		d->sn_vec[0].select_fds = d->sn_vec[0].enabled_fds;
	    else
		FD_ZERO( &d->sn_vec[0].select_fds );

	    if ( d->sn_vec[1].list && ! d->sn_vec[1].list->isEmpty() )
		d->sn_vec[1].select_fds = d->sn_vec[1].enabled_fds;
	    else
		FD_ZERO( &d->sn_vec[1].select_fds );

	    if ( d->sn_vec[2].list && ! d->sn_vec[2].list->isEmpty() )
		d->sn_vec[2].select_fds = d->sn_vec[2].enabled_fds;
	    else
		FD_ZERO( &d->sn_vec[2].select_fds );
	} else {
	    FD_ZERO( &d->sn_vec[0].select_fds );

	    FD_ZERO( &d->sn_vec[1].select_fds );
	    FD_ZERO( &d->sn_vec[2].select_fds );
	}

	highest = d->sn_highest;
    } else {
        FD_ZERO( &d->sn_vec[0].select_fds );
	FD_ZERO( &d->sn_vec[1].select_fds );
	FD_ZERO( &d->sn_vec[2].select_fds );
    }

    if ( qt_is_gui_used ) {
	// select for events on the event socket - only on X11
	FD_SET( d->xfd, &d->sn_vec[0].select_fds );
	highest = QMAX( highest, d->xfd );
    }

    FD_SET( d->thread_pipe[0], &d->sn_vec[0].select_fds );
    highest = QMAX( highest, d->thread_pipe[0] );

    if ( canWait )
	emit aboutToBlock();

    if ( qt_preselect_handler ) {
	QVFuncList::Iterator it, end = qt_preselect_handler->end();
	for ( it = qt_preselect_handler->begin(); it != end; ++it )
	    (**it)();
    }

    // unlock the GUI mutex and select.  when we return from this function, there is
    // something for us to do
#if defined(QT_THREAD_SUPPORT)
    locker.mutex()->unlock();
#endif

    int nsel;
    do {
	nsel = select( highest + 1,
		       &d->sn_vec[0].select_fds,
		       &d->sn_vec[1].select_fds,
		       &d->sn_vec[2].select_fds,
		       tm );
    } while (nsel == -1 && (errno == EINTR || errno == EAGAIN));

    // relock the GUI mutex before processing any pending events
#if defined(QT_THREAD_SUPPORT)
    locker.mutex()->lock();
#endif

    // we are awake, broadcast it
    emit awake();
    emit qApp->guiThreadAwake();

    if (nsel == -1) {
	if (errno == EBADF) {
	    // it seems a socket notifier has a bad fd... find out
	    // which one it is and disable it
	    fd_set fdset;
	    zerotm.tv_sec = zerotm.tv_usec = 0l;

	    for (int type = 0; type < 3; ++type) {
		QPtrList<QSockNot> *list = d->sn_vec[type].list;
		if (!list) continue;

		QSockNot *sn = list->first();
		while (sn) {
		    FD_ZERO(&fdset);
		    FD_SET(sn->fd, &fdset);

		    int ret = -1;
		    do {
			switch (type) {
			case 0: // read
			    ret = select(sn->fd + 1, &fdset, 0, 0, &zerotm);
			    break;
			case 1: // write
			    ret = select(sn->fd + 1, 0, &fdset, 0, &zerotm);
			    break;
			case 2: // except
			    ret = select(sn->fd + 1, 0, 0, &fdset, &zerotm);
			    break;
			}
		    } while (ret == -1 && (errno == EINTR || errno == EAGAIN));

		    if (ret == -1 && errno == EBADF) {
			// disable the invalid socket notifier
			static const char *t[] = { "Read", "Write", "Exception" };
			qWarning("QSocketNotifier: invalid socket %d and type '%s', disabling...",
				 sn->fd, t[type]);
			sn->obj->setEnabled(FALSE);
		    }

		    sn = list->next();
		}
	    }
	} else {
	    // EINVAL... shouldn't happen, so let's complain to stderr
	    // and hope someone sends us a bug report
	    perror( "select" );
	}
    }

    // some other thread woke us up... consume the data on the thread pipe so that
    // select doesn't immediately return next time
    if ( nsel > 0 && FD_ISSET( d->thread_pipe[0], &d->sn_vec[0].select_fds ) ) {
	char c;
	::read( d->thread_pipe[0], &c, 1 );
    }

    if ( qt_postselect_handler ) {
	QVFuncList::Iterator it, end = qt_postselect_handler->end();
	for ( it = qt_postselect_handler->begin(); it != end; ++it )
	    (**it)();
    }

    // activate socket notifiers
    if ( ! ( flags & ExcludeSocketNotifiers ) && nsel > 0 && d->sn_highest >= 0 ) {
	// if select says data is ready on any socket, then set the socket notifier
	// to pending
	int i;
	for ( i=0; i<3; i++ ) {
	    if ( ! d->sn_vec[i].list )
		continue;

	    QPtrList<QSockNot> *list = d->sn_vec[i].list;
	    QSockNot *sn = list->first();
	    while ( sn ) {
		if ( FD_ISSET( sn->fd, &d->sn_vec[i].select_fds ) )
		    setSocketNotifierPending( sn->obj );
		sn = list->next();
	    }
	}

	nevents += activateSocketNotifiers();
    }

    // activate timers
    if ( ! ( flags & 0x08 ) ) {
	// 0x08 == ExcludeTimers for X11 only
	nevents += activateTimers();
    }

    // color approx. optimization - only on X11
    qt_reset_color_avail();

    // return true if we handled events, false otherwise
    return (nevents > 0);
}
Esempio n. 29
0
bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags)
{
    Q_D(QEventDispatcherMac);
#if 0
    //TrackDrag says you may not use the EventManager things..
    if(qt_mac_in_drag) {
        qWarning("Qt: Cannot process events whilst dragging!");
        return false;
    }
#endif
    d->interrupt = false;
    emit awake();

#ifndef QT_MAC_NO_QUICKDRAW
    if(!qt_mac_safe_pdev) { //create an empty widget and this can be used for a port anytime
        QWidget *tlw = new QWidget;
        tlw->setAttribute(Qt::WA_DeleteOnClose);
        tlw->setObjectName(QLatin1String("empty_widget"));
        tlw->hide();
        qt_mac_safe_pdev = tlw;
    }
#endif

    bool retVal = false;
    for (;;) {
        QApplicationPrivate::sendPostedEvents(0, 0, d->threadData);

        if (d->activateTimers() > 0) //send null timers
            retVal = true;

        do {
            EventRef event;
            if (!(flags & QEventLoop::ExcludeUserInputEvents)
                    && !d->queuedUserInputEvents.isEmpty()) {
                // process a pending user input event
                event = d->queuedUserInputEvents.takeFirst();
            } else {
                OSStatus err = ReceiveNextEvent(0,0, kEventDurationNoWait, true, &event);
                if(err != noErr)
                    continue;
                // else
                if (flags & QEventLoop::ExcludeUserInputEvents) {
                     UInt32 ekind = GetEventKind(event),
                            eclass = GetEventClass(event);
                     switch(eclass) {
                         case kEventClassQt:
                             if(ekind != kEventQtRequestContext)
                                 break;
                             // fall through
                         case kEventClassMouse:
                         case kEventClassKeyboard:
                             d->queuedUserInputEvents.append(event);
                             continue;
                     }
                }
            }

            if (!filterEvent(&event) && qt_mac_send_event(flags, event))
                retVal = true;
            ReleaseEvent(event);
        } while(!d->interrupt && GetNumEventsInQueue(GetMainEventQueue()) > 0);

        bool canWait = (d->threadData->canWait
                        && !retVal
                        && !d->interrupt
                        && (flags & QEventLoop::WaitForMoreEvents)
                        && !d->zero_timer_count);
        if (canWait) {
            emit aboutToBlock();
            while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, true) == kCFRunLoopRunTimedOut);
            flags &= ~QEventLoop::WaitForMoreEvents;
            emit awake();
        } else {
            CFRunLoopRunInMode(kCFRunLoopDefaultMode, kEventDurationNoWait, true);
            break;
        }
    }
    return retVal;
}
Esempio n. 30
0
void QWaylandIntegration::initialize()
{
    QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::eventDispatcher;
    QObject::connect(dispatcher, SIGNAL(aboutToBlock()), mDisplay, SLOT(flushRequests()));
    QObject::connect(dispatcher, SIGNAL(awake()), mDisplay, SLOT(flushRequests()));
}