Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'scheduling' into rework-memory
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueDoctor authored Apr 12, 2020
2 parents a49727d + 9525598 commit 3310940
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/graphics/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ impl GraphicsApi for WebGl {
}

fn upload_texture(&mut self, texture: &Texture, n: u32) -> Result<(), ClientError> {

log::debug!(
"uploading texture (id {}, {}x{})",
n,
Expand Down Expand Up @@ -280,6 +281,7 @@ impl GraphicsApi for WebGl {
self.gl
.viewport(0, 0, self.width as i32, self.height as i32);
self.draw_rect_notexture(&-Mat3::identity())?;

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions client/graphics/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl<T: GraphicsApi> Render<T> {
self.upload_texture(sprite.tex_id)?;

self.graphics.draw_rect(&sprite.transform, sprite.tex_id)?;

}
Ok(true)
} else {
Expand Down
44 changes: 44 additions & 0 deletions client/shared/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,47 @@ pub fn wake_up_at(ptr: *mut i32) -> bool {

(unsafe { llvm_atomic_notify(ptr, -1) }) > 0
}

extern "C" {
#[link_name = "llvm.wasm.atomic.wait.i32"]
/// see https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait-and-notify-operators
pub fn llvm_atomic_wait_i32(ptr: *mut i32, exp: i32, timeout: i64) -> i32;

#[link_name = "llvm.wasm.atomic.notify"]
/// see https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait-and-notify-operators
fn llvm_atomic_notify(ptr: *mut i32, cnt: i32) -> i32;
}

pub unsafe fn atomic_write_u8(ptr: *mut u8, v: u8) {
(*(ptr as *mut core::sync::atomic::AtomicU8)).store(v, core::sync::atomic::Ordering::SeqCst)
}

pub unsafe fn atomic_read_u8(ptr: *const u8) -> u8 {
(*(ptr as *const core::sync::atomic::AtomicU8)).load(core::sync::atomic::Ordering::SeqCst)
}

pub unsafe fn atomic_read_i32(ptr: *const i32) -> i32 {
(*(ptr as *const core::sync::atomic::AtomicI32)).load(core::sync::atomic::Ordering::SeqCst)
}

pub unsafe fn atomic_write_u32(ptr: *mut u32, v: u32) {
(*(ptr as *mut core::sync::atomic::AtomicU32)).store(v, core::sync::atomic::Ordering::SeqCst)
}

pub unsafe fn atomic_read_u32(ptr: *const u32) -> u32 {
(*(ptr as *const core::sync::atomic::AtomicU32)).load(core::sync::atomic::Ordering::SeqCst)
}

pub fn wait_until_wake_up_at(ptr: *mut i32) {
let res = unsafe { llvm_atomic_wait_i32(ptr, atomic_read_i32(ptr), -1) };
debug_assert!(res == 0)
}

/// performs a notify at a given address and return the count of waiters
pub fn wake_up_at(ptr: *mut i32) -> bool {
// Documented at https://tc39.es/ecma262/#sec-atomics.notify
// and https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#wait-and-notify-operators.
// The notify function wakes all waiters up.

(unsafe { llvm_atomic_notify(ptr, -1) }) > 0
}

0 comments on commit 3310940

Please sign in to comment.