]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Make use of levelmu to prioritize client.TorrentReadAt
authorMatt Joiner <anacrolix@gmail.com>
Sun, 24 Aug 2014 19:23:28 +0000 (05:23 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 24 Aug 2014 19:23:28 +0000 (05:23 +1000)
client.go

index 86f908818c1fe354900964d6faae75997a1c429f..1f8cf72427647af41c4a91dc739054bb529ebd63 100644 (file)
--- a/client.go
+++ b/client.go
@@ -31,6 +31,8 @@ import (
        "syscall"
        "time"
 
+       "bitbucket.org/anacrolix/go.torrent/util/levelmu"
+
        "bitbucket.org/anacrolix/go.torrent/dht"
        . "bitbucket.org/anacrolix/go.torrent/util"
 
@@ -98,7 +100,7 @@ type Client struct {
        downloadStrategy DownloadStrategy
        dHT              *dht.Server
 
-       mu    sync.Mutex
+       mu    levelmu.LevelMutex
        event sync.Cond
        quit  chan struct{}
 
@@ -143,7 +145,7 @@ func (cl *Client) WriteStatus(w io.Writer) {
 // Read torrent data at the given offset. Returns ErrDataNotReady if the data
 // isn't available.
 func (cl *Client) TorrentReadAt(ih InfoHash, off int64, p []byte) (n int, err error) {
-       cl.mu.Lock()
+       cl.mu.LevelLock(1)
        defer cl.mu.Unlock()
        t := cl.torrent(ih)
        if t == nil {
@@ -206,6 +208,7 @@ func NewClient(cfg *Config) (cl *Client, err error) {
                torrents: make(map[InfoHash]*torrent),
        }
        cl.event.L = &cl.mu
+       cl.mu.Init(2)
 
        o := copy(cl.peerID[:], BEP20)
        _, err = rand.Read(cl.peerID[o:])