Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

add core.sync.event to be used as Windows events#2517

Merged
dlang-bot merged 3 commits intodlang:masterfrom
rainers:core_sync_event
Mar 25, 2019
Merged

add core.sync.event to be used as Windows events#2517
dlang-bot merged 3 commits intodlang:masterfrom
rainers:core_sync_event

Conversation

@rainers
Copy link
Copy Markdown
Member

@rainers rainers commented Mar 22, 2019

extracted from #2514

@dlang-bot
Copy link
Copy Markdown
Contributor

Thanks for your pull request, @rainers!

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 fetch digger
dub run digger -- build "master + druntime#2517"

@rainers rainers force-pushed the core_sync_event branch 7 times, most recently from 3f7ef75 to 0232a3f Compare March 22, 2019 16:38

version (Windows)
{
import core.sys.windows.basetsd /+: HANDLE +/;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why these comments?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This follows the example of https://github.com/dlang/druntime/pull/2400/files (selective imports create a public alias).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hasn't this been fixed a year ago or so?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh well, looks like it's really still in deprecation, but there's a PR to remove them for good:

dlang/dmd#9393

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That will go in very soon.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rainers this has been merged now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not good enough:

test.d(3): Deprecation: core.sync.event.HANDLE is not visible from module test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

😞

pthread_cond_signal(&waiter.cond);
pthread_mutex_unlock(&waiter.mutex);
}
pthread_mutex_unlock(&m_mutex);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

scope(exit)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The function is nothrow anyway, so it doesn't make a difference in code generation. With a short function like this, having the symmetry show up in the function is slightly better IMO.

* manualReset = the state of the event is not reset automatically after resuming waiting clients
* initialState = initial state of the signal
*/
void initialize(bool manualReset, bool initialState)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this a separate method?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You cannot pass arguments to the constructor if it is part of another struct, e.g. https://github.com/dlang/druntime/pull/2514/files#diff-6615611ba51118215a271e3500c61122R2605. You have to use an explicit initialize-call then. __ctor could be an alternative, but I think it should not be part of the API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a downside to do evStart = Event(...) in Gcx.initialize?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've explicitly added @disable this(this) as this could duplicate the handle reference.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does not seem to prevent assignment: https://run.dlang.io/is/iefkBG.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, seems like opAssign should be disabled, too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If that's required then I'm fine with using initialize instead of a constructor.

@rainers rainers force-pushed the core_sync_event branch 2 times, most recently from e0006b2 to 0fb8576 Compare March 23, 2019 10:22
terminate();
}

void terminate()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No documentation.

@jacob-carlborg
Copy link
Copy Markdown
Contributor

No changelog.

Copy link
Copy Markdown
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

Pending:

  • uncommented selective imports
  • changelog
  • initialize in place of constructor
  • terminate documentation

@rainers
Copy link
Copy Markdown
Member Author

rainers commented Mar 23, 2019

Added changelog and a bit more documentation. I've also added a bool to keep track of the initialization state of the posix version.

* uncommented selective imports

I think this should be done for all the imports once the dmd deprecation is gone (dlang/dmd#9393 doesn't help for this case yet).

@thewilsonator
Copy link
Copy Markdown
Contributor

posix.mak:348: recipe for target 'checkwhitespace' failed

@rainers rainers force-pushed the core_sync_event branch 2 times, most recently from 7171e27 to 05e84ca Compare March 23, 2019 14:27
@kinke
Copy link
Copy Markdown
Contributor

kinke commented Mar 23, 2019

Rainer, have you explored whether pthread_cond_broadcast and a single condition variable could work too?

@rainers
Copy link
Copy Markdown
Member Author

rainers commented Mar 24, 2019

Rainer, have you explored whether pthread_cond_broadcast and a single condition variable could work too?

Didn't know about it, now replaced the manual implementation.

}
}

// Test single-thread (non-shared) use.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe make this example public, s.t. there's at least one user-facing example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this example is a pretty bad one as it doesn't involve multiple threads. Maybe better to move the example from the changelog into the documentation?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure. I just saw that the module is currently without any public example.

@dlang-bot dlang-bot merged commit 334b9df into dlang:master Mar 25, 2019
event.terminate();
}
}
---
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why isn't it a documented unittest instead ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think its already a bit too long for a really good example, and making it actually runnable would make it even longer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants