Files
gf/os/gfpool/gfpool.go

42 lines
1.4 KiB
Go
Raw Permalink Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
2018-09-17 18:43:59 +08:00
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
2018-09-17 18:43:59 +08:00
2019-01-16 13:02:59 +08:00
// Package gfpool provides io-reusable pool for file pointer.
2018-09-17 18:43:59 +08:00
package gfpool
import (
2021-11-15 20:26:31 +08:00
"os"
"time"
2021-10-11 21:41:56 +08:00
"github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/container/gpool"
"github.com/gogf/gf/v2/container/gtype"
2018-09-17 18:43:59 +08:00
)
2021-11-15 20:26:31 +08:00
// Pool pointer pool.
2018-09-17 18:43:59 +08:00
type Pool struct {
id *gtype.Int // Pool id, which is used to mark this pool whether recreated.
pool *gpool.Pool // Underlying pool.
init *gtype.Bool // Whether initialized, used for marking this file added to fsnotify, and it can only be added just once.
ttl time.Duration // Time to live for file pointer items.
2018-09-17 18:43:59 +08:00
}
// File is an item in the pool.
2018-09-17 18:43:59 +08:00
type File struct {
*os.File // Underlying file pointer.
stat os.FileInfo // State of current file pointer.
pid int // Belonging pool id, which is set when file pointer created. It's used to check whether the pool is recreated.
pool *Pool // Belonging ool.
flag int // Flash for opening file.
perm os.FileMode // Permission for opening file.
path string // Absolute path of the file.
2018-09-17 18:43:59 +08:00
}
2019-06-01 19:34:03 +08:00
var (
// Global file pointer pool.
pools = gmap.NewStrAnyMap(true)
2019-06-01 19:34:03 +08:00
)