Skip to content

Conversation

@SergeyRyabinin
Copy link
Contributor

@SergeyRyabinin SergeyRyabinin commented Oct 11, 2023

Issue #, if available:
This is a workaround for issues where customer is not able to control underlying libraries using the C++ SDK, such as #2699
Description of changes:
Add reference count on and blocking on mutex on InitAPI-ShutdownAPI methods.
This does not really fix the root architectural issue, but at least it provides a some level of workaround.
All consequent calls to InitAPI only increases the SDK usage count, options argument is completely ignored on any subsequent call, and only the last ShutdownAPI will actually shut down the library.
Check all that applies:

  • Did a review by yourself.
  • Added proper tests to cover this PR. (If tests are not applicable, explain.)
  • Checked if this PR is a breaking (APIs have been changed) change.
  • Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • Linux
  • Windows
  • Android
  • MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

if(s_initCount != 1)
{
if(!s_initCount) {
AWS_LOGSTREAM_ERROR(ALLOCATION_TAG, "Unable to ShutdownAPI of AWS-SDK-CPP: the SDK was not initialized.");
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 have no idea how this one is going to be actually traced (without an initialized logger)
I don't want to add an assert here though.

{
std::unique_lock<std::mutex> lock(s_initShutdownMutex);
s_initCount += 1;
if(s_initCount != 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

could we use an atomic int instead of a mutex?

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 also wanted to prevent simultaneous Init/Shutdown calls.

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.

2 participants