Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
288814d3
Commit
288814d3
authored
Oct 03, 2023
by
Michael Yang
Browse files
fix ref counts
parent
04733438
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
+13
-6
server/download.go
server/download.go
+13
-6
No files found.
server/download.go
View file @
288814d3
...
@@ -36,7 +36,7 @@ type blobDownload struct {
...
@@ -36,7 +36,7 @@ type blobDownload struct {
done
chan
struct
{}
done
chan
struct
{}
context
.
CancelFunc
context
.
CancelFunc
ref
Count
atomic
.
Int32
ref
erences
atomic
.
Int32
}
}
type
blobDownloadPart
struct
{
type
blobDownloadPart
struct
{
...
@@ -241,8 +241,19 @@ func (b *blobDownload) Write(p []byte) (n int, err error) {
...
@@ -241,8 +241,19 @@ func (b *blobDownload) Write(p []byte) (n int, err error) {
return
n
,
nil
return
n
,
nil
}
}
func
(
b
*
blobDownload
)
acquire
()
{
b
.
references
.
Add
(
1
)
}
func
(
b
*
blobDownload
)
release
()
{
if
b
.
references
.
Add
(
-
1
)
==
0
{
b
.
CancelFunc
()
}
}
func
(
b
*
blobDownload
)
Wait
(
ctx
context
.
Context
,
fn
func
(
api
.
ProgressResponse
))
error
{
func
(
b
*
blobDownload
)
Wait
(
ctx
context
.
Context
,
fn
func
(
api
.
ProgressResponse
))
error
{
b
.
refCount
.
Add
(
1
)
b
.
acquire
()
defer
b
.
release
()
ticker
:=
time
.
NewTicker
(
60
*
time
.
Millisecond
)
ticker
:=
time
.
NewTicker
(
60
*
time
.
Millisecond
)
for
{
for
{
...
@@ -253,10 +264,6 @@ func (b *blobDownload) Wait(ctx context.Context, fn func(api.ProgressResponse))
...
@@ -253,10 +264,6 @@ func (b *blobDownload) Wait(ctx context.Context, fn func(api.ProgressResponse))
}
}
case
<-
ticker
.
C
:
case
<-
ticker
.
C
:
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
if
b
.
refCount
.
Add
(
-
1
)
==
0
{
b
.
CancelFunc
()
}
return
ctx
.
Err
()
return
ctx
.
Err
()
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment