Skip to content

Add some logic related to initialization to various block devices #7773

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

Merged
merged 1 commit into from
Aug 27, 2018

Conversation

davidsaada
Copy link
Contributor

Description

  • Add an initialization flag on which BD actions depend (fail if uninitialized).
  • Fix behavior of init reference count if first initialization fails.

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Feature
[ ] Breaking change

@davidsaada davidsaada force-pushed the david_fix_init_ref_count branch from 4fade51 to c10d029 Compare August 13, 2018 13:13
@cmonr cmonr requested a review from a team August 13, 2018 14:39
@@ -39,6 +39,10 @@ BufferedBlockDevice::~BufferedBlockDevice()

int BufferedBlockDevice::init()
{
if (!_is_initialized) {
_init_ref_count = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's a fault in this protection - Consider this Scenario:

  1. Threads1&2 are the first to call init simultaneously.
  2. Thread 1 calls init(), contact switch just before _init_ref_count = 0.
    (_is_initialized is still false)
  3. Thread 2 calls init(), also enters this 'if' and completes init() with _init_ref_count = 1.
  4. Thread 1 is now back and now it sets _init_ref_count = 0, it will also go through entire
    init() function and mess up the ref count

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Offir - you are right. This is indeed a bug (however awkward). Issuing a fix now.

@davidsaada davidsaada force-pushed the david_fix_init_ref_count branch from c10d029 to 5a87f3a Compare August 21, 2018 13:09
@davidsaada
Copy link
Contributor Author

Pushed a fix following @offirko's comments.

@offirko
Copy link
Contributor

offirko commented Aug 21, 2018

Looks great , thanks

- Add an initialization flag on which BD actions depend (fail if uninitialized).
- Fix behavior of init reference count if first initialization fails
@0xc0170
Copy link
Contributor

0xc0170 commented Aug 21, 2018

/morph build

@davidsaada
Copy link
Contributor Author

I really don't understand what the travis-ci/littlefs error is about. Has nothing to do with this PR.

@mbed-ci
Copy link

mbed-ci commented Aug 21, 2018

Build : SUCCESS

Build number : 2854
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7773/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Aug 21, 2018

@mbed-ci
Copy link

mbed-ci commented Aug 22, 2018

@cmonr
Copy link
Contributor

cmonr commented Aug 22, 2018

/morph test

@cmonr
Copy link
Contributor

cmonr commented Aug 23, 2018

Pausing Test CI until 5.9.6 PR is merged.
Will restart CI shortly after.

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 24, 2018

/morph test

@mbed-ci
Copy link

mbed-ci commented Aug 24, 2018

@cmonr
Copy link
Contributor

cmonr commented Aug 25, 2018

/morph test

@mbed-ci
Copy link

mbed-ci commented Aug 25, 2018

@cmonr
Copy link
Contributor

cmonr commented Aug 26, 2018

/morph test

2 similar comments
@NirSonnenschein
Copy link
Contributor

/morph test

@cmonr
Copy link
Contributor

cmonr commented Aug 27, 2018

/morph test

@mbed-ci
Copy link

mbed-ci commented Aug 27, 2018

@0xc0170 0xc0170 merged commit 928f90a into ARMmbed:master Aug 27, 2018
@davidsaada davidsaada deleted the david_fix_init_ref_count branch December 6, 2018 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants