Exemplo n.º 1
0
int
Application_hintPause( Handle self, Bool set, int hintPause)
{
   if ( !set)
      return CTimer( var->  hintTimer)-> get_timeout( var->  hintTimer);
   return CTimer( var->  hintTimer)-> set_timeout( var->  hintTimer, hintPause);
}
Local gint CTimer__LINUX_interval(gpointer data) {
   CTimer *this = CTimer(data);

   (*this->method)(this->method_object, this->method_data);

   return TRUE;
}/*CTimer__WIN32_interval*/
Exemplo n.º 3
0
void
Application_set_hint_action( Handle self, Handle view, Bool show, Bool byMouse)
{
   if ( show && !is_opt( optShowHint)) return;
   if ( show)
   {
      var->  hintUnder = view;
      if ( var->  hintActive == -1)
      {
         Event ev = {cmHint};
         ev. gen. B = true;
         ev. gen. H = view;
         ((( PTimer) var->  hintTimer)-> self)-> stop( var-> hintTimer);
         var->  hintVisible = 1;
         if (( PWidget( view)-> stage == csNormal) &&
             ( CWidget( view)-> message( view, &ev)))
             hshow( self);
      } else {
         if ( !byMouse && var->  hintActive == 1) return;
         CTimer( var->  hintTimer)-> start( var-> hintTimer);
      }
      var->  hintActive = 1;
   } else {
      int oldHA = var->  hintActive;
      int oldHV = var->  hintVisible;
      if ( oldHA != -1)
         ((( PTimer) var-> hintTimer)-> self)-> stop( var-> hintTimer);
      if ( var->  hintVisible)
      {
         Event ev = {cmHint};
         ev. gen. B = false;
         ev. gen. H = view;
         var->  hintVisible = 0;
         if (( PWidget( view)-> stage != csNormal) ||
              ( CWidget( view)-> message( view, &ev)))
            CWidget( var->  hintWidget)-> hide( var->  hintWidget);
      }
      if ( oldHA != -1) var->  hintActive = 0;
      if ( byMouse && oldHV) {
         var->  hintActive = -1;
         CTimer( var->  hintTimer)-> start( var->  hintTimer);
      }
   }
}
Exemplo n.º 4
0
  CTimer& CTimer::get(const std::string name)
  {
    if(allTimer_ptr == NULL) allTimer_ptr = new std::map<std::string,CTimer>;

    //std::map<std::string,CTimer>::iterator it = allTimer.find(name);
    std::map<std::string,CTimer>::iterator it = allTimer_ptr->find(name);
    //if (it == allTimer.end())
    if (it == allTimer_ptr->end())
      it = allTimer_ptr->insert(std::make_pair(name, CTimer(name))).first;

      //it = allTimer.insert(std::make_pair(name, CTimer(name))).first;
    return it->second;
  }
Exemplo n.º 5
0
CEventQueueTimer*
CEventQueue::newOneShotTimer(double duration, void* target)
{
	assert(duration > 0.0);

	CEventQueueTimer* timer = m_buffer->newTimer(duration, true);
	if (target == NULL) {
		target = timer;
	}
	CArchMutexLock lock(m_mutex);
	m_timers.insert(timer);
	// initial duration is requested duration plus whatever's on
	// the clock currently because the latter will be subtracted
	// the next time we check for timers.
	m_timerQueue.push(CTimer(timer, duration,
							duration + m_time.getTime(), target, true));
	return timer;
}
Exemplo n.º 6
0
void
Application_HintTimer_handle_event( Handle timer, PEvent event)
{
   CComponent-> handle_event( timer, event);
   if ( event-> cmd == cmTimer) {
      Handle self = application;
      CTimer(timer)-> stop( timer);
      if ( var->  hintActive == 1) {
         Event ev = {cmHint};
         if (   !var->hintUnder
             || apc_application_get_widget_from_point( self,
                   my-> get_pointerPos(self)) != var->hintUnder
             || PObject( var-> hintUnder)-> stage != csNormal)
            return;
         ev. gen. B = true;
         ev. gen. H = var->  hintUnder;
         var->  hintVisible = 1;
         if (( PWidget( var->  hintUnder)-> stage == csNormal) &&
             ( CWidget( var->  hintUnder)-> message( var->  hintUnder, &ev)))
             hshow( self);
      } else if ( var->  hintActive == -1)
         var->  hintActive = 0;
   }
}
Exemplo n.º 7
0
const unsigned int MIN_HEARD_TIME_SECS     = 120U;

const int MINIMUM_DD_FRAME_LENGTH = 60;

const unsigned char ETHERNET_BROADCAST_ADDRESS[] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU};

IIRC*          CDDHandler::m_irc          = NULL;
CHeaderLogger* CDDHandler::m_headerLogger = NULL;
int            CDDHandler::m_fd           = -1;
unsigned int   CDDHandler::m_maxRoutes    = 0U;
CEthernet**    CDDHandler::m_list         = NULL;
unsigned char* CDDHandler::m_buffer       = NULL;
bool           CDDHandler::m_logEnabled   = false;
wxString       CDDHandler::m_logDir       = wxEmptyString;
wxString       CDDHandler::m_name         = wxEmptyString;
CTimer         CDDHandler::m_timer        = CTimer(1000U, MIN_HEARD_TIME_SECS);

CEthernet::CEthernet(const unsigned char* address, const wxString& callsign) :
m_address(NULL),
m_callsign(callsign)
{
	wxASSERT(address != NULL);
	wxASSERT(!callsign.IsEmpty());

	m_address = new unsigned char[ETHERNET_ADDRESS_LENGTH];
	::memcpy(m_address, address, ETHERNET_ADDRESS_LENGTH);
}

