Skip to content

add rust_trylock_little_lock #10428

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
Nov 14, 2013
Merged

add rust_trylock_little_lock #10428

merged 1 commit into from
Nov 14, 2013

Conversation

toffaletti
Copy link
Contributor

I need try_lock for an algorithm I'm trying to implement in Rust.

_holding_thread = pthread_self();
#endif
return true;
} else if (trylock == EBUSY) {
Copy link
Member

Choose a reason for hiding this comment

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

How come this is explicitly checked?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EBUSY is what happens when the lock is already locked.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I'd be more comfortable with a comment along the lines of:

// Explicitly return false on EBUSY (lock is already locked), but assert on all other errors

@toffaletti
Copy link
Contributor Author

I've attempted to improve the readability.

@toffaletti
Copy link
Contributor Author

I've fixed the compile error. I'm not able to compile and test this locally, which is why this happened. The error I get has something to do with stage0 snapshot not containing my changes to the C++ lib. I might have to split this into two changes. One to change the C++ lib and a later change to libstd?

@alexcrichton
Copy link
Member

Oh I forgot to ask before, but could you expand the commit message a little bit? Just the standard short-title + 1-2 sentences after it explaining what's going on. Thanks!

@toffaletti
Copy link
Contributor Author

@huonw Thanks, adding #[cfg(not(stage0))] before try_lock worked, but then my make check-stage1 failed at:

compile_and_link: x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/librustpkg.so
/home/jason/rust/src/librustpkg/path_util.rs:476:12: 476:23 error: invoking non-Rust fn in fn without #[fixed_stack_segment], #[deny(cstack)] on by default
/home/jason/rust/src/librustpkg/path_util.rs:476             libc::chmod(src_buf, S_IRUSR as libc::mode_t) == 0
                                                             ^~~~~~~~~~~
error: aborting due to previous error

This was rebased off latest master.

@alexcrichton I updated the commit message, but before this is merged I'll probably need to rebase off master once the above issue is fixed.

@alexcrichton
Copy link
Member

This doesn't look to be a snapshot problem, we rebuild the runtime for stage0. It looks like you're just missing the shim C function in the middle.

@toffaletti
Copy link
Contributor Author

Sorry, two different problems. First I had a problem building stage0, which iirc was complaining about librustrt not containing rust_trylock_littlelock. This was related to my change and was fixed by the annotation suggested by huonw. Then I pulled in the latest master changes and like I said above, got a new error while running make check. This second error seems unrelated to my changes it just means my pull request won't build because I pulled in someone else's bug in librustpkg.

@toffaletti
Copy link
Contributor Author

Looks like 65aacd0#diff-e16b4a8a6901a9937ee5627cfddb3590R474 fixes my second problem. I'll pull that in and try again tomorrow.

@toffaletti
Copy link
Contributor Author

This should be good to merge now. I rebased off current master and it passed make check-stage1.

@alexcrichton
Copy link
Member

Are you sure? I'm still not seeing a definition of rust_trylock_little_lock and the cfg(not(stage0)) is still there (it's not needed)

@toffaletti
Copy link
Contributor Author

You're right, it would help if I committed my local changes.

Try to acquire lock and succeed only if lock is not already held.
Uses TryEnterCriticalSection or pthread_mutex_trylock.
bors added a commit that referenced this pull request Nov 14, 2013
I need try_lock for an algorithm I'm trying to implement in Rust.
@bors bors closed this Nov 14, 2013
@bors bors merged commit 91de538 into rust-lang:master Nov 14, 2013
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.

3 participants