コード例 #1
0
   void task_pool::join()
   {
      for ( ; ; )
      {
         m_task_condition_var.lock();

         if (!m_tasks.empty())
         {
            task tsk(m_tasks.front());
            m_tasks.pop_front();

            m_task_condition_var.unlock();

            process_task(tsk);
         }
         else
         {
            int result = m_task_condition_var.wait(join_condition_func, this);
            result;
            CRNLIB_ASSERT(result >= 0);

            m_task_condition_var.unlock();

            break;
         }
      }
   }
コード例 #2
0
void AudioFileCopyConvert::dequeue_tasks()
{
	m_mutex.lock();
	if (m_tasks.size()) {
		CopyTask task = m_tasks.dequeue();
		m_mutex.unlock();
		process_task(task);
		return;
	}
	m_mutex.unlock();
}
コード例 #3
0
 void task_pool::join()
 {
    while (atomic_add32(&m_num_outstanding_tasks, 0) > 0)
    {
       task tsk;
       if (m_task_stack.pop(tsk))
       {
          process_task(tsk);
       }
       else
       {
          lzham_sleep(1);
       }
    }
 }
コード例 #4
0
    void task_pool::join()
    {
        // Try to steal any outstanding tasks. This could cause one or more worker threads to wake up and immediately go back to sleep, which is wasteful but should be harmless.
        task tsk;
        while (m_task_stack.pop(tsk))
            process_task(tsk);

        // At this point the task stack is empty.
        // Now wait for all concurrent tasks to complete. The m_all_tasks_completed semaphore has a max count of 1, so it's possible it could have saturated to 1 as the tasks
        // where issued and asynchronously completed, so this loop may iterate a few times.
        const int total_submitted_tasks = static_cast<int>(atomic_add32(&m_total_submitted_tasks, 0));
        while (m_total_completed_tasks != total_submitted_tasks)
        {
            // If the previous (m_total_completed_tasks != total_submitted_tasks) check failed the semaphore MUST be eventually signalled once the last task completes.
            // So I think this can actually be an INFINITE delay, but it shouldn't really matter if it's 1ms.
            m_all_tasks_completed.wait(1);
        }
    }
コード例 #5
0
void
execute_round(Scheduler& s) {
  // Execute the select
  s.select(s.timeout);

  // Build a priority queue of tasks.
  std::vector<Task*> q(s.tasks.size());
  for (auto x : s.tasks)
    q.push_back(x.second);
  std::make_heap(q.begin(), q.end(), Less);
  
  // Execute the run queue 
  while(not q.empty()) {
    Task* task = q.front();
    std::pop_heap(q.begin(), q.end());
    q.pop_back();
    process_task(s, task, now());
  }
}
コード例 #6
0
void CALifeMonsterBrain::update				()
{
#if 0//def DEBUG
	if (!Level().MapManager().HasMapLocation("debug_stalker",object().ID)) {
		CMapLocation				*map_location = 
			Level().MapManager().AddMapLocation(
				"debug_stalker",
				object().ID
			);

		map_location->SetHint		(object().name_replace());
	}
#endif

	select_task						();
	
	if (object().m_smart_terrain_id != 0xffff)
		process_task				();
	else
		default_behaviour			();

	movement().update				();
}
コード例 #7
0
ファイル: main.c プロジェクト: proxygin/beegfs-chunk-parity
int do_file(const char *key, size_t keylen, const FileInfo *fi)
{
    struct timespec tv1;
    clock_gettime(CLOCK_MONOTONIC, &tv1);

    int my_st = rank2st[mpi_rank];
    int P = GET_P(fi->locations);
    if (P == NO_P
            || P == rebuild_target
            || TEST_BIT(fi->locations, rebuild_target) == 0)
        return 0;

    hs.storage_target = my_st;
    hs.sample = &pr_sample;

    if (helper == my_st) {
        /* Send fi, key to rebuild_target so it knows whats up */
        MPI_Ssend((void*)fi, sizeof(FileInfo), MPI_BYTE, st2rank[rebuild_target], 0, MPI_COMM_WORLD);
        MPI_Ssend((void*)key, keylen, MPI_BYTE, st2rank[rebuild_target], 0, MPI_COMM_WORLD);
    }
    /* The rank that holds the P block needs read from parity in stead of
     * chunks, and the rebuild target has to write to chunks rather than
     * parity. If the rebuild target had the original P block, we don't want to
     * switch - we just want to recalculate it. */
    const char *load_pat = "         chunks";
    const char *save_pat = "         parity";
    if ((P != rebuild_target) && (P == my_st || rebuild_target == my_st)) {
        const char *tmp = load_pat;
        load_pat = save_pat;
        save_pat = tmp;
    }
    FileInfo mod_fi = *fi;
    if (P != rebuild_target) {
        mod_fi.locations |= (1 << P);
        mod_fi.locations &= ~(1 << rebuild_target);
        mod_fi.locations = WITH_P(mod_fi.locations, (uint64_t)rebuild_target);
    }
    TaskInfo ti = { load_pat, save_pat, (P != rebuild_target), P };
    int report = process_task(&hs, key, &mod_fi, ti);
#if 0
#define FIRST_8_BITS(x)     ((x) & 0x80 ? 1 : 0), ((x) & 0x40 ? 1 : 0), \
      ((x) & 0x20 ? 1 : 0), ((x) & 0x10 ? 1 : 0), ((x) & 0x08 ? 1 : 0), \
      ((x) & 0x04 ? 1 : 0), ((x) & 0x02 ? 1 : 0), ((x) & 0x01 ? 1 : 0) 
    int locs = mod_fi.locations & 0xFF;
    int cP = GET_P(mod_fi.locations);
    if (rank2st[mpi_rank] == rebuild_target)
    printf("process_task(%d, '%s', %d%d%d%d%d%d%d%d, op=%d, np=%d, '%s', '%s')\n", my_st, key, FIRST_8_BITS(locs), P, cP, load_pat, save_pat);
#endif

    struct timespec tv2;
    clock_gettime(CLOCK_MONOTONIC, &tv2);
    double dt = (tv2.tv_sec - tv1.tv_sec) * 1.0
        + (tv2.tv_nsec - tv1.tv_nsec) * 1e-9;
    if (report) {
        pr_sample.dt += dt;
        pr_sample.nfiles += 1;
    }
    if (pr_sample.dt >= 1.0) {
        pr_add_tmp_to_total(&pr_sample);
        pr_report_progress(&pr_sender, pr_sample);
        pr_clear_tmp(&pr_sample);
    }
    return 0;
}
コード例 #8
0
static void* task_worker( void* pArg )
{
  UTV_RESULT result;
  cJSON* task;
  cJSON* taskId;
  cJSON* output;
  UTV_BYTE* sessionId;

  sessionId = UtvMalloc( SESSION_ID_SIZE );
  UtvLiveSupportGetSessionId( sessionId, SESSION_ID_SIZE );

  while ( UtvLiveSupportIsSessionActive() )
  {
    result =
      UtvInternetDeviceWebServiceLiveSupportGetNextTask(
        sessionId,
        GET_NEXT_TASK_TIMEOUT_SECONDS,
        (void**)&task );

    if ( UTV_OK == result )
    {
      if ( task )
      {
        taskId = cJSON_GetObjectItem( task, "TASK_ID" );

        /*
         * If the taskId is -1 then the session has been terminated.
         */

        if ( -1 == taskId->valueint )
        {
          /*
           * This is an early exit so make sure we free up the task object.
           */

          cJSON_Delete( task );
          break;
        }
      
        UtvLiveSupportSetSessionState( UTV_LIVE_SUPPORT_SESSION_STATE_RUNNING );

        output = process_task( task );

        UtvInternetDeviceWebServiceLiveSupportCompleteTask(
          sessionId,
          taskId->valueint,
          output );

        cJSON_Delete( task );
      }
    }
    else
    {
      UtvMessage( UTV_LEVEL_ERROR,
                  "%s: Error occured getting next task, terminating task worker \"%s\"",
                  __FUNCTION__,
                  UtvGetMessageString( result ) );
      break;
    }
  }

  UtvFree( sessionId );

  s_taskWorkerThread = 0;

  /*
   * If the session is terminated by the Agent instead of the NetReady Services then the
   * session ID is already zero and there is no need to print anything or set the session
   * ID to zero.
   */

  if ( UtvLiveSupportIsSessionActive() )
  {
    /*
     * If the result from the get next task request is UTV_OK it means the session was
     * terminated from the NetReady Services and not internally initiated so pass FALSE to
     * the session shutdown processing.
     *
     * If the result from the get next task request is NOT UTV_OK it means an error occurred
     * within this processing and that the shutdown is being initiated internally so pass
     * TRUE to the session shutdown processing.
     */

    UtvLiveSupportSessionShutdown( ( result != UTV_OK ) );
  }

  UTV_THREAD_EXIT;
}