本文整理汇总了Golang中syscall.UnmapViewOfFile函数的典型用法代码示例。如果您正苦于以下问题:Golang UnmapViewOfFile函数的具体用法?Golang UnmapViewOfFile怎么用?Golang UnmapViewOfFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UnmapViewOfFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: munmap
func munmap(b []byte) (err error) {
m := MMap(b)
dh := m.header()
addr := dh.Data
length := uintptr(dh.Len)
flush(addr, length)
err = syscall.UnmapViewOfFile(addr)
if err != nil {
return err
}
handleLock.Lock()
defer handleLock.Unlock()
handle, ok := handleMap[addr]
if !ok {
// should be impossible; we would've errored above
return errors.New("unknown base address")
}
delete(handleMap, addr)
e := syscall.CloseHandle(syscall.Handle(handle))
return os.NewSyscallError("CloseHandle", e)
}
示例2: munmap
// munmap Windows implementation
// Based on: https://github.com/edsrzf/mmap-go
// Based on: https://github.com/boltdb/bolt/bolt_windows.go
func munmap(b []byte) (err error) {
handleLock.Lock()
defer handleLock.Unlock()
addr := (uintptr)(unsafe.Pointer(&b[0]))
if err := syscall.UnmapViewOfFile(addr); err != nil {
return os.NewSyscallError("UnmapViewOfFile", err)
}
handle, ok := handleMap[addr]
if !ok {
// should be impossible; we would've seen the error above
return errors.New("unknown base address")
}
delete(handleMap, addr)
e := syscall.CloseHandle(syscall.Handle(handle))
if e != nil {
return os.NewSyscallError("CloseHandle", e)
}
file, ok := fileMap[addr]
if !ok {
// should be impossible; we would've seen the error above
return errors.New("unknown base address")
}
delete(fileMap, addr)
e = file.Close()
if e != nil {
return errors.New("close file" + e.Error())
}
return nil
}
示例3: unmmapFile
func unmmapFile(m *mmapData) error {
err := syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&m.d[0])))
if err != nil {
return err
}
return m.f.Close()
}
示例4: unmap
func (m *mmap) unmap() error {
slcHead := (*reflect.SliceHeader)(unsafe.Pointer(&m.buf))
err := syscall.UnmapViewOfFile(slcHead.Data)
if err != nil {
return err
}
return os.NewSyscallError("CloseHandle", syscall.CloseHandle(syscall.Handle(m.handle)))
}
示例5: munmap
// munmap unmaps a pointer from a file.
// Based on: https://github.com/edsrzf/mmap-go
func munmap(db *DB) error {
if db.data == nil {
return nil
}
addr := (uintptr)(unsafe.Pointer(&db.data[0]))
if err := syscall.UnmapViewOfFile(addr); err != nil {
return os.NewSyscallError("UnmapViewOfFile", err)
}
return nil
}
示例6: unmap
func unmap(addr, len uintptr) error {
if err := syscall.UnmapViewOfFile(addr); err != nil {
return err
}
handleLock.Lock()
defer handleLock.Unlock()
handle := handleMap[addr]
delete(handleMap, addr)
return os.NewSyscallError("CloseHandle", syscall.CloseHandle(syscall.Handle(handle)))
}
示例7: unmmapFile
func unmmapFile(mm *mmapData) {
err := syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&mm.d[0])))
if err != nil {
log.Fatal(err)
}
err2 := syscall.CloseHandle(syscall.Handle(mm.h))
if err2 != nil {
log.Fatal(err2)
}
err3 := mm.f.Close()
if err3 != nil {
log.Fatal(err3)
}
}
示例8: Close
// Close closes the reader.
func (r *ReaderAt) Close() error {
if r.data == nil {
return nil
}
data := r.data
r.data = nil
if debug {
var p *byte
if len(data) != 0 {
p = &data[0]
}
println("munmap", r, p)
}
runtime.SetFinalizer(r, nil)
return syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&data[0])))
}
示例9: unmap
func unmap(addr, len uintptr) error {
flush(addr, len)
err := syscall.UnmapViewOfFile(addr)
if err != nil {
return err
}
handleLock.Lock()
defer handleLock.Unlock()
handle, ok := handleMap[addr]
if !ok {
// should be impossible; we would've errored above
return errors.New("unknown base address")
}
delete(handleMap, addr)
e := syscall.CloseHandle(syscall.Handle(handle))
return os.NewSyscallError("CloseHandle", e)
}
示例10: unmap
func unmap(addr, len uintptr) os.Error {
flush(addr, len)
errno := syscall.UnmapViewOfFile(addr)
if errno != 0 {
return os.NewSyscallError("UnmapViewOfFile", errno)
}
handleLock.Lock()
defer handleLock.Unlock()
handle, ok := handleMap[addr]
if !ok {
// should be impossible; we would've errored above
return os.NewError("unknown base address")
}
handleMap[addr] = 0, false
e := syscall.CloseHandle(handle)
return os.NewSyscallError("CloseHandle", e)
}
示例11: unmap
func unmap(p []byte) error {
addr := uintptr(unsafe.Pointer(&p[0]))
syscall.FlushViewOfFile(addr, uintptr(len(p)))
err := syscall.UnmapViewOfFile(addr)
if err != nil {
return err
}
handleLock.Lock()
defer handleLock.Unlock()
handle, ok := handleMap[addr]
if !ok {
// should be impossible; we would've errored above
return errors.New("unknown base address")
}
delete(handleMap, addr)
e := syscall.CloseHandle(syscall.Handle(handle))
return os.NewSyscallError("CloseHandle", e)
}
示例12: unmap_file
// Implement munmap for windows
func unmap_file(data []byte) error {
// Use unsafe to get the buffer address
addr := uintptr(unsafe.Pointer(&data[0]))
// retrieve the mapping handle
win_mapper_mutex.Lock()
h := win_mapper_handle[addr]
delete(win_mapper_handle, addr)
win_mapper_mutex.Unlock()
// unmap file view
err := syscall.UnmapViewOfFile(addr)
// close the mapping handle
if err == nil {
err = syscall.CloseHandle(h)
}
return err
}
示例13: unmap
func unmap(addr, len uintptr) error {
flush(addr, len)
// Lock the UnmapViewOfFile along with the handleMap deletion.
// As soon as we unmap the view, the OS is free to give the
// same addr to another new map. We don't want another goroutine
// to insert and remove the same addr into handleMap while
// we're trying to remove our old addr/handle pair.
handleLock.Lock()
defer handleLock.Unlock()
err := syscall.UnmapViewOfFile(addr)
if err != nil {
return err
}
handle, ok := handleMap[addr]
if !ok {
// should be impossible; we would've errored above
return errors.New("unknown base address")
}
delete(handleMap, addr)
e := syscall.CloseHandle(syscall.Handle(handle))
return os.NewSyscallError("CloseHandle", e)
}
示例14: Close
func (agent Pagent) Close() {
defer syscall.CloseHandle(agent.Hwnd)
defer syscall.CloseHandle(agent.Fmap)
defer syscall.UnmapViewOfFile(agent.SharedMemory)
}
示例15: destroy
func (m *Mapping) destroy() {
syscall.UnmapViewOfFile(m.addr)
syscall.CloseHandle(m.mapping)
}