CEthernet::~CEthernet()
{
	delete[] m_address;
Exemplo n.º 8
0
void CWnd::SetTimer(ui32 nInterval)
{
	m_arrTimers.Add( CTimer(this, nInterval) ); 
}
int main(int argc, char **argv)
{
  FILE *fa, *fb;
  int numRowsA, numColsA, numRowsB, numColsB, numThreads;

  if(argc != 7) {
    printf("usage: my_matrix_multiply -a a_matrix_file.txt -b b_matrix_file.txt -t thread_count\n");
    exit(0);
  }
  int opt;
  while ((opt = getopt(argc, argv, ARGS)) != -1) {
    switch (opt) {
      case 'a':
        fa = fopen(optarg, "r");
        break;
      case 'b':
        fb = fopen(optarg, "r");
        break;
      case 't':
        numThreads = atoi(optarg);
        break;
      default:
        fprintf(stderr, "usage: my_matrix_multiply -a a_matrix_file.txt -b b_matrix_file.txt -t thread_count\n");
        exit(0);
    }
  }

  if (fa == NULL || fb == NULL){
    fprintf(stderr, "error: could not open file.\n");
    exit(0);
  }

  if (numThreads < 1){
    fprintf(stderr, "error: number of threads must be greater than 0.\n");
    exit(0);
  }

  if(fscanf(fa, "%d %d", &numRowsA, &numColsA) < 2) {
    fprintf(stderr, "error: input file for matrix A is formatted improperly.\n");
    exit(0);
  }
  if(fscanf(fb, "%d %d", &numRowsB, &numColsB) < 2) {
    fprintf(stderr, "error: input file for matrix B is formatted improperly.\n");
    exit(0);
  }

  // check if matrix multiplication is possible
  if(numColsA != numRowsB) {
    fprintf(stderr, "error: Matrix multiplication not possible with given matrices.\n");
    exit(0);
  }

  double *arrayA = (double *)malloc((numRowsA * numColsA) * sizeof(double));
  double *arrayB = (double *)malloc((numRowsB * numColsB) * sizeof(double));
  double *arrayC = (double *)malloc((numRowsA * numColsB) * sizeof(double));
  char line[100];
  int i = 0;
  int j = 0;

  while(fgets(line, 100, fa)) {
    if(sscanf(line, "%lf", &arrayA[i]) == 1){
      i++;
    }
  }
  if(i < numRowsA * numColsA){
    fprintf(stderr, "error: input file for matrix A formatted improperly.\n");
    exit(0);
  }

  while(fgets(line, 100, fb)){
    if(sscanf(line, "%lf", &arrayB[j]) == 1) {
      j++;
    }
  }
  if(j < numRowsB * numColsB){
    fprintf(stderr, "error: input file for matrix B formatted improperly.\n");
    exit(0);
  }
  fclose(fa);
  fclose(fb);

  struct matrix *matrixA = (struct matrix *)malloc(sizeof(struct matrix));
  struct matrix *matrixB = (struct matrix *)malloc(sizeof(struct matrix));
  struct matrix *matrixC = (struct matrix *)malloc(sizeof(struct matrix));
  matrixA->numRows = numRowsA;
  matrixA->numCols = numColsA;
  matrixA->data = arrayA;
  matrixB->numRows = numRowsB;
  matrixB->numCols = numColsB;
  matrixB->data = arrayB;
  matrixC->numRows = numRowsA;
  matrixC->numCols = numColsB;
  matrixC->data = arrayC;

  pthread_t *threads = (pthread_t *)malloc(sizeof(pthread_t)*numThreads);
  struct arg_struct *args;

  // make adjustment if too many threads are specified
  if(numThreads > numRowsA){
    numThreads = numRowsA;
  }
  // divide up the rows evenly amongst the threads and track the remainder
  int remainderRows = numRowsA % numThreads;
  int threadRows = (numRowsA - remainderRows)/numThreads;
  int index = 0;
  int matrixC_index = 0;
  int err;

  double timer = CTimer();

  fflush(stdout);
  for(int i = 0; i < numThreads; i++){
    args = (struct arg_struct *)malloc(sizeof(struct arg_struct));
    args->id = i;
    args->A = matrixA;
    args->B = matrixB;
    args->C = matrixC;
    args->index = index;
    args->matrixC_index = matrixC_index;

    // distribute the remainder rows amongst the first n threads
    if(i < remainderRows){
      args->rowsToCompute = threadRows + 1;
    }
    else{
      args->rowsToCompute = threadRows;
    }
    index += numColsA * args->rowsToCompute;
    matrixC_index += matrixC->numCols * args->rowsToCompute;
    err = pthread_create(&(threads[i]), NULL, matrixMultiply, (void *)args);
  }
  
  for(int i = 0; i < numThreads; i++){
    fflush(stdout);
    err = pthread_join(threads[i], (void **)&args);
  }

  double timePassed = CTimer() - timer;

  int it = 0;
  printf("%d %d\n", args->C->numRows, args->C->numCols);

  for(int i = 0; i < args->C->numRows * args->C->numCols; i++){
    if(i % args->C->numCols == 0){
      printf("# Row %d\n", it);
      it++;
    }
    printf("%lf\n", args->C->data[i]);
  }

  free(arrayA);
  free(arrayB);
  free(arrayC);
  free(matrixA);
  free(matrixB);
  free(matrixC);
  free(threads);
  free(args);

  printf("Elapsed time: %f\n", timePassed);

  return(0);
}