Skip to content
Open
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
33 changes: 33 additions & 0 deletions include/hx/thread/Scratch.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#ifndef HXCPP_H
#include <hxcpp.h>
#endif

HX_DECLARE_CLASS2(hx, thread, Thread)

namespace hx
{
namespace thread
{
class Scratch final
{
using ReleaseFunc = void(*)(cpp::marshal::View<uint8_t>);

int* count;
ReleaseFunc release;

public:
static Scratch alloc(int bytes);

cpp::marshal::View<uint8_t> view;

Scratch(int* _count, cpp::marshal::View<uint8_t> _view, ReleaseFunc _release);
Scratch(const Scratch& other);

~Scratch();

Scratch& operator=(const Scratch& other);
};
}
}
37 changes: 37 additions & 0 deletions include/hx/thread/Thread.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#ifndef HXCPP_H
#include <hxcpp.h>
#endif

HX_DECLARE_CLASS2(hx, thread, Thread)

namespace hx
{
namespace thread
{
struct Thread_obj : public hx::Object
{
using CreateFunction =
#if (HXCPP_API_LEVEL >= 500)
Callable<void(void)>;
#else
Dynamic;
#endif

static Thread create(CreateFunction);
static Thread current();
static int id();

virtual String getName() = 0;
virtual void setName(const String& name) = 0;

virtual String toString() override = 0;

virtual void __Mark(HX_MARK_PARAMS) override = 0;
#ifdef HXCPP_VISIT_ALLOCS
virtual void __Visit(HX_VISIT_PARAMS) override = 0;
#endif
};
}
}
26 changes: 26 additions & 0 deletions include/hx/thread/ThreadLocal.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#ifndef HXCPP_H
#include <hxcpp.h>
#endif

HX_DECLARE_CLASS2(hx, thread, ThreadLocal)

namespace hx
{
namespace thread
{
class ThreadLocal_obj : public hx::Object
{
struct Impl;

Impl* impl;

public:
ThreadLocal_obj();

Dynamic get();
void set(Dynamic obj);
};
}
}
3 changes: 2 additions & 1 deletion src/hx/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <hx/Thread.h>
#include <hx/Telemetry.h>
#include <hx/Unordered.h>
#include <hx/thread/Thread.hpp>
#include <hx/OS.h>
#include <mutex>

Expand Down Expand Up @@ -244,7 +245,7 @@ StackContext::~StackContext()
void StackContext::onThreadAttach()
{
#ifdef HXCPP_STACK_IDS
mThreadId = __hxcpp_GetCurrentThreadNumber();
mThreadId = hx::thread::Thread_obj::id();

{
std::lock_guard<std::mutex> guard(sStackMapMutex);
Expand Down
5 changes: 3 additions & 2 deletions src/hx/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <hx/Thread.h>
#include <hx/OS.h>
#include <hx/QuickVec.h>
#include <hx/thread/Thread.hpp>
#include <mutex>

// Newer versions of haxe compiler will set these too (or might be null for haxe 3.0)
Expand Down Expand Up @@ -1260,7 +1261,7 @@ void __hxcpp_dbg_setEventNotificationHandler(Dynamic handler)
if (hx::g_eventNotificationHandler != null()) {
GCRemoveRoot(&(hx::g_eventNotificationHandler.mPtr));
}
hx::g_debugThreadNumber = __hxcpp_GetCurrentThreadNumber();
hx::g_debugThreadNumber = hx::thread::Thread_obj::id();
hx::g_eventNotificationHandler = handler;
GCAddRoot(&(hx::g_eventNotificationHandler.mPtr));
}
Expand All @@ -1275,7 +1276,7 @@ void __hxcpp_dbg_enableCurrentThreadDebugging(bool enable)

int __hxcpp_dbg_getCurrentThreadNumber()
{
return __hxcpp_GetCurrentThreadNumber();
return hx::thread::Thread_obj::id();
}


Expand Down
Loading
Loading