Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dmd-cxx] Use run-time allocated mutexes for plain synchronized statements #11902

Merged
merged 1 commit into from
Oct 23, 2020

Conversation

ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Oct 23, 2020

Backport of #11824, depends on dlang/druntime#3248

@ibuclaw ibuclaw added GDC Gnu D Compiler C++ Port labels Oct 23, 2020
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @ibuclaw!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "dmd-cxx + dmd#11902"

@ibuclaw ibuclaw changed the title [dmd-cxx ]Use run-time allocated mutexes for plain synchronized statements [dmd-cxx] Use run-time allocated mutexes for plain synchronized statements Oct 23, 2020
…tements

Synchronized statements have two forms, `synchronized` and `synchronized(exp)`.
When there is no expression argument, a global mutex is created using a static
buffer big enough to store the platform dependant critical section type and a
pointer field.

Example:
```
void main()
{
    synchronized {
        // __gshared byte[40 + 8] __critsec;
        // _d_criticalenter(&__critsec[0]);
        // scope(exit) _d_criticalexit(&__critsec[0]);
        (cast() counter) += 1;
    }
}
```

This implementation suffers from a couple deficiencies. Neither the size nor
alignment of the `critsec` buffer are obtained from the OS critical section
type defined in druntime. As a result, if the size allocated by the compiler is
too small, or the platform has strict alignment requirements, then the program
run-time will crash on entering the synchronized statement.

This code will now call a new implementation that allocates the critical
section lazily at run-time.
@dlang-bot dlang-bot merged commit bec5973 into dlang:dmd-cxx Oct 23, 2020
@ibuclaw ibuclaw deleted the dmd-cxx-synchronized branch October 23, 2020 14:38
sebhub pushed a commit to RTEMS/gnu-mirror-gcc that referenced this pull request Oct 27, 2020
The allocation of mutex objects for synchronized statements has been
moved to the library as of merging druntime 58560d51.  All support code
in the compiler for getting the OS critical section size has been
removed along with it.

Reviewed-on: dlang/dmd#11902
	     dlang/druntime#3248

gcc/ChangeLog:

	* config/aarch64/aarch64-linux.h (GNU_USER_TARGET_D_CRITSEC_SIZE):
	Remove.
	* config/glibc-d.c (glibc_d_critsec_size): Likewise.
	(TARGET_D_CRITSEC_SIZE): Likewise.
	* config/i386/linux-common.h (GNU_USER_TARGET_D_CRITSEC_SIZE):
	Likewise.
	* config/sol2-d.c (solaris_d_critsec_size): Likewise.
	(TARGET_D_CRITSEC_SIZE):  Likewise.
	* doc/tm.texi.in (TARGET_D_CRITSEC_SIZE): Likewise.
	* doc/tm.texi: Regenerate.

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd bec5973b0.
	* d-target.cc (Target::critsecsize): Remove.
	* d-target.def: Remove d_critsec_size.

libphobos/ChangeLog:

	* libdruntime/MERGE: Merge upstream druntime 58560d51.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants