]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
copy map
authorqydysky <qydysky@foxmail.com>
Wed, 20 Jan 2021 09:00:15 +0000 (17:00 +0800)
committerqydysky <qydysky@foxmail.com>
Wed, 20 Jan 2021 09:00:15 +0000 (17:00 +0800)
Reply/F.go
Reply/Reply.go
demo/main.go

index a5be923fbeb48959efcb959264767dc3b3fdbc65..d74f0134f5bf4530cb859640c3dc91c44aaf09d1 100644 (file)
@@ -506,6 +506,7 @@ func Danmuji_auto(sleep int) {
 
 type Autoskip struct {
        buf map[string]Autoskip_item
+       sync.Mutex
        now uint
        ticker *time.Ticker
        sync.Mutex
@@ -527,6 +528,7 @@ func init(){
                        <-autoskip.ticker.C
                        if len(autoskip.buf) == 0 {continue}
                        autoskip.now += 1
+                       autoskip.Lock()
                        for k,v := range autoskip.buf{
                                if v.Exprie <= autoskip.now {
                                        autoskip.Lock()
@@ -541,6 +543,12 @@ func init(){
                                        }
                                }
                        }
+                       {//copy map
+                               tmp := make(map[string]Autoskip_item)
+                               for k,v := range autoskip.buf {tmp[k] = v}
+                               autoskip.buf = tmp
+                       }
+                       autoskip.Unlock()                       
                }
        }()
 }
@@ -558,6 +566,8 @@ func Autoskipf(s string) uint {
                        return v.Num
                }
        }
+       autoskip.Lock()
+       defer autoskip.Unlock()
        {//设置
                autoskip.buf[s] = Autoskip_item{
                        Exprie:autoskip.now + 8,
index 5dec003fc07704a91f13827624f02558799eee4e..b91f6a09ae0b7b0fec5907a6b20e8a282bb7628f 100644 (file)
@@ -458,15 +458,20 @@ func (replyF) live(s string) {
 }
 
 //Msg-超级留言处理
-var sc_buf = make(map[string]bool)
+var sc_buf = make(map[string]struct{})
 func (replyF) super_chat_message(s string){
        id := p.Json().GetValFromS(s, "data.id");
        if id != nil {
                if _,ok := sc_buf[id.(string)];ok{return}
                if len(sc_buf) >= 10 {
                        for k,_ := range sc_buf {delete(sc_buf, k);break}
+                       {//copy map
+                               tmp := make(map[string]struct{})
+                               for k,v := range sc_buf {tmp[k] = v}
+                               sc_buf = tmp
+                       }
                }
-               sc_buf[id.(string)] = true
+               sc_buf[id.(string)] = struct{}{}
        }
        uname := p.Json().GetValFromS(s, "data.user_info.uname");
        price := p.Json().GetValFromS(s, "data.price");
index 0d24d2373187492870e86fd17d6e21e69ad5cb80..c7e8a479f17046f37edd72f44d283bab7337125e 100644 (file)
@@ -1,42 +1,36 @@
 package main
 
 import (
-       // "time"
+       "time"
+       "runtime"
        // "runtime/pprof"
-       // "os"
+       "os"
        // "log"
-       // "net/http"
-       // "fmt"
-       // _ "net/http/pprof"
+       "net/http"
+       "fmt"
+       _ "net/http/pprof"
+       "runtime/debug"
        // "github.com/skratchdot/open-golang/open"
        q "github.com/qydysky/bili_danmu"
 )
 
 func main() {
-       // go func() {
-       //      http.ListenAndServe("0.0.0.0:8899", nil)
-       // }()
+       go func() {
+               http.ListenAndServe("0.0.0.0:8899", nil)
+       }()
        // defer func(){
        //      open.Run("http://127.0.0.1:8899/debug/pprof/goroutine?debug=2")
        //      time.Sleep(time.Duration(3)*time.Second)
        // }()
-       // go func(){
-       //      // var memStats_old runtime.MemStats
-       //      for{
-       //              time.Sleep(time.Duration(10)*time.Second)
-       //              var memStats runtime.MemStats
-       //              runtime.ReadMemStats(&memStats)
-       //              fmt.Printf("=====\n")
-       //              // fmt.Printf("总内存:%v MB\n",memStats.Sys/1024e2/8)
-       //              fmt.Printf("GC次数:%v \n",memStats.NumGC)
-
-       //              fmt.Printf("堆 :%v %v MB\n",memStats.HeapInuse/1024e2/8,(memStats.HeapIdle - memStats.HeapReleased)/1024e2/8)
-
-       //              fmt.Printf("栈 :%v/%v MB\n",memStats.StackInuse/1024e2/8,memStats.StackSys/1024e2/8)
-       //              fmt.Printf("=====\n")
-       //              // memStats_old = memStats
-       //      }
-       // }()
+       go func(){
+               for{
+                       View()
+                       time.Sleep(time.Duration(60)*time.Second)
+                       {
+                               debug.FreeOSMemory()
+                       }
+               }
+       }()
        // f, err := os.OpenFile("cpu.pprof", os.O_RDWR|os.O_CREATE, 0644)
     // if err != nil {
     //     log.Fatal(err)
@@ -47,4 +41,15 @@ func main() {
        q.Demo()
 
        // pprof.StopCPUProfile()
+}
+
+func View(){
+       var memStats runtime.MemStats
+       runtime.ReadMemStats(&memStats)
+       fmt.Printf("=====\n")
+       fmt.Printf("PID:%d\n",os.Getpid())
+       fmt.Printf("总内存:%v MB\n",memStats.Alloc/1024e2/8)
+       fmt.Printf("GC次数:%v \n",memStats.NumGC)
+       fmt.Printf("堆 :%v %v MB\n",memStats.HeapInuse/1024e2/8,(memStats.HeapIdle - memStats.HeapReleased)/1024e2/8)
+       fmt.Printf("=====\n")
 }
\ No newline at end of file