/src/test/run-make-fulldeps/atomic-lock-free/atomic_lock_free.rs

https://gitlab.com/jianglu/rust · Rust · 68 lines · 54 code · 5 blank · 9 comment · 1 complexity · 0c25429c9c62298164f297cb2bda7a7e MD5 · raw file

  1. // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // http://rust-lang.org/COPYRIGHT.
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. #![feature(cfg_target_has_atomic, no_core, intrinsics, lang_items)]
  11. #![crate_type="rlib"]
  12. #![no_core]
  13. extern "rust-intrinsic" {
  14. fn atomic_xadd<T>(dst: *mut T, src: T) -> T;
  15. }
  16. #[lang = "sized"]
  17. trait Sized {}
  18. #[lang = "copy"]
  19. trait Copy {}
  20. #[lang = "freeze"]
  21. trait Freeze {}
  22. impl<T: ?Sized> Copy for *mut T {}
  23. #[cfg(target_has_atomic = "8")]
  24. pub unsafe fn atomic_u8(x: *mut u8) {
  25. atomic_xadd(x, 1);
  26. atomic_xadd(x, 1);
  27. }
  28. #[cfg(target_has_atomic = "8")]
  29. pub unsafe fn atomic_i8(x: *mut i8) {
  30. atomic_xadd(x, 1);
  31. }
  32. #[cfg(target_has_atomic = "16")]
  33. pub unsafe fn atomic_u16(x: *mut u16) {
  34. atomic_xadd(x, 1);
  35. }
  36. #[cfg(target_has_atomic = "16")]
  37. pub unsafe fn atomic_i16(x: *mut i16) {
  38. atomic_xadd(x, 1);
  39. }
  40. #[cfg(target_has_atomic = "32")]
  41. pub unsafe fn atomic_u32(x: *mut u32) {
  42. atomic_xadd(x, 1);
  43. }
  44. #[cfg(target_has_atomic = "32")]
  45. pub unsafe fn atomic_i32(x: *mut i32) {
  46. atomic_xadd(x, 1);
  47. }
  48. #[cfg(target_has_atomic = "64")]
  49. pub unsafe fn atomic_u64(x: *mut u64) {
  50. atomic_xadd(x, 1);
  51. }
  52. #[cfg(target_has_atomic = "64")]
  53. pub unsafe fn atomic_i64(x: *mut i64) {
  54. atomic_xadd(x, 1);
  55. }
  56. #[cfg(target_has_atomic = "ptr")]
  57. pub unsafe fn atomic_usize(x: *mut usize) {
  58. atomic_xadd(x, 1);
  59. }
  60. #[cfg(target_has_atomic = "ptr")]
  61. pub unsafe fn atomic_isize(x: *mut isize) {
  62. atomic_xadd(x, 1);
  63. }