Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from panda3d:master #169

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions panda/src/event/asyncTaskChain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,9 @@ AsyncTaskChainThread(const string &name, AsyncTaskChain *chain) :
void AsyncTaskChain::AsyncTaskChainThread::
thread_main() {
#ifdef HAVE_THREADS
// Let PStats know this thread exists.
PStatClient::thread_tick();

MutexHolder holder(_chain->_manager->_lock);
while (_chain->_state != S_shutdown && _chain->_state != S_interrupted) {
thread_consider_yield();
Expand Down
35 changes: 17 additions & 18 deletions panda/src/express/trueClock.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ TrueClock() {
#include <stdio.h> // for perror

static long _init_sec;
static time_t _init_sec_monotonic = 0;

/**
*
Expand Down Expand Up @@ -553,25 +554,13 @@ get_long_time() {
*/
double TrueClock::
get_short_raw_time() {
struct timeval tv;

int result;

#ifdef GETTIMEOFDAY_ONE_PARAM
result = gettimeofday(&tv);
#else
result = gettimeofday(&tv, nullptr);
#endif

if (result < 0) {
// Error in gettimeofday().
return 0.0;
#if defined(CLOCK_MONOTONIC) && !defined(__APPLE__)
struct timespec spec;
if (clock_gettime(CLOCK_MONOTONIC, &spec) == 0) {
return (double)(spec.tv_sec - _init_sec_monotonic) + (double)spec.tv_nsec / 1000000000.0;
}

// We subtract out the time at which the clock was initialized, because we
// don't care about the number of seconds all the way back to 1970, and we
// want to leave the double with as much precision as it can get.
return (double)(tv.tv_sec - _init_sec) + (double)tv.tv_usec / 1000000.0;
#endif
return get_long_time();
}

/**
Expand Down Expand Up @@ -603,6 +592,16 @@ TrueClock() {
} else {
_init_sec = tv.tv_sec;
}

#if defined(CLOCK_MONOTONIC) && !defined(__APPLE__)
struct timespec spec;
if (clock_gettime(CLOCK_MONOTONIC, &spec) == 0) {
_init_sec_monotonic = spec.tv_sec;
} else {
perror("clock_gettime(CLOCK_MONOTONIC)");
_init_sec_monotonic = 0;
}
#endif
}

#endif
25 changes: 10 additions & 15 deletions panda/src/pstatclient/pStatClientImpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,9 @@ client_connect(std::string hostname, int port) {
int thread_index = current_thread->get_pstats_index();
if (thread_index >= 0) {
PStatClient *client = PStatClient::get_global_pstats();
double start = client->get_real_time();
client->start(_wait_sleep_pcollector.get_index(), thread_index);
ThreadImpl::sleep(seconds);
double stop = client->get_real_time();
client->start_stop(_wait_sleep_pcollector.get_index(), thread_index, start, stop);
client->stop(_wait_sleep_pcollector.get_index(), thread_index);
client->add_level(_cswitch_sleep_pcollector.get_index(), thread_index, 1);
}
else {
Expand All @@ -171,10 +170,9 @@ client_connect(std::string hostname, int port) {
int thread_index = current_thread->get_pstats_index();
if (thread_index >= 0) {
PStatClient *client = PStatClient::get_global_pstats();
double start = client->get_real_time();
client->start(_wait_yield_pcollector.get_index(), thread_index);
ThreadImpl::yield();
double stop = client->get_real_time();
client->start_stop(_wait_yield_pcollector.get_index(), thread_index, start, stop);
client->stop(_wait_yield_pcollector.get_index(), thread_index);
client->add_level(_cswitch_yield_pcollector.get_index(), thread_index, 1);
}
else {
Expand All @@ -190,10 +188,9 @@ client_connect(std::string hostname, int port) {
BOOL result;
if (thread_index >= 0) {
PStatClient *client = PStatClient::get_global_pstats();
double start = client->get_real_time();
client->start(_wait_cvar_pcollector.get_index(), thread_index);
result = SleepConditionVariableSRW(cvar, lock, time, flags);
double stop = client->get_real_time();
client->start_stop(_wait_cvar_pcollector.get_index(), thread_index, start, stop);
client->stop(_wait_cvar_pcollector.get_index(), thread_index);
client->add_level(_cswitch_cvar_pcollector.get_index(), thread_index, 1);
}
else {
Expand All @@ -211,10 +208,9 @@ client_connect(std::string hostname, int port) {
int result;
if (thread_index >= 0) {
PStatClient *client = PStatClient::get_global_pstats();
double start = client->get_real_time();
client->start(_wait_cvar_pcollector.get_index(), thread_index);
result = pthread_cond_wait(cvar, lock);
double stop = client->get_real_time();
client->start_stop(_wait_cvar_pcollector.get_index(), thread_index, start, stop);
client->stop(_wait_cvar_pcollector.get_index(), thread_index);
client->add_level(_cswitch_cvar_pcollector.get_index(), thread_index, 1);
}
else {
Expand All @@ -231,10 +227,9 @@ client_connect(std::string hostname, int port) {
int result;
if (thread_index >= 0) {
PStatClient *client = PStatClient::get_global_pstats();
double start = client->get_real_time();
client->start(_wait_cvar_pcollector.get_index(), thread_index);
result = pthread_cond_timedwait(cvar, lock, ts);
double stop = client->get_real_time();
client->start_stop(_wait_cvar_pcollector.get_index(), thread_index, start, stop);
client->stop(_wait_cvar_pcollector.get_index(), thread_index);
client->add_level(_cswitch_cvar_pcollector.get_index(), thread_index, 1);
}
else {
Expand Down
Loading