On Windows if you know what the right declarations are it should be easy to ...
12 years, 8 months ago
(2012-08-13 16:05:32 UTC)
#4
On Windows if you know what the right declarations are it should be
easy to implement the macros like for pthread and not have any static
initializers. If that matters to you, just let me know what to type.
:-)
On 2012/08/13 16:05:32, rsc_swtch wrote: > On Windows if you know what the right declarations ...
12 years, 8 months ago
(2012-08-13 16:16:17 UTC)
#5
On 2012/08/13 16:05:32, rsc_swtch wrote:
> On Windows if you know what the right declarations are it should be
> easy to implement the macros like for pthread and not have any static
> initializers. If that matters to you, just let me know what to type.
> :-)
:-)
David suggested this snippet for windows (and using pthread_once_t for pthread):
// MSVC ensures that loads of volatile variables have acquire semantics, and
stores have release semantics.
typedef LONG volatile OnceType;
enum {
ONCE_INIT = 0,
ONCE_CONSTRUCTING,
ONCE_COMPLETED
};
void inline OnceInit(OnceType* once, void(*callback)()) {
if (*once == ONCE_COMPLETED) // inlined fast-path
return;
OnceInitImpl(once, callback);
}
....
void OnceInitImpl(OnceType* once, void (*callback)()) {
OnceType state = reinterpret_cast<OnceType>(InterlockedCompareExchange(once,
ONCE_CONSTRUCTING, ONCE_INIT));
if (state == ONCE_COMPLETED)
return;
else if (state == ONCE_INIT) { // we're the first thread, run the callback
(*callback)();
*once = ONCE_COMPLETED;
} else while (*once == ONCE_CONSTRUCTING) { // need to wait for completion
Sleep(0); // yield thread on Windows
}
}
Bug I am happy with the current proposal if David is.
Best regards,
Dominic
On 2012/08/13 16:16:17, Dominic Battre wrote: > On 2012/08/13 16:05:32, rsc_swtch wrote: > > On ...
12 years, 8 months ago
(2012-08-16 16:03:41 UTC)
#6
On 2012/08/13 16:16:17, Dominic Battre wrote:
> On 2012/08/13 16:05:32, rsc_swtch wrote:
> > On Windows if you know what the right declarations are it should be
> > easy to implement the macros like for pthread and not have any static
> > initializers. If that matters to you, just let me know what to type.
> > :-)
>
> :-)
>
> David suggested this snippet for windows (and using pthread_once_t for
pthread):
>
> // MSVC ensures that loads of volatile variables have acquire semantics, and
> stores have release semantics.
>
> typedef LONG volatile OnceType;
> enum {
> ONCE_INIT = 0,
> ONCE_CONSTRUCTING,
> ONCE_COMPLETED
> };
> void inline OnceInit(OnceType* once, void(*callback)()) {
> if (*once == ONCE_COMPLETED) // inlined fast-path
> return;
> OnceInitImpl(once, callback);
>
> }
> ....
> void OnceInitImpl(OnceType* once, void (*callback)()) {
> OnceType state = reinterpret_cast<OnceType>(InterlockedCompareExchange(once,
> ONCE_CONSTRUCTING, ONCE_INIT));
>
> if (state == ONCE_COMPLETED)
> return;
> else if (state == ONCE_INIT) { // we're the first thread, run the callback
> (*callback)();
>
> *once = ONCE_COMPLETED;
> } else while (*once == ONCE_CONSTRUCTING) { // need to wait for completion
> Sleep(0); // yield thread on Windows
>
> }
> }
>
> Bug I am happy with the current proposal if David is.
>
> Best regards,
> Dominic
friendly ping @digit
lgtm Sorry if I wasn't clear. I think this patch is good enough for now. ...
12 years, 8 months ago
(2012-08-16 16:06:09 UTC)
#7
lgtm
Sorry if I wasn't clear. I think this patch is good enough for now. I.e. I
prefer that proper support for the Windows global mutex be added in another
patch, which will make it easier to review (it's after all quite tricky).
(Note that I work on Chrome for Android, which is in no way related to Windows
:-))
Issue 6442107: code review 6442107: re2: eliminate global c++ constructors
(Closed)
Created 12 years, 8 months ago by rsc
Modified 12 years, 4 months ago
Reviewers:
Base URL:
Comments: 2