Example #1
0
/* backfill_agent - detached thread periodically attempts to backfill jobs */
extern void *backfill_agent(void *args)
{
	time_t now;
	double wait_time;
	static time_t last_backfill_time = 0;
	/* Read config and partitions; Write jobs and nodes */
	slurmctld_lock_t all_locks = {
		READ_LOCK, WRITE_LOCK, WRITE_LOCK, READ_LOCK };

	_load_config();
	last_backfill_time = time(NULL);
	while (!stop_backfill) {
		_my_sleep(backfill_interval);
		if (stop_backfill)
			break;
		if (config_flag) {
			config_flag = false;
			_load_config();
		}
		now = time(NULL);
		wait_time = difftime(now, last_backfill_time);
		if ((wait_time < backfill_interval) ||
		    _job_is_completing() || _many_pending_rpcs() ||
		    !avail_front_end(NULL) || !_more_work(last_backfill_time))
			continue;

		lock_slurmctld(all_locks);
		(void) _attempt_backfill();
		last_backfill_time = time(NULL);
		unlock_slurmctld(all_locks);
	}
	return NULL;
}
bool ZipPlatform::GetFileModTime(LPCTSTR lpFileName, time_t & ttime)
{
	WIN32_FIND_DATA findData = {0};
	HANDLE handle = ::FindFirstFile(CZipPathComponent::AddPrefix(lpFileName), &findData);
	if (handle == INVALID_HANDLE_VALUE)
	{
		ttime = time(NULL);
		return false;
	}
	bool ret = false;
    if ( findData.ftLastWriteTime.dwLowDateTime || findData.ftLastWriteTime.dwHighDateTime )
    {
		LONGLONG val = (findData.ftLastWriteTime.dwLowDateTime & 0xFFFFFFFF);

		val |= ((LONGLONG)findData.ftLastWriteTime.dwHighDateTime << 32) & SUFFIX_I64(0xFFFFFFFF00000000);
		val -= SUFFIX_I64(116444736000000000);

		ttime = (time_t)(val / 10000000);
		ret = ttime >= 0;
    }
	FindClose(handle);
	if (ret == false)
		ttime = time(NULL);	
	return ret;
}
Example #3
0
/* Returns 0, if the pid is still running, >0 if it was exited or <0 error code */
int wait_until_finished(pid_t pid, unsigned long deadline, int *status, int child)
{
    int res;
    time_t start, end;
    double elapsed;

    TRACE_ENTRY();

    time(&start);
    do {
        res = waitpid(pid, status, WNOHANG);
        if (res != 0) {
            if (res < 0) {
                res = -errno;
                PRINT_ERROR("Waitpid for pid %d (child %d) "
                            "failed: %d (%s)", pid, child,
                            errno, strerror(errno));
            }
            break;
        }
        sleep(0.1);
        time(&end);
        elapsed = difftime(end, start);
    } while (elapsed < deadline);

    TRACE_EXIT_RES(res);
    return res;
}
Example #4
0
unsigned long calculate_busy_wait_millisecond(void)
{
    unsigned long count = 2000000000;
    time_t start = time(NULL);
    while(--count);
    return (unsigned long) (2000000 / difftime(time(NULL), start));
}
Example #5
0
int checkHold(){
    int x0, y0, x1, y1;
    time_t start;
    time_t end;
    static int firstCall = 1;

    if (firstCall) {
        firstCall = 0;
        time(&start);
        get_cursor(&x0, &y0);
        return 0;
    }  

    sched_yield();
    get_cursor(&x1, &y1);
    
    if ( (abs(x0-x1)+abs(y0-y1)) > 3 ) {
        x0 = x1;
        y0 = y1;
        time(&start);
        return 0;
    }

    time(&end);
    printf("%lf\n", difftime(end, start) );

    if ( difftime(end, start) > 3 ) {
        time(&start);
        get_cursor(&x0, &y0);
        printf("I have got the cursor\n");
        return 1;
    }

    return 0;
}
Example #6
0
void WorldSession::SendQueryTimeResponse()
{
    WorldPacket data(SMSG_QUERY_TIME_RESPONSE, 4 + 4);
    data << uint32(time(NULL));
    data << uint32(sWorld.GetNextDailyQuestsResetTime() - time(NULL));
    SendPacket(&data);
}
Example #7
0
void
AssertEquals(int expected, int actual, char *message, ...)
{
   va_list args;
   char buf[256];

   va_start( args, message );
   memset(buf, 0, sizeof(buf));
   SDL_vsnprintf( buf, sizeof(buf), message, args );
   va_end( args );

   if(expected != actual) {
      AssertWithValues("AssertEquals", 0, buf, actual, expected, time(0));

      _testReturnValue = TEST_RESULT_FAILURE;
      _testAssertsFailed++;

      _BailOut();
      } else {
	   AssertWithValues("AssertEquals", 1, buf,
    		  actual, expected, time(0));

      _testAssertsPassed++;
   }
}
Example #8
0
int main(int argc, char *argv[])
{
   time_t starttime = time(NULL);
   /* Can't instantiate lwrf classes before pigpio is initialised. */
   if (gpioInitialise() >= 0)
   {
      std::string TX_TEST = "0001F15AC2";
      LwrfRX rx(RX, RX_REPEAT);
      LwrfTX tx(TX);
      
      tx.Put(TX_TEST, TX_REPEAT);

      do
      {
         if (rx.Ready() > 0)
         {
            std::cout << rx.Get() << std::endl;
         }
         else
         {
            //No messages, pause for 50msec breather
            usleep(50000);
         }
      } while ((time(NULL) - starttime) < 30);
      std::cout << "Rx debug " << rx.Debug() << std::endl;
      std::cout << "Tx debug " << tx.Debug() << std::endl;
   }
}
Example #9
0
unsigned char adc_read(unsigned char channel, float *value)
{
   unsigned long xdata d, start_time;
   unsigned char xdata i;

   /* start conversion */
   channel = adc_index[channel % (N_HV_CHN*2)];
   write_adc(REG_CONTROL, channel << 4 | 0x0F); // adc_chn, +2.56V range
   write_adc(REG_MODE, (1<<4) | (1<<1));        // single conversion, 10 channel mode

   start_time = time();

   while (ADC_NRDY) {
      yield();
      for (i=0 ; i<N_HV_CHN ; i++)
         ramp_hv(i);      // do ramping while reading ADC

      /* abort if no ADC ready after 300ms */
      if (time() - start_time > 30) {
         reset_adc();
         return 0;
      }
   }

   read_adc24(REG_ADCDATA, &d);

   /* convert to volts */
   *value = ((float)d / (1l<<24)) * 2.56;

   /* round result to 6 digits */
   *value = floor(*value*1E6+0.5)/1E6;

   return 1;
}
Example #10
0
void quit(){
     time_t begin, end;
    
    printf("______________________________\n");
    printf("|                            |\n");
    printf("|                            |\n");
    printf("|                            |\n");
    printf("|                            |\n");
    printf("|   ::::::::::::::::::::::   |\n");
    printf("|   ::                  ::   |\n");
    printf("|   :: CLOSING GAME.... ::   |\n");
    printf("|   ::                  ::   |\n");
    printf("|   ::::::::::::::::::::::   |\n");
    printf("|                            |\n");
    printf("|                            |\n");
    printf("|                            |\n");
    printf("|                            |\n");
    printf("::::::::::::::::::::::::::::::\n");
   
    time(&begin);
    while (1){
         time(&end);
         if (difftime(end, begin) >= 5){
            break;
            }
      }
}
Example #11
0
static int
efinet_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout)
{
	struct netif *nif = desc->io_netif;
	EFI_SIMPLE_NETWORK *net;
	EFI_STATUS status;
	UINTN bufsz;
	time_t t;
	char buf[2048];

	net = nif->nif_devdata;

	t = time(0);
	while ((time(0) - t) < timeout) {
		bufsz = sizeof(buf);
		status = net->Receive(net, 0, &bufsz, buf, 0, 0, 0);
		if (status == EFI_SUCCESS) {
			/*
			 * XXX EFI1.1 and the E1000 card trash our
			 * workspace if we do not do this silly copy.
			 * Either they are not respecting the len
			 * value or do not like the alignment.
			 */
			if (bufsz > len)
				bufsz = len;
			bcopy(buf, pkt, bufsz);
			return (bufsz);
		}
		if (status != EFI_NOT_READY)
			return (0);
	}

	return (0);
}
Example #12
0
/*! \brief Get symbol data.
 *  \par Function Description
 *  Get the unparsed gEDA-format data corresponding to a symbol from
 *  the symbol's data source.  The return value should be free()'d
 *  when no longer needed.
 *
 *  On failure, returns \b NULL (the error will be logged).
 *
 *  \param symbol Symbol to get data for.
 *  \return Allocated buffer containing symbol data.
 */
gchar *s_clib_symbol_get_data (const CLibSymbol *symbol)
{
  CacheEntry *cached;
  gchar *data;
  gpointer symptr;
  gint n;

  g_return_val_if_fail ((symbol != NULL), NULL);
  g_return_val_if_fail ((symbol->source != NULL), NULL);

  /* Trickery to bypass effects of const */
  symptr = (gpointer) symbol;

  /* First, try the cache. */
  cached = (CacheEntry*) g_hash_table_lookup (clib_symbol_cache, symptr);
  if (cached != NULL) {
    cached->accessed = time(NULL);
    return g_strdup(cached->data);
  }

  /* If the symbol wasn't found in the cache, get it directly. */
  switch (symbol->source->type)
    {
    case CLIB_DIR:
      data = get_data_directory (symbol);
      break;
    case CLIB_CMD:
      data = get_data_command (symbol);
      break;
    case CLIB_SCM:
      data = get_data_scm (symbol);
      break;
    default:
      g_critical("s_clib_symbol_get_data: source %1$p has bad source type %2$i\n",
                 symbol->source, (gint) symbol->source->type);
      return NULL;
    }

  if (data == NULL) return NULL;

  /* Cache the symbol data */
  cached = g_new (CacheEntry, 1);
  cached->ptr = (CLibSymbol *) symptr;
  cached->data = g_strdup (data);
  cached->accessed = time (NULL);
  g_hash_table_insert (clib_symbol_cache, symptr, cached);

  /* Clean out the cache if it's too full */
  n = g_hash_table_size (clib_symbol_cache);
  if (n > CLIB_MAX_SYMBOL_CACHE) {
    for ( ; n > CLIB_MIN_SYMBOL_CACHE; n--) {
      g_hash_table_foreach (clib_symbol_cache,
                            (GHFunc) cache_find_oldest,
                            &cached);
      g_hash_table_remove (clib_symbol_cache, cached->ptr);
    }
  }

  return data;
}
Example #13
0
DWORD WINAPI Avisos()
{
    time_t start,end;
    time (&start);

    while(1)
    {
        time(&end);
        if(((difftime (end,start))/60) >= 10)
        {
			SendNotice("Bem vindo ao GNS-WSv.");
			Sleep(5000);
			SendNotice("Estamos trabalhando para melhoria do servidor.");
			Sleep(5000);
			SendNotice("Faça sua doação para o servidor evoluir!");
			Sleep(5000);
			SendNotice("Nosso site é : www.gnomudos.com.br");
			Sleep(5000);
			SendNotice("Equipe: ADM LUAN,COTOCO,ISAQUE PROGRAMADOR: GNS MALEIRO.");
			Sleep(5000);
			SendNotice("Qualquer problema relate via site ou skype:htfulltop!");
			Sleep(5000);
			SendNotice("Servidor Gnomudos Wyd Server.");
			Sleep(5000);
			SendNotice("Nossa equipe agradece a sua preferencia Bom jogo!");
            time (&start);
        }
        Sleep(7000); // pausa pra n sobrecarregar cpu
    }
    return 0;
}
Example #14
0
int Application::Run(TestCases::TestCase p_testCase)
{
	m_Al_The_Croc = new MemoryAllocator(p_testCase.customAllocation);
	
	if(p_testCase.functionFlag == 1)
	{		
		unsigned int numberOfThreads = p_testCase.nrThreads;

		m_pool = m_Al_The_Croc->CreatePool<Particle>(p_testCase.pool.nrOfBlocks, p_testCase.alignment, numberOfThreads == 1 ? false : true);
		m_pool->init();

		srand (time(NULL));
		std::thread* thread = new std::thread[numberOfThreads];

		for(int i = 0; i < numberOfThreads; i++) {
			threadParam params;
			params.emissionRate = rand() % 10000 + 1000;
			params.freeBlocks = 0;
			params.runTime = p_testCase.pool.runTime;
			params.pool = m_pool;
			thread[i] = std::thread(PoolTest, params);
		}
		for(int i = 0; i < numberOfThreads; i++) {
			thread[i].join();
		}
	}
	else if(p_testCase.functionFlag == 2)
	{
		unsigned int numberOfThreads = p_testCase.nrThreads;

		m_stack = m_Al_The_Croc->CreateStack(TOTAL_SIZE, 4, numberOfThreads == 1 ? false : true); 
		srand (time(NULL));

		std::thread* thread = new std::thread[numberOfThreads];

		unsigned int* pixmap;
		if(p_testCase.customAllocation)
			pixmap = reinterpret_cast<unsigned int*>(m_stack->Push<unsigned int[WIDTH*HEIGHT]>());
		else
			pixmap = (unsigned int*)malloc(TOTAL_SIZE);	

		for(int i = 0; i < numberOfThreads; i++) 
		{
			threadParam params;
			params.al_the_croc = m_Al_The_Croc;
			params.stack = m_stack;
			params.customAllocation = p_testCase.customAllocation;
			params.id = i;
			params.pixmap = pixmap;
			thread[i] = std::thread(StackTest, params);
		}

		for(int i = 0; i < NUM_THREADS; i++) {
			thread[i].join();
		}
		//writeTga(pixmap, WIDTH, HEIGHT, "image.tga");
	}

	return (int)StopCode::CleanStop;
}
Example #15
0
 bool ValueUpdated() {
   int current_value = value;
   time_t start = time(NULL);
   while (current_value == value && (time(NULL) - start) < 5) {
   }
   return current_value != value;
 }
Example #16
0
static void smsbox_thread(void *arg)
{
    Connection *conn;
    Msg *msg;
    Octstr *os;
    Octstr *reply_msg;
    unsigned long count;
    
    msg = msg_create(sms);
    msg->sms.sender = octstr_create("123");
    msg->sms.receiver = octstr_create("456");
    msg->sms.msgdata = octstr_create("hello world");
    reply_msg = msg_pack(msg);
    msg_destroy(msg);

    gwthread_sleep(1.0);
    conn = conn_open_tcp(bearerbox_host, port_for_smsbox, NULL);
    if (conn == NULL) {
	gwthread_sleep(2.0);
	conn = conn_open_tcp(bearerbox_host, port_for_smsbox, NULL);
    	if (conn == NULL)
	    panic(0, "Couldn't connect to bearerbox as smsbox");
    }

    while (!quitting && conn_wait(conn, -1.0) != -1) {
    	for (;;) {
	    os = conn_read_withlen(conn);
	    if (os == NULL) {
		if (conn_eof(conn) || conn_error(conn))
		    goto error;
		break;
	    }
	    
	    msg = msg_unpack(os);
	    if (msg == NULL || msg->type == wdp_datagram)
		error(0, "Bearerbox sent garbage to smsbox");

	    if (msg->type == sms) {
		if (first_from_bb == (time_t) -1)
		    time(&first_from_bb);
		count = counter_increase(num_from_bearerbox) + 1;
		debug("test.smpp", 0, 
		      "Bearerbox sent sms #%ld <%s> to smsbox, sending reply.",
		      count, octstr_get_cstr(msg->sms.msgdata));
		if (count == max_to_esme)
		    info(0, "Bearerbox has sent all messages to smsbox.");
		conn_write_withlen(conn, reply_msg);
		counter_increase(num_to_bearerbox);
	    }
	    msg_destroy(msg);
	    octstr_destroy(os);
	    time(&last_to_bb);
	}
    }
    
error:
    conn_destroy(conn);
    octstr_destroy(reply_msg);
    debug("test.smpp", 0, "%s terminates.", __func__);
}
Example #17
0
TEST(time, timer_delete_from_timer_thread) {
  TimerDeleteData tdd;
  sigevent_t se;

  memset(&se, 0, sizeof(se));
  se.sigev_notify = SIGEV_THREAD;
  se.sigev_notify_function = TimerDeleteCallback;
  se.sigev_value.sival_ptr = &tdd;

  tdd.complete = false;
  ASSERT_EQ(0, timer_create(CLOCK_REALTIME, &se, &tdd.timer_id));

  itimerspec ts;
  ts.it_value.tv_sec = 1;
  ts.it_value.tv_nsec = 0;
  ts.it_interval.tv_sec = 0;
  ts.it_interval.tv_nsec = 0;
  ASSERT_EQ(0, timer_settime(tdd.timer_id, 0, &ts, NULL));

  time_t cur_time = time(NULL);
  while (!tdd.complete && (time(NULL) - cur_time) < 5);
  ASSERT_TRUE(tdd.complete);

#if defined(__BIONIC__)
  // Since bionic timers are implemented by creating a thread to handle the
  // callback, verify that the thread actually completes.
  cur_time = time(NULL);
  while (pthread_detach(tdd.thread_id) != ESRCH && (time(NULL) - cur_time) < 5);
  ASSERT_EQ(ESRCH, pthread_detach(tdd.thread_id));
#endif
}
Example #18
0
void wvtest_check(bool cond, const char *reason)
{
#ifndef _WIN32
    alarm(MAX_TEST_TIME); // restart per-test timeout
#endif
    if (!start_time) start_time = time(NULL);

    if (time(NULL) - start_time > MAX_TOTAL_TIME)
    {
	printf("\n! WvTest   Total run time exceeded %d seconds!  FAILED\n",
	       MAX_TOTAL_TIME);
	fflush(stdout);
	abort();
    }

    runs++;

    print_result_str(false, NULL, 0, NULL, cond ? "ok" : (reason ? reason : "FAILED"));

    if (!cond)
    {
	fails++;

	if (getenv("WVTEST_DIE_FAST"))
	    abort();
    }
}
Example #19
0
void *server_sync_master_handle_db_timer (void *arg)
{
  long timeout_val = 0;

  if (!mainp || mainp->db_fp <= 0) {
    LOG_SERVER_MESSAGE_TO_FILE ("ERROR", "Something very wrong here. Exiting thread.");
    pthread_exit (NULL);
  }

  /* Register for the signals */
  //signal_registration();

  LOG_SERVER_MESSAGE_TO_FILE ("INFO", "Thread to query DB every %d seconds.",
                              SERVER_MASTER_DB_QUERY_TIME);

  while (1) {
    timeout_val = time(0) + SERVER_MASTER_DB_QUERY_TIME;
    while (time (0) < timeout_val);
    if (server_sync_master_query_db() != F_SUCCESS){
      LOG_SERVER_MESSAGE_TO_FILE ("ERROR", "Stopping synchronization.");
    }
  }

  pthread_exit (NULL);
}
Example #20
0
/*----------------------------------------------------------------------
  hbInkey
  ----------------------------------------------------------------------*/
int hbInkey(int Tijdsduur)
{

  int Toets;
  time_t BeginTijd=0;
  char HuidigeTijd[9];

  Tijdsduur++;   /* WEGHALEN !!!!! alleen om warning te vermijden. */
  /* BeginTijd=time(NULL); */

  for(;;) {
	 /* Doe van alles en nog wat. */
	 /* Kijk of er een muistoets is ingedrukt etc. */
	 if ((time(NULL)-BeginTijd) >= 1) {
		_strtime(HuidigeTijd);
		hbPrint(TijdY,TijdX,HuidigeTijd,Kleur);
		BeginTijd=time(NULL);
	 }

	 if (bioskey(1)>0) {
		Toets=bioskey(0);
		Toets=((Toets & 0xff)==0 ? -(Toets>>8) : (Toets & 0xff));

		if (Toets==K_F1)
		  Help();
		else
		  break;
	 }
  }
Example #21
0
int main() {
    
    srand(time(0));
    
    // A couple testing arrays.
    int* arr1 = makeRandSortArray(SIZE);
    int* arr2 = makeRandSortArray(SIZE);
    
    // Set to whatever value you want to search for (as the sum of one
    // element in each array.
    int total = 3;
    
    /* Note: In order to accurately time the other two, you need to run them
             many times (say 100) and divide the total time by how many times
             you ran them.
    */
    
    int start1 = time(0);
    int ansbf = arraySumBF(arr1,SIZE,arr2,SIZE,total);
    int start2 = time(0);
    int ansbs = arraySumBinSearch(arr1,SIZE,arr2,SIZE,total);
    int start3 = time(0);
    int anslin = arraySumLinear(arr1,SIZE,arr2,SIZE,total);
    int end = time(0);
        
    printf("Brute force took %d seconds.\n", start2 - start1);
    printf("Bin search took %d seconds.\n", start3 - start2);
    printf("Linear took %d seconds.\n", end - start3);

    free(arr1);
    free(arr2);
    
    system("PAUSE");
    return 0;
}
Example #22
0
time_t GetCurrentStringTime(std::string& timeStr, int iIndex=0)
	{
		std::string tmpStr;
		char buf[32] = {0};

#ifdef _WIN32
		time_t t;
		tm *tp;
		t = time(NULL);
		tp = localtime(&t);
		sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", 
			tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday
			,tp->tm_hour, tp->tm_min, 
			(tp->tm_sec - iIndex > 0) ? tp->tm_sec - iIndex: 0);

		timeStr = buf;
		return t - iIndex;
#else
		time_t now;
		time(&now);
		now = now - iIndex;
		struct tm timenow;
		localtime_r(&now, &timenow);
		strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &timenow);
		timeStr = buf;
		return now;
#endif
	}
/**
 * Creates a Authorization Session.
 */
AAASession* AAACreateAuthSession(void *generic_data,int is_client,int is_statefull,AAASessionCallback_f *cb,void *param)
{
	AAASession *s;
	str id;
	cdp_session_type_t type;
	
	generate_session_id(&id,0);
	
	if (is_client){
		if (is_statefull) type = AUTH_CLIENT_STATEFULL;
		else type = AUTH_CLIENT_STATELESS;
	}else{
		if (is_statefull) type = AUTH_SERVER_STATEFULL;
		else type = AUTH_SERVER_STATELESS;		
	}
	s = new_session(id,type);
	if (s) {
		s->u.auth.generic_data = generic_data;
		s->cb = cb;
		s->cb_param = param;
		s->u.auth.timeout=time(0)+config->tc*30; 
		s->u.auth.lifetime=time(0)+config->tc*32;
		s->u.auth.grace_period=config->tc*2;
		LOG(L_DBG,"id is %.*s",s->id.len,s->id.s);
		LOG(L_DBG,"hash is %u",s->hash);
		add_session(s);
	}
	return s;
}
Example #24
0
int set_cn_to_cache(const char *host, int port, const char *cn, int index) {
  if(cn == NULL || strlen(cn) <= 0) return;
  int i_int = -1;
  if(index >= -1 && index < CN_CACHE_SIZE) {
    i_int = index; 
  } else {
    int hit = 2^sizeof(int) - 1;
    int hit_index = 0;

    for(i_int = 0; i_int < CN_CACHE_SIZE; i_int++) {
      if(cn_cache[i_int].ip == NULL || (time(NULL) - cn_cache[i_int].updated_on) > ONE_MONTH) {
        if(cn_cache[i_int].hit_count < hit) {
          hit_index = i_int;
          hit = cn_cache[i_int].hit_count;
        }
        break;
      }
    } 

    if(i_int == CN_CACHE_SIZE) i_int = hit_index;
  }

  printf("  In thread %ld setting cn in cache for %s:%d...\n", pthread_self(), host, port);
  strcpy(cn_cache[i_int].ip, host);
  cn_cache[i_int].port = port;
  strcpy(cn_cache[i_int].cn, cn);
  cn_cache[i_int].updated_on = time(NULL);
}
void CEntityAntiAddictonComponent::OnEvent(CComponentEvent& refEvent)
{
	if (!m_bActive)
	{
		return;
	}
	if (refEvent.nID == eComponentEvent_AntiAddiction)
	{
		unsigned int nNowTime = (unsigned int)time(NULL);
		unsigned short nOnlineTime = *(unsigned short*)(refEvent.m_pData);
		CreateNextTimer(nNowTime, nOnlineTime*60);
	}
	else if (refEvent.nID == eComponentEvent_AntiAddictionTip)
	{
		if (m_pCurConfigItem != NULL)
		{
			SendTipMsg(m_pCurConfigItem->tipText);
		}
		unsigned int nNowTime = (unsigned int)time(NULL);
		if (m_nTipCount > 0)
		{
			CreateNextTipTimer(nNowTime);
			--m_nTipCount;
		}
	}
}
Example #26
0
void Field::setOpen(int x, int y){
  if(minesPlaced == false){
    startTime = time(nullptr);
    placeMines(x, y);
    minesPlaced = true;
  }
  int index = y * width + x;
  if(field[index].isOpen == false){
    openTiles++;
  }
  field[index].isOpen = true;
  if(field[index].isMine){
    minesOpened = true;
    endTime = time(nullptr);
    endTimeSet = true;
    for(int i = 0; i < height * width; i++){
      if(field[i].isMine){
        field[i].isOpen = true;
      }
    }
  }
  if(isMine(x,y) == false && getSurroundingMines(x, y) == 0){
    flushSurrounding(x, y);
  }
  if(onlyMinesLeft()){
    endTime = time(nullptr);
    endTimeSet = true;
    for(int i = 0; i < height * width; i++){
      if(field[i].isMine){
        field[i].isFlagged = true;
      }
    }
  }
}
Example #27
0
void handle_alarm(void) {
  int new_timeout = 0;

  /* We need to adjust for any time that might be remaining on the alarm,
   * in case we were called in order to change alarm durations.  Note
   * that rapid-fire calling of this function will probably screw
   * up the already poor resolution of alarm() _horribly_.  Oh well,
   * this shouldn't be used for any precise work anyway, it's only
   * for modules to perform approximate timing.
   */

  /* It's possible that alarms are blocked when this function is
   * called, if so, increment alarm_pending and exit swiftly
   */
  while (nalarms) {
    nalarms = 0;

    if (!alarms_blocked) {
      int alarm_elapsed;

      alarm(0);
      alarm_elapsed = _alarmed_time ? (int) time(NULL) - _alarmed_time : 0;
      new_timeout = _total_time + alarm_elapsed;
      _total_time = 0;
      new_timeout = process_timers(new_timeout);

      _alarmed_time = time(NULL);
      alarm(_current_timeout = new_timeout);

    } else {
      alarm_pending++;
    }
  }
}
Example #28
0
void trafcountfunc(struct clientparam *param){
	struct trafcount * tc;
	int countout = 0;

	pthread_mutex_lock(&tc_mutex);
	for(tc = conf.trafcounter; tc; tc = tc->next) {
		if(ACLmatches(tc->ace, param)){
			time_t t;
			if(tc->ace->action == NOCOUNTIN) break;
			if(tc->ace->action != COUNTIN) {
				countout = 1;
				continue;
			}
			tc->traf64 += param->statssrv64;
			time(&t);
			tc->updated = t;
		}
	}
	if(countout) for(tc = conf.trafcounter; tc; tc = tc->next) {
		if(ACLmatches(tc->ace, param)){
			time_t t;
			if(tc->ace->action == NOCOUNTOUT) break;
			if(tc->ace->action != COUNTOUT) {
				continue;
			}
			tc->traf64 += param->statscli64;
			time(&t);
			tc->updated = t;
		}
	}

	pthread_mutex_unlock(&tc_mutex);
}
Example #29
0
File: post.c Project: gerow/hnfs
/*
 * the calling thread should have a lock on the collection before
 * calling this function
 */
int hnfs_post_fetch_content(hnfs_post_t *post)
{
  if ((time(NULL) - post->content_update_time) < HNFS_TIME_BETWEEN_UPDATES) {
    fprintf(stderr, "Content fresh. Skipping update.\n");
    return 0;
  }

  /* if content is allocated free it */
  if (post->content) {
    free(post->content);
  }

  curl_saver_t saver = {
    .data = NULL,
    .size = 0
  };
  CURLcode res = fetch_url(post->url, &saver);
  if (res != CURLE_OK) {
    fprintf(stderr,
            "Failed to fetch url %s: %s\n",
            post->url,
            curl_easy_strerror(res));
    return res;
  }
  post->content = saver.data;
  post->content_update_time = time(NULL);

  return 0;
}
Example #30
0
/* builtin_agent - detached thread periodically when pending jobs can start */
extern void *builtin_agent(void *args)
{
	time_t now;
	double wait_time;
	static time_t last_sched_time = 0;
	/* Read config, nodes and partitions; Write jobs */
	slurmctld_lock_t all_locks = {
		READ_LOCK, WRITE_LOCK, READ_LOCK, READ_LOCK, READ_LOCK };

	_load_config();
	last_sched_time = time(NULL);
	while (!stop_builtin) {
		_my_sleep(builtin_interval);
		if (stop_builtin)
			break;
		if (config_flag) {
			config_flag = false;
			_load_config();
		}
		now = time(NULL);
		wait_time = difftime(now, last_sched_time);
		if ((wait_time < builtin_interval))
			continue;

		lock_slurmctld(all_locks);
		_compute_start_times();
		last_sched_time = time(NULL);
		(void) bb_g_job_try_stage_in();
		unlock_slurmctld(all_locks);
	}
	return NULL;
}