mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
cgen: move closure C code to V code under vlib/builtin/closure/ (#24912)
This commit is contained in:
parent
a08ea74167
commit
2d87ac4837
17 changed files with 719 additions and 311 deletions
53
vlib/builtin/closure/closure_windows.c.v
Normal file
53
vlib/builtin/closure/closure_windows.c.v
Normal file
|
@ -0,0 +1,53 @@
|
|||
module closure
|
||||
|
||||
#include <synchapi.h>
|
||||
|
||||
struct ClosureMutex {
|
||||
closure_mtx C.SRWLOCK
|
||||
}
|
||||
|
||||
@[inline]
|
||||
fn closure_alloc_platform() &u8 {
|
||||
p := &u8(C.VirtualAlloc(0, g_closure.v_page_size * 2, C.MEM_COMMIT | C.MEM_RESERVE,
|
||||
C.PAGE_READWRITE))
|
||||
return p
|
||||
}
|
||||
|
||||
@[inline]
|
||||
fn closure_memory_protect_platform(ptr voidptr, size isize, attr MemoryProtectAtrr) {
|
||||
mut tmp := u32(0)
|
||||
match attr {
|
||||
.read_exec {
|
||||
_ := C.VirtualProtect(ptr, size, C.PAGE_EXECUTE_READ, &tmp)
|
||||
}
|
||||
.read_write {
|
||||
_ := C.VirtualProtect(ptr, size, C.PAGE_READWRITE, &tmp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@[inline]
|
||||
fn get_page_size_platform() int {
|
||||
// Determine system page size
|
||||
mut si := C.SYSTEM_INFO{}
|
||||
C.GetNativeSystemInfo(&si)
|
||||
|
||||
// Calculate required allocation size
|
||||
page_size := int(si.dwPageSize) * (((assumed_page_size - 1) / int(si.dwPageSize)) + 1)
|
||||
return page_size
|
||||
}
|
||||
|
||||
@[inline]
|
||||
fn closure_mtx_lock_init_platform() {
|
||||
C.InitializeSRWLock(&g_closure.closure_mtx)
|
||||
}
|
||||
|
||||
@[inline]
|
||||
fn closure_mtx_lock_platform() {
|
||||
C.AcquireSRWLockExclusive(&g_closure.closure_mtx)
|
||||
}
|
||||
|
||||
@[inline]
|
||||
fn closure_mtx_unlock_platform() {
|
||||
C.ReleaseSRWLockExclusive(&g_closure.closure_mtx)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue