当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Munmap函数代码示例

本文整理汇总了Golang中syscall.Munmap函数的典型用法代码示例。如果您正苦于以下问题:Golang Munmap函数的具体用法?Golang Munmap怎么用?Golang Munmap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Munmap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Msync

func (t *FsyncErrorTest) Msync() {
	var err error

	// On OS X, msync does not cause SyncFile.
	if isDarwin {
		return
	}

	// Open the file.
	t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_RDWR, 0)
	AssertEq(nil, err)

	// mmap the file.
	data, err := syscall.Mmap(
		int(t.f1.Fd()), 0, 4,
		syscall.PROT_READ|syscall.PROT_WRITE,
		syscall.MAP_SHARED)

	AssertEq(nil, err)
	defer syscall.Munmap(data)

	// msync the mapping.
	err = msync(data)
	ExpectThat(err, Error(HasSubstr("no such file")))

	// Unmap.
	err = syscall.Munmap(data)
	AssertEq(nil, err)
}
开发者ID:andrewgaul,项目名称:fuse,代码行数:29,代码来源:flush_fs_test.go

示例2: Close

func (p pack) Close() {
	if p.p != nil {
		_ = syscall.Munmap(p.p.data)
		_ = p.pFile.Close()
	}
	_ = syscall.Munmap(p.idx.data)
	_ = p.idxFile.Close()
}
开发者ID:jamesr,项目名称:ggit,代码行数:8,代码来源:db.go

示例3: Mmap_WithMsync_MunmapBeforeClose

func (t *NoErrorsTest) Mmap_WithMsync_MunmapBeforeClose() {
	var n int
	var err error

	var expectedFsyncs []interface{}

	// Open the file.
	t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_RDWR, 0)
	AssertEq(nil, err)

	// Write some contents to the file.
	n, err = t.f1.Write([]byte("taco"))
	AssertEq(nil, err)
	AssertEq(4, n)

	// mmap the file.
	data, err := syscall.Mmap(
		int(t.f1.Fd()), 0, 4,
		syscall.PROT_READ|syscall.PROT_WRITE,
		syscall.MAP_SHARED)

	AssertEq(nil, err)
	defer syscall.Munmap(data)

	AssertEq("taco", string(data))

	// Modify the contents.
	data[0] = 'p'

	// msync. This causes an fsync, except on OS X (cf.
	// https://github.com/osxfuse/osxfuse/issues/202).
	err = msync(data)
	ExpectEq(nil, err)

	if !isDarwin {
		expectedFsyncs = append(expectedFsyncs, "paco")
	}

	ExpectThat(t.getFlushes(), ElementsAre())
	ExpectThat(t.getFsyncs(), ElementsAre(expectedFsyncs...))

	// Unmap. This does not cause anything.
	err = syscall.Munmap(data)
	AssertEq(nil, err)

	ExpectThat(t.getFlushes(), ElementsAre())
	ExpectThat(t.getFsyncs(), ElementsAre(expectedFsyncs...))

	// Close the file. We should now see a flush with the modified contents, even
	// on OS X.
	err = t.f1.Close()
	t.f1 = nil
	AssertEq(nil, err)

	ExpectThat(t.getFlushes(), ElementsAre("paco"))
	ExpectThat(t.getFsyncs(), ElementsAre(expectedFsyncs...))
}
开发者ID:andrewgaul,项目名称:fuse,代码行数:57,代码来源:flush_fs_test.go

示例4: Mmap_NoMsync_MunmapBeforeClose

func (t *NoErrorsTest) Mmap_NoMsync_MunmapBeforeClose() {
	var n int
	var err error

	// Open the file.
	t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_RDWR, 0)
	AssertEq(nil, err)

	// Write some contents to the file.
	n, err = t.f1.Write([]byte("taco"))
	AssertEq(nil, err)
	AssertEq(4, n)

	// mmap the file.
	data, err := syscall.Mmap(
		int(t.f1.Fd()), 0, 4,
		syscall.PROT_READ|syscall.PROT_WRITE,
		syscall.MAP_SHARED)

	AssertEq(nil, err)
	defer syscall.Munmap(data)

	AssertEq("taco", string(data))

	// Modify the contents.
	data[0] = 'p'

	// Unmap.
	err = syscall.Munmap(data)
	AssertEq(nil, err)

	// munmap does not cause a flush.
	ExpectThat(t.getFlushes(), ElementsAre())
	ExpectThat(t.getFsyncs(), ElementsAre())

	// Close the file. We should see a flush. On Darwin, this will contain out of
	// date contents (cf. https://github.com/osxfuse/osxfuse/issues/202).
	err = t.f1.Close()
	t.f1 = nil
	AssertEq(nil, err)

	if isDarwin {
		ExpectThat(t.getFlushes(), ElementsAre("taco"))
		ExpectThat(t.getFsyncs(), ElementsAre())
	} else {
		ExpectThat(t.getFlushes(), ElementsAre("paco"))
		ExpectThat(t.getFsyncs(), ElementsAre())
	}
}
开发者ID:andrewgaul,项目名称:fuse,代码行数:49,代码来源:flush_fs_test.go

示例5: Close

func (r *Runner) Close() (first error) {
	if r.stack != nil {
		if err := syscall.Munmap(r.stack); err != nil && first == nil {
			first = err
		}
	}

	if r.globalsMemory != nil {
		if err := syscall.Munmap(r.globalsMemory); err != nil && first == nil {
			first = err
		}
	}

	return
}
开发者ID:tsavola,项目名称:wag,代码行数:15,代码来源:runner.go

示例6: Close

// Close closes the pisearch object.  Note:  This code is not thread-safe.
// The caller must guarantee that no other threads are accessing the object.
func (p *Pisearch) Close() {
	// I'm writing the code this way
	// as a reminder to my future-self that, if you really want
	// to have threads playing willy-nilly, you'll need to guard
	// piMap and idxMap.
	p.numDigits = 0
	tmp := p.piMap
	p.piMap = nil
	_ = syscall.Munmap(tmp)
	p.piFile.Close()
	tmp = p.idxMap
	p.idxMap = nil
	_ = syscall.Munmap(tmp)
	p.idxFile.Close()
}
开发者ID:magwain2,项目名称:pisearch3,代码行数:17,代码来源:pisearch.go

示例7: Close

// Close closes the pisearch object.  Note:  This code is not thread-safe.
// The caller must guarantee that no other threads are accessing the object.
func (pisearch *Pisearch) Close() {
	// I'm writing the code this way
	// as a reminder to my future-self that, if you really want
	// to have threads playing willy-nilly, you'll need to guard
	// filemap_ and idxmap_.
	pisearch.numDigits = 0
	tmp := pisearch.filemap_
	pisearch.filemap_ = nil
	_ = syscall.Munmap(tmp)
	pisearch.pifile_.Close()
	tmp = pisearch.idxmap_
	pisearch.idxmap_ = nil
	_ = syscall.Munmap(tmp)
	pisearch.idxfile_.Close()
}
开发者ID:purcaro,项目名称:pisearch,代码行数:17,代码来源:pisearch.go

示例8: unmmapFile

func unmmapFile(m *mmapData) error {
	if err := syscall.Munmap(m.o); err != nil {
		return err
	}

	return m.f.Close()
}
开发者ID:Rajat-Agrawal,项目名称:hound,代码行数:7,代码来源:mmap_bsd.go

示例9: main

func main() {
	const n = 4096 * 50 // size of shared memory
	t := int(1) * n
	fmt.Println("Total size of shared memory : ", t)

	// open device file
	mmap_file, err := os.OpenFile(device_file, os.O_RDWR, 0666)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer mmap_file.Close()

	// mmap memory
	mmap, err := syscall.Mmap(int(mmap_file.Fd()), 0, int(t),
		syscall.PROT_READ|syscall.PROT_WRITE,
		syscall.MAP_SHARED)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer syscall.Munmap(mmap)

	mmap_array := (*[n]byte)(unsafe.Pointer(&mmap[0]))
	fmt.Println(*mmap_array)

	// using memcpy to copy mmap memory buffer into program buffer
	mmap_buf := make([]byte, t)
	copy(mmap_buf, mmap_array[:])
	fmt.Println(mmap_buf)
}
开发者ID:prashants,项目名称:km,代码行数:31,代码来源:go_client.go

示例10: Close

// Unmaps the shared memory, closes the region and - if the region owns the
// underlying shm object - signals that the shm object can be unlinked
// when its unmapped by all processes.
func (r *region) Close() error {
	err := syscall.Munmap(r.bytes)
	if err != nil {
		rpcLog.Error("Failed to unmap memory: %s", err.Error())
		return err
	}

	err = r.fd.Close()
	if err != nil {
		rpcLog.Error("Failed to close shared memory handle: %s", err.Error())
		return err
	}

	if r.unlink {
		cname := C.CString(r.name)
		defer C.free(unsafe.Pointer(cname))
		_, err = C.shm_unlink(cname)
		if err != nil {
			rpcLog.Error("Failed to mark shm block for deletion: %s", err.Error())
			return err
		}
	}

	return nil
}
开发者ID:tcsc,项目名称:squaddie,代码行数:28,代码来源:shm.go

示例11: Open

// Open takes a string path to a MaxMind DB file and returns a Reader
// structure or an error. The database file is opened using a memory map. Use
// the Close method on the Reader object to return the resources to the
// system.
func Open(file string) (*Reader, error) {
	mapFile, err := os.Open(file)
	if err != nil {
		return nil, err
	}
	stats, err := mapFile.Stat()
	if err != nil {
		return nil, err
	}

	fileSize := int(stats.Size())
	mmap, err := syscall.Mmap(int(mapFile.Fd()), 0, fileSize, syscall.PROT_READ, syscall.MAP_SHARED)
	if err != nil {
		return nil, err
	}

	reader, err := FromBytes(mmap)
	if err != nil {
		syscall.Munmap(mmap)
		mapFile.Close()
		return nil, err
	}

	reader.file = mapFile
	return reader, nil
}
开发者ID:oxtoacart,项目名称:go-geoserve,代码行数:30,代码来源:reader.go

示例12: findModifiedAndUntracked

func findModifiedAndUntracked() (err error) {
	_, entries, _, data, err := ggit.MapIndexFile(".git/index")
	if err != nil {
		return err
	}
	defer syscall.Munmap(data)

	parseIgnored(".git/info/exclude")

	modified = make([]string, 0)
	untracked = make([]string, 0)
	ignorePatterns = make([]string, 0)

	err = walkDir(".", entries)

	/*
		err = filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
			return statusWalk(path, info, err, entries)
		})
	*/
	if err != nil {
		return err
	}
	return nil
}
开发者ID:jamesr,项目名称:ggit,代码行数:25,代码来源:status.go

示例13: Close

func (this *Bitmap) Close() error {

	this.Sync()

	syscall.Munmap(this.Data)
	return nil
}
开发者ID:wyh267,项目名称:FalconEngine,代码行数:7,代码来源:BitMap.go

示例14: seqMmapRead

// seqMmapRead does n sequential reads of records of size rsize using mmap and copy.
func seqMmapRead(fname string, rsize int, n int) (int, error) {
	f, err := os.Open(fname)
	if err != nil {
		return 0, err
	}
	defer f.Close()
	fi, err := f.Stat()
	if err != nil {
		return 0, err
	}
	fsize := int(fi.Size())
	data, err := syscall.Mmap(int(f.Fd()), 0, fsize, syscall.PROT_READ, syscall.MAP_FILE|syscall.MAP_SHARED)
	// syscall.Madvise(data, syscall.MADV_SEQUENTIAL)
	defer syscall.Munmap(data)
	buf := make([]byte, rsize)
	if n <= 0 || n > fsize/rsize {
		n = fsize / rsize
	}
	var i int
	for i = 0; i < n; i++ {
		offset := i * rsize
		copy(buf, data[offset:offset+len(buf)])
	}
	return i, nil
}
开发者ID:funkygao,项目名称:gafka,代码行数:26,代码来源:main.go

示例15: helperMmap

func helperMmap() {
	f, err := os.Create("child")
	if err != nil {
		log.Fatalf("Create: %v", err)
	}
	defer f.Close()

	data, err := syscall.Mmap(int(f.Fd()), 0, mmapSize, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED)
	if err != nil {
		log.Fatalf("Mmap: %v", err)
	}

	for i, b := range mmapWrites {
		data[i] = b
	}

	if err := syscallx.Msync(data, syscall.MS_SYNC); err != nil {
		log.Fatalf("Msync: %v", err)
	}

	if err := syscall.Munmap(data); err != nil {
		log.Fatalf("Munmap: %v", err)
	}

	if err := f.Sync(); err != nil {
		log.Fatalf("Fsync = %v", err)
	}

	err = f.Close()
	if err != nil {
		log.Fatalf("Close: %v", err)
	}
}
开发者ID:djbarber,项目名称:ipfs-hack,代码行数:33,代码来源:serve_test.go


注:本文中的syscall.Munmap函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。