mirror of
https://github.com/Karaka-Management/cOMS.git
synced 2026-01-11 11:18:40 +00:00
tried to implement network logging. app completely broken. probably threading issue.
This commit is contained in:
parent
4b70891c88
commit
87f29a8310
|
|
@ -14,6 +14,8 @@ global_persist DebugContainer* debug_container = NULL;
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include "../platform/win32/threading/Atomic.h"
|
||||||
|
#include "../platform/win32/threading/Spinlock.cpp"
|
||||||
void setup_performance_count() {
|
void setup_performance_count() {
|
||||||
if (!debug_container) {
|
if (!debug_container) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -24,6 +26,8 @@ global_persist DebugContainer* debug_container = NULL;
|
||||||
debug_container->performance_count_frequency = perf_counter.QuadPart;
|
debug_container->performance_count_frequency = perf_counter.QuadPart;
|
||||||
}
|
}
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
|
#include "../platform/linux/threading/Atomic.h"
|
||||||
|
#include "../platform/linux/threading/Spinlock.cpp"
|
||||||
void setup_performance_count() {
|
void setup_performance_count() {
|
||||||
if (!debug_container) {
|
if (!debug_container) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -98,9 +102,7 @@ void update_timing_stat(uint32 stat, const char* function)
|
||||||
inline
|
inline
|
||||||
void update_timing_stat_start(uint32 stat, const char*)
|
void update_timing_stat_start(uint32 stat, const char*)
|
||||||
{
|
{
|
||||||
spinlock_start(&debug_container->perf_stats_spinlock);
|
atomic_set((int64 *) &debug_container->perf_stats[stat].old_tick_count, __rdtsc());
|
||||||
debug_container->perf_stats[stat].old_tick_count = __rdtsc();
|
|
||||||
spinlock_end(&debug_container->perf_stats_spinlock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
|
@ -134,33 +136,25 @@ void update_timing_stat_end_continued(uint32 stat, const char* function)
|
||||||
inline
|
inline
|
||||||
void update_timing_stat_reset(uint32 stat)
|
void update_timing_stat_reset(uint32 stat)
|
||||||
{
|
{
|
||||||
spinlock_start(&debug_container->perf_stats_spinlock);
|
atomic_set((int32 *) debug_container->perf_stats[stat].function, 0);
|
||||||
debug_container->perf_stats[stat].function = NULL;
|
|
||||||
spinlock_end(&debug_container->perf_stats_spinlock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
void reset_counter(int32 id)
|
void reset_counter(int32 id)
|
||||||
{
|
{
|
||||||
spinlock_start(&debug_container->perf_stats_spinlock);
|
atomic_set(&debug_container->counter[id], 0);
|
||||||
debug_container->counter[id] = 0;
|
|
||||||
spinlock_end(&debug_container->perf_stats_spinlock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
void log_increment(int32 id, int32 by = 1)
|
void log_increment(int32 id, int32 by = 1)
|
||||||
{
|
{
|
||||||
spinlock_start(&debug_container->perf_stats_spinlock);
|
atomic_add(&debug_container->counter[id], by);
|
||||||
debug_container->counter[id] += by;
|
|
||||||
spinlock_end(&debug_container->perf_stats_spinlock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
void log_counter(int32 id, int32 value)
|
void log_counter(int32 id, int32 value)
|
||||||
{
|
{
|
||||||
spinlock_start(&debug_container->perf_stats_spinlock);
|
atomic_set(&debug_container->counter[id], value);
|
||||||
debug_container->counter[id] = value;
|
|
||||||
spinlock_end(&debug_container->perf_stats_spinlock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo don't use a pointer to this should be in a global together with other logging data (see Log.h)
|
// @todo don't use a pointer to this should be in a global together with other logging data (see Log.h)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,12 @@ void atomic_set(volatile int32* value, int32 new_value)
|
||||||
__atomic_store_n(value, new_value, __ATOMIC_SEQ_CST);
|
__atomic_store_n(value, new_value, __ATOMIC_SEQ_CST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void atomic_set(volatile int64* value, int64 new_value)
|
||||||
|
{
|
||||||
|
__atomic_store_n(value, new_value, __ATOMIC_SEQ_CST);
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
void atomic_get(volatile byte* value, byte data[16])
|
void atomic_get(volatile byte* value, byte data[16])
|
||||||
{
|
{
|
||||||
|
|
@ -53,13 +59,13 @@ void atomic_decrement(volatile int32* value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
int32 atomic_add(volatile int32* value, int32 increment) {
|
void atomic_add(volatile int32* value, int32 increment) {
|
||||||
return __atomic_fetch_add(value, increment, __ATOMIC_SEQ_CST);
|
__atomic_fetch_add(value, increment, __ATOMIC_SEQ_CST);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
int32 atomic_subtract(volatile int32* value, int32 decrement) {
|
void atomic_sub(volatile int32* value, int32 decrement) {
|
||||||
return __atomic_fetch_sub(value, decrement, __ATOMIC_SEQ_CST);
|
__atomic_fetch_sub(value, decrement, __ATOMIC_SEQ_CST);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
|
|
||||||
28
platform/linux/threading/Spinlock.cpp
Normal file
28
platform/linux/threading/Spinlock.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
* Jingga
|
||||||
|
*
|
||||||
|
* @copyright Jingga
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
*/
|
||||||
|
#ifndef TOS_PLATFORM_LINUX_THREADING_SPINLOCK_C
|
||||||
|
#define TOS_PLATFORM_LINUX_THREADING_SPINLOCK_C
|
||||||
|
|
||||||
|
#include "../../../stdlib/Types.h"
|
||||||
|
#include "Spinlock.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
inline
|
||||||
|
void spinlock_start(spinlock32* lock, int32 delay = 10) {
|
||||||
|
while (__atomic_exchange_n(lock, 1, __ATOMIC_ACQUIRE) != 0) {
|
||||||
|
usleep(delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void spinlock_end(spinlock32* lock) {
|
||||||
|
__atomic_store_n(lock, 0, __ATOMIC_RELEASE);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -9,19 +9,9 @@
|
||||||
#ifndef TOS_PLATFORM_LINUX_THREADING_SPINLOCK_H
|
#ifndef TOS_PLATFORM_LINUX_THREADING_SPINLOCK_H
|
||||||
#define TOS_PLATFORM_LINUX_THREADING_SPINLOCK_H
|
#define TOS_PLATFORM_LINUX_THREADING_SPINLOCK_H
|
||||||
|
|
||||||
#include <stdatomic.h>
|
|
||||||
#include "../../../stdlib/Types.h"
|
#include "../../../stdlib/Types.h"
|
||||||
|
#include "Spinlock.h"
|
||||||
|
|
||||||
typedef volatile int32 spinlock32;
|
typedef volatile int32 spinlock32;
|
||||||
|
|
||||||
inline
|
|
||||||
void spinlock_start(spinlock32* lock) {
|
|
||||||
while (__atomic_exchange_n(lock, 1, __ATOMIC_ACQUIRE)) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
void spinlock_end(spinlock32* lock) {
|
|
||||||
__atomic_store_n(lock, 0, __ATOMIC_RELEASE);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -18,6 +18,12 @@ void atomic_set(volatile int32* value, int32 new_value)
|
||||||
InterlockedExchange((long *) value, new_value);
|
InterlockedExchange((long *) value, new_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void atomic_set(volatile int64* value, int64 new_value)
|
||||||
|
{
|
||||||
|
InterlockedExchange((long *) value, (long) new_value);
|
||||||
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
void atomic_set(volatile byte* value, const byte new_value[16])
|
void atomic_set(volatile byte* value, const byte new_value[16])
|
||||||
{
|
{
|
||||||
|
|
@ -68,13 +74,13 @@ void atomic_decrement(volatile int32* value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
int32 atomic_add(volatile int32* value, int32 increment) {
|
void atomic_add(volatile int32* value, int32 increment) {
|
||||||
return InterlockedExchangeAdd((long *) value, increment);
|
InterlockedAdd((long *) value, increment);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
int32 atomic_subtract(volatile int32* value, int32 decrement) {
|
void atomic_sub(volatile int32* value, int32 decrement) {
|
||||||
return InterlockedExchangeAdd((long *) value, -decrement);
|
InterlockedAdd((long *) value, -decrement);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
|
|
||||||
27
platform/win32/threading/Spinlock.cpp
Normal file
27
platform/win32/threading/Spinlock.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/**
|
||||||
|
* Jingga
|
||||||
|
*
|
||||||
|
* @copyright Jingga
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
*/
|
||||||
|
#ifndef TOS_PLATFORM_WIN32_THREADING_SPINLOCK_C
|
||||||
|
#define TOS_PLATFORM_WIN32_THREADING_SPINLOCK_C
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include "../TimeUtils.h"
|
||||||
|
|
||||||
|
inline
|
||||||
|
void spinlock_start(spinlock32* lock, int32 delay = 10) {
|
||||||
|
while (InterlockedExchange(lock, 1) != 0) {
|
||||||
|
usleep(delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void spinlock_end(spinlock32* lock) {
|
||||||
|
InterlockedExchange(lock, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -13,14 +13,4 @@
|
||||||
|
|
||||||
typedef volatile long spinlock32;
|
typedef volatile long spinlock32;
|
||||||
|
|
||||||
inline
|
|
||||||
void spinlock_start(spinlock32* lock) {
|
|
||||||
while (InterlockedExchange(lock, 1) == 1) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
void spinlock_end(spinlock32* lock) {
|
|
||||||
InterlockedExchange(lock, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -65,20 +65,4 @@ inline uint32 hash(uint64 a, uint64 b = 0)
|
||||||
return _mm_extract_epi32(hash, 0);
|
return _mm_extract_epi32(hash, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void atomic_increment(int32* a, int32 b) {
|
|
||||||
_aadd_i32(a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void atomic_increment(int64* a, int64 b) {
|
|
||||||
_aadd_i64((long long int *) a, (long long int) b);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void atomic_decrement(int32* a, int32 b) {
|
|
||||||
_aadd_i32(a, -b);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void atomic_decrement(int64* a, int64 b) {
|
|
||||||
_aadd_i64((long long int *) a, (long long int) -b);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user