Skip to content

Commit 866712c

Browse files
committed
---
yaml --- r: 272511 b: refs/heads/master c: 112463a h: refs/heads/master i: 272509: 240ab5c 272507: bbd8562 272503: f2e9b92 272495: 55f22f1 272479: 3b4e96c 272447: 26311af 272383: 2d448ce
1 parent 1b02dcc commit 866712c

File tree

2 files changed

+19
-43
lines changed

2 files changed

+19
-43
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: abc3777c06abced90b415b920082a4814d9051d7
2+
refs/heads/master: 112463a3b1b1fc30c8f407e50e9ef692034ccb37
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
44
refs/heads/try: 49312a405e14a449b98fe0056b12a40ac128be4a
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

trunk/src/libstd/sys/unix/thread.rs

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,17 @@ pub mod guard {
201201
current().map(|s| s as *mut libc::c_void)
202202
}
203203

204-
#[cfg(target_os = "freebsd")]
204+
#[cfg(any(target_os = "android", target_os = "freebsd",
205+
target_os = "linux", target_os = "netbsd"))]
205206
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
206207
let mut ret = None;
207208
let mut attr: libc::pthread_attr_t = ::mem::zeroed();
208209
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
209-
if libc::pthread_attr_get_np(libc::pthread_self(), &mut attr) == 0 {
210-
let mut stackaddr = ::ptr::null_mut();
211-
let mut stacksize = 0;
212-
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr,
213-
&mut stacksize), 0);
214-
ret = Some(stackaddr);
215-
}
216-
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
217-
ret
218-
}
219-
220-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
221-
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
222-
let mut ret = None;
223-
let mut attr: libc::pthread_attr_t = ::mem::zeroed();
224-
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
225-
if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 {
210+
#[cfg(target_os = "freebsd")]
211+
let e = libc::pthread_attr_get_np(libc::pthread_self(), &mut attr);
212+
#[cfg(not(target_os = "freebsd"))]
213+
let e = libc::pthread_getattr_np(libc::pthread_self(), &mut attr);
214+
if e == 0 {
226215
let mut stackaddr = ::ptr::null_mut();
227216
let mut stacksize = 0;
228217
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr,
@@ -304,33 +293,18 @@ pub mod guard {
304293
})
305294
}
306295

307-
#[cfg(target_os = "freebsd")]
308-
pub unsafe fn current() -> Option<usize> {
309-
let mut ret = None;
310-
let mut attr: libc::pthread_attr_t = ::mem::zeroed();
311-
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
312-
if libc::pthread_attr_get_np(libc::pthread_self(), &mut attr) == 0 {
313-
let mut guardsize = 0;
314-
assert_eq!(libc::pthread_attr_getguardsize(&attr, &mut guardsize), 0);
315-
if guardsize == 0 {
316-
panic!("there is no guard page");
317-
}
318-
let mut stackaddr = ::ptr::null_mut();
319-
let mut size = 0;
320-
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr,
321-
&mut size), 0);
322-
ret = Some(stackaddr as usize - guardsize as usize);
323-
}
324-
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
325-
ret
326-
}
327-
328-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
296+
#[cfg(any(target_os = "android", target_os = "freebsd",
297+
target_os = "linux", target_os = "netbsd"))]
329298
pub unsafe fn current() -> Option<usize> {
330299
let mut ret = None;
331300
let mut attr: libc::pthread_attr_t = ::mem::zeroed();
332301
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
333-
if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 {
302+
#[cfg(target_os = "freebsd")]
303+
let e = libc::pthread_attr_get_np(libc::pthread_self(), &mut attr);
304+
#[cfg(not(target_os = "freebsd"))]
305+
let e = libc::pthread_getattr_np(libc::pthread_self(), &mut attr);
306+
if e == 0 {
307+
//if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 {
334308
let mut guardsize = 0;
335309
assert_eq!(libc::pthread_attr_getguardsize(&attr, &mut guardsize), 0);
336310
if guardsize == 0 {
@@ -341,7 +315,9 @@ pub mod guard {
341315
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr,
342316
&mut size), 0);
343317

344-
ret = if cfg!(target_os = "netbsd") {
318+
ret = if cfg!(target_os = "freebsd") {
319+
Some(stackaddr as usize - guardsize as usize)
320+
} else if cfg!(target_os = "netbsd") {
345321
Some(stackaddr as usize)
346322
} else {
347323
Some(stackaddr as usize + guardsize as usize)

0 commit comments

Comments
 (0)