Skip to content

Commit

Permalink
export getAndResetCycles
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Jan 31, 2024
1 parent bf7e7dd commit acbd80d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions native/jsdos/include/jsdos-asyncify.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

#ifndef JS_DOS_JSDOS_ASYNCIFY_H
#define JS_DOS_JSDOS_ASYNCIFY_H

#include <stdint.h>

namespace jsdos {
void initAsyncify();
void asyncifyLock();
void asyncifyUnlock();
void destroyAsyncify();
void incCycles();
uint32_t getAndResetCycles();
}

extern "C" void asyncify_sleep(unsigned int ms, bool nonSkippable = 0);
Expand Down
16 changes: 10 additions & 6 deletions native/jsdos/jsdos-asyncify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Created by caiiiycuk on 13.11.2019.
//
#include <jsdos-asyncify.h>
#include <cstdint>
#include <atomic>

#ifdef EMSCRIPTEN
// clang-format off
Expand Down Expand Up @@ -242,15 +242,19 @@ extern "C" void asyncify_sleep(unsigned int ms, bool nonSkippable) {
}

namespace {
uint64_t cycles = 0;
std::atomic_uint32_t cycles(0);
}

void jsdos::incCycles() {
::cycles++;
}

extern "C" uint64_t EMSCRIPTEN_KEEPALIVE getAndResetCycles() {
uint64_t tmp = cycles;
cycles = 0;
return tmp;
uint32_t jsdos::getAndResetCycles() {
uint32_t tmp = ::cycles;
::cycles = 0;
return tmp;
}

extern "C" uint32_t EMSCRIPTEN_KEEPALIVE getAndResetCycles() {
return jsdos::getAndResetCycles();
}

0 comments on commit acbd80d

Please sign in to comment.