working on timing on linux

This commit is contained in:
Cameron Tacklind 2022-08-28 07:55:15 -07:00
parent 597127c7f3
commit 20fe80e657
6 changed files with 47 additions and 13 deletions

View File

@ -146,10 +146,10 @@ CompilerFlags_wasm+=" -Wl,--no-entry" #
CompilerFlags_wasm+=" -Wl,--allow-undefined" # CompilerFlags_wasm+=" -Wl,--allow-undefined" #
CompilerFlags_wasm+=" -Wl,--export-all" # CompilerFlags_wasm+=" -Wl,--export-all" #
CompilerFlags_linux="" CompilerFlags_linux=" -pthread"
CompilerFlags_raspi="" # "--target=arm-rpi-linux-gnueabihf" # "--target=arm-linux-gnueabihf" #target CompilerFlags_raspi=" -pthread" # "--target=arm-rpi-linux-gnueabihf" # "--target=arm-linux-gnueabihf" #target
CompilerFlags_raspi+="-lm" # link with local system math libraries CompilerFlags_raspi+=" -lm" # link with local system math libraries
CompilerFlags_DEBUG_win32="" CompilerFlags_DEBUG_win32=""

View File

@ -57,7 +57,7 @@ os_file_open(String path, File_Access_Flags flags_access, File_Create_Flags fla
invalid_default_case; invalid_default_case;
} }
s32 file_handle = open((char*)path.str, flags); s32 file_handle = open((char*)path.str, flags, mode);
if (file_handle >= 0) if (file_handle >= 0)
{ {
result = open_files_put_handle(file_handle, path); result = open_files_put_handle(file_handle, path);

View File

@ -98,9 +98,11 @@ void
os_thread_end(Thread_Handle thread_handle) os_thread_end(Thread_Handle thread_handle)
{ {
Os_Osx_Thread* t = osx_threads_ + thread_handle.value; Os_Osx_Thread* t = osx_threads_ + thread_handle.value;
pthread_kill(t->thread, 0); //pthread_kill(t->thread, 0);
} }
#if defined(PLATFORM_osx)
u32 u32
os_interlocked_increment(volatile u32* value) os_interlocked_increment(volatile u32* value)
{ {
@ -117,4 +119,24 @@ os_interlocked_cmp_exchg(volatile u32* dest, u32 old_value, u32 new_value)
return result; return result;
} }
#else
u32
os_interlocked_increment(volatile u32* value)
{
*value += 1;
return *value;
}
bool
os_interlocked_cmp_exchg(volatile u32* dest, u32 old_value, u32 new_value)
{
assert(*dest <= s32_max);
if (*dest == old_value) {
*dest = new_value;
return true;
}
return false;
}
#endif
#endif //LUMENARIUM_OSX_THREAD_H #endif //LUMENARIUM_OSX_THREAD_H

View File

@ -24,6 +24,8 @@
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <pthread.h>
#define linux_err_print(sub_proc) linux_err_print_((char*)__FUNCTION__, (char*)(sub_proc), errno) #define linux_err_print(sub_proc) linux_err_print_((char*)__FUNCTION__, (char*)(sub_proc), errno)
void void
linux_err_print_(char* proc, char* sub_proc, s32 errsv) linux_err_print_(char* proc, char* sub_proc, s32 errsv)
@ -42,6 +44,7 @@ linux_err_print_(char* proc, char* sub_proc, s32 errsv)
#include "../linux/lumenarium_linux_file.h" #include "../linux/lumenarium_linux_file.h"
#include "../linux/lumenarium_linux_time.h" #include "../linux/lumenarium_linux_time.h"
#include "../osx/lumenarium_osx_network.h" #include "../osx/lumenarium_osx_network.h"
#include "../osx/lumenarium_osx_thread.h"
int main (int arg_count, char** args) int main (int arg_count, char** args)
@ -51,6 +54,11 @@ int main (int arg_count, char** args)
}; };
App_State* state = lumenarium_init(&ed_desc); App_State* state = lumenarium_init(&ed_desc);
time_t t = time(NULL);
struct tm* lt = localtime(&t);
// lt.tm_sec, tm_min, tm_hour, tm_mday, etc.
printf("Local Time: %s\n", asctime(lt));
bool running = true; bool running = true;
Ticks ticks_start = os_get_ticks(); Ticks ticks_start = os_get_ticks();
while (has_flag(state->flags, AppState_IsRunning)) while (has_flag(state->flags, AppState_IsRunning))
@ -61,14 +69,18 @@ int main (int arg_count, char** args)
lumenarium_env_validate(); lumenarium_env_validate();
Ticks ticks_end = os_get_ticks(); Ticks ticks_end = os_get_ticks();
r64 seconds_elapsed = get_seconds_elapsed(ticks_start, ticks_end, os_get_ticks_per_second()); usleep((1.f / 30.f) * 1000000);
while (seconds_elapsed < state->target_seconds_per_frame)
{ // r64 seconds_elapsed = (r64)(ticks_end.value - ticks_start.value) / (r64)1e+9;
u32 sleep_time = (u32)(1000.0f * (state->target_seconds_per_frame - seconds_elapsed)); // //get_seconds_elapsed(ticks_start, ticks_end, os_get_ticks_per_second());
usleep(sleep_time); // while (seconds_elapsed < state->target_seconds_per_frame)
ticks_end = os_get_ticks(); // {
seconds_elapsed = get_seconds_elapsed(ticks_start, ticks_end, os_get_ticks_per_second()); // printf("Sleeping\n");
} // u32 sleep_time = (u32)(1000000.0f * (state->target_seconds_per_frame - seconds_elapsed));
// ticks_end = os_get_ticks();
// seconds_elapsed = (r64)(ticks_end.value - ticks_start.value) / (r64)1e+9; //get_seconds_elapsed(ticks_start, ticks_end, os_get_ticks_per_second());
// }
ticks_start = ticks_end; ticks_start = ticks_end;
} }