-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.go
64 lines (52 loc) · 1.28 KB
/
io.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
// "fmt"
"io/ioutil"
"log"
"sync/atomic"
)
type io_resp struct {
dir string
data []byte
}
func new_reader(c_query_reader chan string, f_query_reader chan int32) {
var send_in_tmp, send_in_count, send_out_count, send_gofiles int32 = 0, 0, 0, -1
go func() {
var file string
var ok bool
L:
for {
select {
case file, ok = <-c_query_reader:
if !ok {
break L
}
atomic.AddInt32(&send_in_tmp, 1)
if !is_exist(file) {
log.Println("new_reader os.Stat() failed")
break
}
data, err := ioutil.ReadFile(file)
if err != nil {
log.Println("can not read file")
break
}
c_reader_scan <- &io_resp{file, data}
atomic.AddInt32(&send_out_count, 1)
atomic.StoreInt32(&send_in_count, send_in_tmp)
case all := <-f_query_reader:
atomic.StoreInt32(&send_gofiles, all)
}
if send_in_count == send_gofiles {
//test
// fmt.Println("io finished:------------------", send_out_count, "in", send_in_count)
f_reader_scan <- send_out_count
atomic.StoreInt32(&send_in_count, 0)
atomic.StoreInt32(&send_gofiles, -1)
//rewrite the storage if anything update
g_wg.Add(1)
c_storage_rewrite <- true
}
}
}()
}