Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
045552aa
Unverified
Commit
045552aa
authored
Feb 24, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxccontainer: lxc_container_{get,put}()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
70849dc2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
+20
-13
lxccontainer.c
src/lxc/lxccontainer.c
+20
-13
No files found.
src/lxc/lxccontainer.c
View file @
045552aa
...
@@ -281,19 +281,21 @@ static void lxc_container_free(struct lxc_container *c)
...
@@ -281,19 +281,21 @@ static void lxc_container_free(struct lxc_container *c)
free
(
c
);
free
(
c
);
}
}
/*
/* Consider the following case:
* Consider the following case:
*
freer | racing get()er
* |====================================================================|
==================================================================
* | freer | racing get()er |
lxc_container_put() | lxc_container_get()
* |====================================================================|
\ lxclock(c->privlock) | c->numthreads < 1? (no)
* | lxc_container_put() | lxc_container_get() |
\ c->numthreads = 0 | \ lxclock(c->privlock) -> waits
* | \ lxclock(c->privlock) | c->numthreads < 1? (no) |
\ lxcunlock() | \
* | \ c->numthreads = 0 | \ lxclock(c->privlock) -> waits |
\ lxc_container_free() | \ lxclock() returns
* | \ lxcunlock() | \ |
| \ c->numthreads < 1 -> return 0
* | \ lxc_container_free() | \ lxclock() returns |
\ \ (free stuff) |
* | | \ c->numthreads < 1 -> return 0 |
\ \ sem_destroy(privlock) |
* | \ \ (free stuff) | |
* | \ \ sem_destroy(privlock) | |
* |_______________________________|____________________________________|
*
* When the get()er checks numthreads the first time, one of the following
* When the get()er checks numthreads the first time, one of the following
* is true:
* is true:
* 1. freer has set numthreads = 0. get() returns 0
* 1. freer has set numthreads = 0. get() returns 0
...
@@ -326,6 +328,7 @@ int lxc_container_get(struct lxc_container *c)
...
@@ -326,6 +328,7 @@ int lxc_container_get(struct lxc_container *c)
c
->
numthreads
++
;
c
->
numthreads
++
;
container_mem_unlock
(
c
);
container_mem_unlock
(
c
);
return
1
;
return
1
;
}
}
...
@@ -333,14 +336,18 @@ int lxc_container_put(struct lxc_container *c)
...
@@ -333,14 +336,18 @@ int lxc_container_put(struct lxc_container *c)
{
{
if
(
!
c
)
if
(
!
c
)
return
-
1
;
return
-
1
;
if
(
container_mem_lock
(
c
))
if
(
container_mem_lock
(
c
))
return
-
1
;
return
-
1
;
if
(
--
c
->
numthreads
<
1
)
{
if
(
--
c
->
numthreads
<
1
)
{
container_mem_unlock
(
c
);
container_mem_unlock
(
c
);
lxc_container_free
(
c
);
lxc_container_free
(
c
);
return
1
;
return
1
;
}
}
container_mem_unlock
(
c
);
container_mem_unlock
(
c
);
return
0
;
return
0
;
}
}
...
...
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