Ejemplo n.º 1
0
Archivo: poll.c Proyecto: h-sun/miss
/**
 * Check all active event objects. If an event is detected, notify the
 * associated waiting Java thread.
 */
void check_events()
{
  int i;
  for(i = 0; i < eventCnt; i++)
  {
    NXTEvent *event = events[i];
    NXTEvent *sync = event->sync;
    // Is this event being waited on, and has the event check period expired?
    if (sync->state != 0 && (--event->updateCnt <= 0) && get_monitor_count(&(sync->_super.sync)) == 0)
    {
      // Check to see if we have anything of interest
      int changed = ((*(eventCheckers[event->typ]))(event->filter) | event->userEvents | event->eventData) & event->filter;
      event->eventData |= changed;
      // notify the user thread
      if (changed && (sync->state == WAITING))
      {
        // Don't notify this thread again.
        sync->state |= SET;
        monitor_notify_unchecked(&sync->_super, 1);
        schedule_request(REQUEST_SWITCH_THREAD);
      }
      // Reste the check period counter
      event->updateCnt = event->updatePeriod;
    }
  }
}
Ejemplo n.º 2
0
boolean debug_event(int event, Object *exception, const Thread *thread, const MethodRecord *method, byte *pc, int frame)
{
  // Inform the debug thread (if any) that there has been a debug event.
  // return false if no debug thread is waiting.
  switch(debugEventOptions[event])
  {
    case DBG_EVENT_DISABLE:
      return false;
    case DBG_EVENT_IGNORE:
      return true;
    default:
      break;
  }
  // Check that we have a debugger attached and that it is ready to go...
  if (!debug || get_monitor_count((&(debug->_super.sync))) != 0 ||
      debugThread->state != CONDVAR_WAITING || (Debug *)debugThread->waitingOn != debug)
    return false;
  // Setup the state
  debug->typ = event;
  debug->exception = ptr2ref(exception);
  debug->thread = ptr2ref(thread);
  debug->pc = (pc ? pc - get_binary_base() : 0);
  debug->method = (method ? method - get_method_table(get_class_record(0)) : 0);
  debug->frame = frame;
  // Suspend all threads (except current)
  suspend_thread(null);
  // Make sure current thread is also suspended
  suspend_thread(currentThread);
  //  Allow the debug thread to run
  resume_thread(debugThread);
  monitor_notify_unchecked(&debug->_super, 1);
  return true;
}
Ejemplo n.º 3
0
Archivo: poll.c Proyecto: h-sun/miss
/**
 * set and/or clear events.
 */
int change_event(NXTEvent *event, JINT set, JINT clear)
{
  event->userEvents &= ~clear;
  event->userEvents |= set;
  // deliver event now if it matches the filter and someone is waiting
  set &= event->filter;
  if (set && event->sync->state == WAITING && get_monitor_count(&(event->sync->_super.sync)) == 0)
  {
    event->eventData |= set;
    event->sync->state |= SET;
    monitor_notify_unchecked(&event->sync->_super, 1);
    schedule_request(REQUEST_SWITCH_THREAD);
  }
  return event->userEvents;
}
Ejemplo n.º 4
0
boolean debug_event(int event, Throwable *exception, const Thread *thread,
		const int method, const int pc, const int method2, const int pc2)
{
	if (!debug)
		return false;

	// Check whether the event occured on a system thread. Events on system threads are disabled.
	if (is_system(thread))
		return false;

	// Inform the debug thread (if any) that there has been a debug event.
	// return false if no debug thread is waiting.
	switch (debugEventOptions[event])
	{
	case DBG_EVENT_DISABLE:
		return false;
	case DBG_EVENT_IGNORE:
		return true;
	default:
		break;
	}
	// Check that we have a debugger attached and that it is ready to go...
	if (get_monitor_count((&(debug->_super.sync))) != 0
			|| debugThread->state != CONDVAR_WAITING
			|| (Debug *) debugThread->waitingOn != debug)
		return false;
	// Setup the state
	debug->typ = event;
	debug->exception = ptr2ref(exception);
	debug->thread = ptr2ref(thread);
	debug->pc = pc;
	debug->method = method;
	debug->method2 = method2;
	debug->pc2 = pc2;
	// Suspend all threads (except current)
	suspend_thread(null);
	// Make sure current thread is also suspended
	if (!is_system(currentThread))
		suspend_thread(currentThread);
	//  Allow the debug thread to run
	debugThread->flags &= ~THREAD_DAEMON;
	resume_thread(debugThread);
	monitor_notify_unchecked(&debug->_super, 1);
	return true;
}
Ejemplo n.º 5
0
Archivo: poll.c Proyecto: Ashatta/tools
void poll_inputs()
{
  short changed = 0;
  short button_state = 0;    
  short i;
  short *pOldValue = old_sensor_values;
  sensor_t *pSensor = &sensors[0];
  char packet_available;

  throttle_count--;
  if( throttle_count == 0){
    throttle_count = throttle;

    // If we're not polling or someone already has the monitor
    // return.
    if (!poller || get_monitor_count((&(poller->_super))) != 0)
      return;

    // We do not have a thread that we can use to grab
    // the monitor but that's OK because we are atomic
    // anyway.
      
    // Check the sensor canonical values.
    for (i = 1<<SENSOR_POS; i<(1<<BUTTON_POS); i <<= 1, pOldValue++, pSensor++)
    {
      if (*pOldValue != pSensor->value) {
        changed |= i;
        *pOldValue = pSensor->value;
      }
    }

    // Check the button status
    read_buttons (0x3000, &button_state);
    button_state <<= BUTTON_POS; // Shift into poll position  
    changed |= button_state ^ old_button_state;
    old_button_state = button_state;

    // Check serial status
    check_for_data ( &packet_available, null);
    if (packet_available) {
        changed |= 1 << SERIAL_RECEIVED_POS;
    }

    // Only wake threads up if things have changed since
    // we last looked.    
    if (changed)
    {
      // Or in the latest changes. Some threads may not have
      // responded to earlier changes yet so we can't
      // just overwrite them.
      short jword = 0;
      store_word((byte*)(&jword), 2, changed);
      poller->changed |= jword;
      
#if DEBUG_POLL
      jword = get_word((byte*)&poller->changed, 2);
      printf("Poller: poller->changed = 0x%1X\n", jword);      
#endif
           
      // poller.notifyAll()
      monitor_notify_unchecked(&poller->_super, 1);
    }
  }
}