Skip to content

Conversation

@Aidan63
Copy link
Contributor

@Aidan63 Aidan63 commented Jan 24, 2026

Replaces the old implementation which had a bunch of ifdefs depending on the platform. Now we have a single implementation using the C++ std types. I would have done the same for Lock but for some reason it took until C++20 to get a semaphore type...

I have broken the definitions out into their own headers and exposed the classes so on the haxe side we can remove the untyped code.




Dynamic __hxcpp_mutex_create()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we omit these for hxcpp_api_level >= 500? It would be good to deprecate them anyway since identifiers containing __ are reserved by c++.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do this but in a separate PR, other wise I think we end up in a situation where the CIs need two sets of changes merged at the same time to go green.

}


HxMutex mMutex;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the mutex no longer uses HxMutex, I think we should also remove the HxMutex type from everywhere else in the codebase for internal consistency.

That also officially breaks the HX_THREAD_H_OVERRIDE feature, so we would have to remove that too, or continue to have a HxMutex wrapper.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think replacing uses of HxMutex with std::recursive_mutex makes sense. As a replacement for HX_THREAD_H_OVERRIDE maybe have a hxml & xml HX_THREAD_API_XML define which you can point to a custom xml file which will provide the implementation of the ConditionVariable and RecursiveMutex types?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, though if it is for hxml use it should be prefixed with HXCPP_ for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's only one use of HxMutex / a bit of manual pthread condition left in Immix.cpp now, unfortunately this last one is a bit of a pain. C++ states that when the dtor of std::condition_variable gets called no thread should have it locked, however on exit hxcpp programs hang when adapting the last uses of pthread conditions to std::condition_variable as some thread seems to be holding onto the locks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've solved that, the only remaining use of HxMutex is in the Deque and Lock implementation. These two also seem a bit tricky as there is differing implementations for Windows and non Windows platforms (not sure why).
Think I'll also try and get those sorted in a different PR.

return cond->TimedWait(timeout);
bool __hxcpp_condition_timed_wait(Dynamic inCond, double timeout)
{
return hx::Throw(HX_CSTRING("Not Implemented"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is being removed, I think it would be better to remove it completely rather than keeping it and having a runtime error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was I'd get rid of it along with the other functions after it's merged in so the CI on the haxe side can stay green with the pending PR.

@Simn
Copy link
Member

Simn commented Jan 28, 2026

Let me know when this is good to merge, I'd like to get hxcoro back to hxcpp master soon to see if we benefit from the pch change!

@Aidan63
Copy link
Contributor Author

Aidan63 commented Jan 28, 2026

I think it's good to go, the remaining things mentioned are best done in a separate PR after the haxe side is merged so we can keep the CIs green.

@Simn
Copy link
Member

Simn commented Jan 28, 2026

Alright! Any change to Immix.cpp terrifies me, but if something comes up I'm sure we (= you) will figure it out!

@Simn Simn merged commit 0e9183d into HaxeFoundation:master Jan 28, 2026
120 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants