Skip to content

Mutexes, take 5 #11866

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

Closed
wants to merge 9 commits into from
Next Next commit
Add an AtomicU64 type to std::sync::atomics
This also generalizes all atomic intrinsics over T so we'll be able to add u8
atomics if we really feel the need to (do we really want to?)
  • Loading branch information
alexcrichton committed Feb 3, 2014
commit b00147a99b289b11a210d9fc841b8aca3e59ce0e
11 changes: 7 additions & 4 deletions src/librustc/middle/trans/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use lib::llvm::{Opcode, IntPredicate, RealPredicate, False};
use lib::llvm::{ValueRef, BasicBlockRef, BuilderRef, ModuleRef};
use middle::trans::base;
use middle::trans::common::*;
use middle::trans::machine::llalign_of_min;
use middle::trans::machine::llalign_of_pref;
use middle::trans::type_::Type;
use std::cast;
use std::hashmap::HashMap;
Expand Down Expand Up @@ -461,8 +461,10 @@ impl Builder {
pub fn atomic_load(&self, ptr: ValueRef, order: AtomicOrdering) -> ValueRef {
self.count_insn("load.atomic");
unsafe {
let align = llalign_of_min(self.ccx, self.ccx.int_type);
llvm::LLVMBuildAtomicLoad(self.llbuilder, ptr, noname(), order, align as c_uint)
let ty = Type::from_ref(llvm::LLVMTypeOf(ptr));
let align = llalign_of_pref(self.ccx, ty.element_type());
llvm::LLVMBuildAtomicLoad(self.llbuilder, ptr, noname(), order,
align as c_uint)
}
}

Expand Down Expand Up @@ -514,8 +516,9 @@ impl Builder {
self.ccx.tn.val_to_str(val),
self.ccx.tn.val_to_str(ptr));
self.count_insn("store.atomic");
let align = llalign_of_min(self.ccx, self.ccx.int_type);
unsafe {
let ty = Type::from_ref(llvm::LLVMTypeOf(ptr));
let align = llalign_of_pref(self.ccx, ty.element_type());
llvm::LLVMBuildAtomicStore(self.llbuilder, val, ptr, order, align as c_uint);
}
}
Expand Down
41 changes: 17 additions & 24 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4030,29 +4030,32 @@ pub fn check_intrinsic_type(ccx: @CrateCtxt, it: &ast::ForeignItem) {

//We only care about the operation here
match split[1] {
"cxchg" => (0, ~[ty::mk_mut_rptr(tcx,
"cxchg" => (1, ~[ty::mk_mut_rptr(tcx,
ty::ReLateBound(it.id, ty::BrAnon(0)),
ty::mk_int()),
ty::mk_int(),
ty::mk_int()
], ty::mk_int()),
"load" => (0,
param(ccx, 0)),
param(ccx, 0),
param(ccx, 0),
], param(ccx, 0)),
"load" => (1,
~[
ty::mk_imm_rptr(tcx, ty::ReLateBound(it.id, ty::BrAnon(0)), ty::mk_int())
ty::mk_imm_rptr(tcx, ty::ReLateBound(it.id, ty::BrAnon(0)),
param(ccx, 0))
],
ty::mk_int()),
"store" => (0,
param(ccx, 0)),
"store" => (1,
~[
ty::mk_mut_rptr(tcx, ty::ReLateBound(it.id, ty::BrAnon(0)), ty::mk_int()),
ty::mk_int()
ty::mk_mut_rptr(tcx, ty::ReLateBound(it.id, ty::BrAnon(0)),
param(ccx, 0)),
param(ccx, 0)
],
ty::mk_nil()),

"xchg" | "xadd" | "xsub" | "and" | "nand" | "or" | "xor" | "max" |
"xchg" | "xadd" | "xsub" | "and" | "nand" | "or" | "xor" | "max" |
"min" | "umax" | "umin" => {
(0, ~[ty::mk_mut_rptr(tcx,
(1, ~[ty::mk_mut_rptr(tcx,
ty::ReLateBound(it.id, ty::BrAnon(0)),
ty::mk_int()), ty::mk_int() ], ty::mk_int())
param(ccx, 0)), param(ccx, 0) ],
param(ccx, 0))
}
"fence" => {
(0, ~[], ty::mk_nil())
Expand Down Expand Up @@ -4085,16 +4088,6 @@ pub fn check_intrinsic_type(ccx: @CrateCtxt, it: &ast::ForeignItem) {
}
"needs_drop" => (1u, ~[], ty::mk_bool()),
"owns_managed" => (1u, ~[], ty::mk_bool()),
"atomic_xchg" | "atomic_xadd" | "atomic_xsub" |
"atomic_xchg_acq" | "atomic_xadd_acq" | "atomic_xsub_acq" |
"atomic_xchg_rel" | "atomic_xadd_rel" | "atomic_xsub_rel" => {
(0,
~[
ty::mk_mut_rptr(tcx, ty::ReLateBound(it.id, ty::BrAnon(0)), ty::mk_int()),
ty::mk_int()
],
ty::mk_int())
}

"get_tydesc" => {
let tydesc_ty = match ty::get_tydesc_ty(ccx.tcx) {
Expand Down
Loading