-
Notifications
You must be signed in to change notification settings - Fork 465
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
tsfn: Implement copy constructor #546
Conversation
Removes the `unique_ptr` from `ThreadSafeFunction`, thereby allowing copies. Ref: nodejs#524
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should copied ThreadSafeFunction be acquired automatically and requires a release?
Hi @legendecas , So... IMO I don't think it should automatically acquire/release. I believe it adds an assumption that each copy must perform an Also, if |
@legendecas IINM passing to another thread may not be the only reason for copying a |
Also IINM it should be easy to subclass |
So I have no idea about the ambiguous function calls for |
I agree that the problem related to ambiguous function calls is independent and could be addressed in a follow on PR. |
TestData* testData = static_cast<TestData*>(info.Data()); | ||
ThreadSafeFunction tsfn = testData->tsfn; | ||
int threadId = testData->threads.size(); | ||
testData->threads.push_back( thread(entryAcquire, tsfn, threadId) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be useful to highlight with a comment that this is where the copy constructor is being tested. Since the main change is to add the copy constructor it would be good to make it obvious in the test that it is being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hey @mhdawson, can we get this landed so I can continue work on Ref/Unref as well as the incorrect |
I'm in the process of landing. It did not seem to compile with master and the older 4.8.5 compiler. That may just be because master need gcc 6, but I want to run a CI on 8.x before landing. Unfortunately, the CI job is having some issues getting the Node binaries so I'll have to figure that out first. |
This seems to fail to build on 8.x with the 4.8.5 compiler level. You can see the compile failures her: https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/nodes=ubuntu1604-64/822/console |
@KevinEady can you take a look:
|
Hey team, So I was actually testing this on Windows, and it was failing because defining a move operator implicitly deletes the assignment operator... And, if you think about it, the
I did not think it was worthwhile to explicitly create these constructors, nor state them as default in napi.h , so I just removed them. Since this is structural change, I've dismissed your review @mhdawson |
CI job to validate builds on Node 8.x: https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/854/ |
@KevinEady seems to be failures on osx and aix: : https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/854/ |
Hi @mhdawson , Fixed some issues in the tests that I know were problematic, but this one is really stumping me..
I don't know, just looking at the node name os |
Hi @mhdawson / @gabrielschulhof , So I re-wrote my tests to use |
I noticed there are still usages on promises/futures in |
Hi @legendecas ,
So I noticed I did not remove the include, which I now replaced with the correct ones for use with condition_variable/mutex. However, the promise / deferred you see are |
CI run to see if it works on 8.x https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/906/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@legendecas let us know if the latest changes address your concerns and then approve if appropriate. Will wait to hear from you before landing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall with one nit...
} | ||
|
||
inline ThreadSafeFunction::ConvertibleContext | ||
ThreadSafeFunction::GetContext() const { | ||
void* context; | ||
napi_get_threadsafe_function_context(*_tsfn, &context); | ||
napi_get_threadsafe_function_context(_tsfn, &context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abort if failed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the change doesn't change the behavior here, we could address this issue in another PR. Opened issue here #581.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@legendecas I agree, can you open an issue to make sure we fix it later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KevinEady - oops should have read more carefullly. Thanks.
Landed as 2e71842 |
* tsfn: Implement copy constructor Refs: nodejs/node-addon-api#524 PR-URL: nodejs/node-addon-api#546 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
* tsfn: Implement copy constructor Refs: nodejs/node-addon-api#524 PR-URL: nodejs/node-addon-api#546 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
* tsfn: Implement copy constructor Refs: nodejs/node-addon-api#524 PR-URL: nodejs/node-addon-api#546 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
* tsfn: Implement copy constructor Refs: nodejs/node-addon-api#524 PR-URL: nodejs/node-addon-api#546 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
Removes the
unique_ptr
fromThreadSafeFunction
, thereby allowingcopies.
Ref: #524