Exemple #1
0
uint32_t __hw_clock_event_get(void)
{
	/* At what time will the next event fire? */
	uint32_t time_now_in_ticks;
	time_now_in_ticks = (0xffffffff - GR_TIMEHS_VALUE(0, 1));
	return ticks_to_usecs(time_now_in_ticks + GR_TIMEHS_VALUE(0, 2));
}
Exemple #2
0
int
callout_reset(struct callout *c, int ticks, void (*func)(void *), void *arg)
{
    int canceled = callout_stop(c);

    MutexLocker locker(sLock);

    c->c_func = func;
    c->c_arg = arg;

    TRACE("callout_reset %p, func %p, arg %p\n", c, c->c_func, c->c_arg);

    if (ticks >= 0) {
        // reschedule or add this timer
        if (c->due <= 0)
            list_add_item(&sTimers, c);

        c->due = system_time() + ticks_to_usecs(ticks);

        // notify timer about the change if necessary
        if (sTimeout > c->due)
            release_sem(sWaitSem);
    }

    return canceled;
}
Exemple #3
0
uint32_t __hw_clock_source_read(void)
{
	/*
	 * Return the current time in usecs. Since the counter counts down,
	 * we have to invert the value.
	 */
	return ticks_to_usecs(0xffffffff - GR_TIMEHS_VALUE(0, 1));
}
Exemple #4
0
int
conditionTimedWait(struct cv* variable, const int timeout)
{
	status_t status = variable->condition.Wait(B_RELATIVE_TIMEOUT,
		ticks_to_usecs(timeout));

	if (status != B_OK)
		status = EWOULDBLOCK;
	return status;
}
Exemple #5
0
int
publishedConditionTimedWait(const void* waitChannel, const int timeout)
{
	ConditionVariableEntry variableEntry;

	status_t status = variableEntry.Wait(waitChannel, B_RELATIVE_TIMEOUT,
		ticks_to_usecs(timeout));

	if (status != B_OK)
		status = EWOULDBLOCK;
	return status;
}
Exemple #6
0
QueryData genCpuTime(QueryContext& context) {
  QueryData results;

  natural_t processor_count;
  processor_cpu_load_info_data_t* processor_times;
  mach_port_t host = mach_host_self();
  mach_msg_type_number_t processor_msg_count;

  kern_return_t ret =
      host_processor_info(host,
                          PROCESSOR_CPU_LOAD_INFO,
                          &processor_count,
                          reinterpret_cast<processor_info_t*>(&processor_times),
                          &processor_msg_count);

  if (ret == KERN_SUCCESS) {
    // Loop through the cores and add rows for each core.
    for (unsigned int core = 0; core < processor_count; core++) {
      Row r;
      r["core"] = INTEGER(core);
      r["user"] = BIGINT(
          ticks_to_usecs(processor_times[core].cpu_ticks[CPU_STATE_USER]));
      r["idle"] = BIGINT(
          ticks_to_usecs(processor_times[core].cpu_ticks[CPU_STATE_IDLE]));
      r["system"] = BIGINT(
          ticks_to_usecs(processor_times[core].cpu_ticks[CPU_STATE_SYSTEM]));
      r["nice"] = BIGINT(
          ticks_to_usecs(processor_times[core].cpu_ticks[CPU_STATE_NICE]));

      results.push_back(r);
    }
    vm_deallocate(
        mach_task_self(),
        reinterpret_cast<vm_address_t>(processor_times),
        static_cast<vm_size_t>(processor_count * sizeof(*processor_times)));
  }
  return results;
}
Exemple #7
0
void PlayVolumeSound(
        short whichSoundID, uint8_t amplitude, short persistence, soundPriorityType priority) {
    int32_t oldestSoundTime = -ticks_to_usecs(kLongPersistence), whichChannel = -1;
    // TODO(sfiera): don't play sound at all if the game is muted.
    if (amplitude > 0) {
        int timeDif = VideoDriver::driver()->usecs() - globals()->gLastSoundTime;
        for (int count = 0; count < kMaxChannelNum; count++) {
            globals()->gChannel[count].soundAge += timeDif;
        }

        // if not see if there's another channel with the same sound at same or lower volume
        int count = 0;
        if (priority > kVeryLowPrioritySound) {
            while ((count < kMaxChannelNum) && (whichChannel == -1)) {
                if ((globals()->gChannel[count].whichSound == whichSoundID) &&
                    (globals()->gChannel[count].soundVolume <= amplitude)) {
                    whichChannel = count;
                }
                count++;
            }
        }

        // if not see if there's another channel at lower volume
        if (whichChannel == -1) {
            count = 0;
            while ((count < kMaxChannelNum) && (whichChannel == -1)) {
                if (globals()->gChannel[count].soundVolume < amplitude) {
                    whichChannel = count;
                }
                count++;
            }
        }

        // if not see if there's another channel at lower priority
        if (whichChannel == -1) {
            count = 0;
            while ((count < kMaxChannelNum) && (whichChannel == -1)) {
                if (globals()->gChannel[count].soundPriority < priority) {
                    whichChannel = count;
                }
                count++;
            }
        }

        // if not, take the oldest sound if past minimum persistence
        if (whichChannel == -1) {
            count = 0;
            while (count < kMaxChannelNum) {
                if ((globals()->gChannel[count].soundAge > 0)
                        && (globals()->gChannel[count].soundAge > oldestSoundTime)) {
                    oldestSoundTime = globals()->gChannel[count].soundAge;
                    whichChannel = count;
                }
                count++;
            }
        }

        // we're not checking for importance

        globals()->gLastSoundTime = VideoDriver::driver()->usecs();

        int whichSound = 0;
        while ((globals()->gSound[whichSound].id != whichSoundID) && (whichSound < kSoundNum)) {
            whichSound++;
        }
        if (whichSound == kSoundNum) {
            whichChannel = -1;
        }

        if (whichChannel >= 0) {
            globals()->gChannel[whichChannel].whichSound = whichSoundID;
            globals()->gChannel[whichChannel].soundAge = -ticks_to_usecs(persistence);
            globals()->gChannel[whichChannel].soundPriority = priority;
            globals()->gChannel[whichChannel].soundVolume = amplitude;

            globals()->gChannel[whichChannel].channelPtr->quiet();

            globals()->gChannel[whichChannel].channelPtr->amp(amplitude);
            globals()->gChannel[whichChannel].channelPtr->activate();
            globals()->gSound[whichSound].soundHandle->play();
        }
    }
}
 int64_t usecs() const { return ticks_to_usecs(_ticks); }