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
41f68357
Commit
41f68357
authored
Nov 13, 2013
by
S.Çağlar Onur
Committed by
Serge Hallyn
Nov 14, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gather all locking related code into src/lxc/lxclock.c
Signed-off-by:
S.Çağlar Onur
<
caglar@10ur.org
>
Signed-off-by:
Serge Hallyn
<
serge.hallyn@ubuntu.com
>
parent
b466dc33
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
69 deletions
+65
-69
lxclock.c
src/lxc/lxclock.c
+61
-13
lxclock.h
src/lxc/lxclock.h
+3
-0
utils.c
src/lxc/utils.c
+1
-56
No files found.
src/lxc/lxclock.c
View file @
41f68357
...
@@ -31,6 +31,10 @@
...
@@ -31,6 +31,10 @@
#include <lxc/log.h>
#include <lxc/log.h>
#include <lxc/lxccontainer.h>
#include <lxc/lxccontainer.h>
#ifdef MUTEX_DEBUGGING
#include <execinfo.h>
#endif
#define OFLAG (O_CREAT | O_RDWR)
#define OFLAG (O_CREAT | O_RDWR)
#define SEMMODE 0660
#define SEMMODE 0660
#define SEMVALUE 1
#define SEMVALUE 1
...
@@ -40,10 +44,55 @@ lxc_log_define(lxc_lock, lxc);
...
@@ -40,10 +44,55 @@ lxc_log_define(lxc_lock, lxc);
#ifdef MUTEX_DEBUGGING
#ifdef MUTEX_DEBUGGING
pthread_mutex_t
thread_mutex
=
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
;
pthread_mutex_t
thread_mutex
=
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
;
pthread_mutex_t
static_mutex
=
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
;
inline
void
dump_stacktrace
(
void
)
{
void
*
array
[
MAX_STACKDEPTH
];
size_t
size
;
char
**
strings
;
size_t
i
;
size
=
backtrace
(
array
,
MAX_STACKDEPTH
);
strings
=
backtrace_symbols
(
array
,
size
);
// Using fprintf here as our logging module is not thread safe
fprintf
(
stderr
,
"
\t
Obtained %zd stack frames.
\n
"
,
size
);
for
(
i
=
0
;
i
<
size
;
i
++
)
fprintf
(
stderr
,
"
\t\t
%s
\n
"
,
strings
[
i
]);
free
(
strings
);
}
#else
#else
pthread_mutex_t
thread_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
pthread_mutex_t
thread_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
pthread_mutex_t
static_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
inline
void
dump_stacktrace
(
void
)
{;}
#endif
#endif
void
lock_mutex
(
pthread_mutex_t
*
l
)
{
int
ret
;
if
((
ret
=
pthread_mutex_lock
(
l
))
!=
0
)
{
fprintf
(
stderr
,
"pthread_mutex_lock returned:%d %s"
,
ret
,
strerror
(
ret
));
dump_stacktrace
();
exit
(
1
);
}
}
void
unlock_mutex
(
pthread_mutex_t
*
l
)
{
int
ret
;
if
((
ret
=
pthread_mutex_unlock
(
l
))
!=
0
)
{
fprintf
(
stderr
,
"pthread_mutex_lock returned:%d %s"
,
ret
,
strerror
(
ret
));
dump_stacktrace
();
exit
(
1
);
}
}
static
char
*
lxclock_name
(
const
char
*
p
,
const
char
*
n
)
static
char
*
lxclock_name
(
const
char
*
p
,
const
char
*
n
)
{
{
int
ret
;
int
ret
;
...
@@ -267,24 +316,23 @@ void lxc_putlock(struct lxc_lock *l)
...
@@ -267,24 +316,23 @@ void lxc_putlock(struct lxc_lock *l)
void
process_lock
(
void
)
void
process_lock
(
void
)
{
{
int
ret
;
lock_mutex
(
&
thread_mutex
);
if
((
ret
=
pthread_mutex_lock
(
&
thread_mutex
))
!=
0
)
{
ERROR
(
"pthread_mutex_lock returned:%d %s"
,
ret
,
strerror
(
ret
));
dump_stacktrace
();
exit
(
1
);
}
}
}
void
process_unlock
(
void
)
void
process_unlock
(
void
)
{
{
int
ret
;
unlock_mutex
(
&
thread_mutex
);
}
if
((
ret
=
pthread_mutex_unlock
(
&
thread_mutex
))
!=
0
)
{
/* Protects static const values inside the lxc_global_config_value funtion */
ERROR
(
"pthread_mutex_unlock returned:%d %s"
,
ret
,
strerror
(
ret
));
void
static_lock
(
void
)
dump_stacktrace
();
{
exit
(
1
);
lock_mutex
(
&
static_mutex
);
}
}
void
static_unlock
(
void
)
{
unlock_mutex
(
&
static_mutex
);
}
}
int
container_mem_lock
(
struct
lxc_container
*
c
)
int
container_mem_lock
(
struct
lxc_container
*
c
)
...
...
src/lxc/lxclock.h
View file @
41f68357
...
@@ -87,6 +87,9 @@ extern void lxc_putlock(struct lxc_lock *l);
...
@@ -87,6 +87,9 @@ extern void lxc_putlock(struct lxc_lock *l);
extern
void
process_lock
(
void
);
extern
void
process_lock
(
void
);
extern
void
process_unlock
(
void
);
extern
void
process_unlock
(
void
);
extern
void
static_lock
(
void
);
extern
void
static_unlock
(
void
);
struct
lxc_container
;
struct
lxc_container
;
extern
int
container_mem_lock
(
struct
lxc_container
*
c
);
extern
int
container_mem_lock
(
struct
lxc_container
*
c
);
extern
void
container_mem_unlock
(
struct
lxc_container
*
c
);
extern
void
container_mem_unlock
(
struct
lxc_container
*
c
);
...
...
src/lxc/utils.c
View file @
41f68357
...
@@ -39,11 +39,6 @@
...
@@ -39,11 +39,6 @@
#include <sys/types.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <assert.h>
#include <assert.h>
#include <pthread.h>
#ifdef MUTEX_DEBUGGING
#include <execinfo.h>
#endif
#ifndef HAVE_GETLINE
#ifndef HAVE_GETLINE
#ifdef HAVE_FGETLN
#ifdef HAVE_FGETLN
...
@@ -59,57 +54,6 @@
...
@@ -59,57 +54,6 @@
lxc_log_define
(
lxc_utils
,
lxc
);
lxc_log_define
(
lxc_utils
,
lxc
);
#ifdef MUTEX_DEBUGGING
static
pthread_mutex_t
static_mutex
=
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
;
inline
void
dump_stacktrace
(
void
)
{
void
*
array
[
MAX_STACKDEPTH
];
size_t
size
;
char
**
strings
;
size_t
i
;
size
=
backtrace
(
array
,
MAX_STACKDEPTH
);
strings
=
backtrace_symbols
(
array
,
size
);
// Using fprintf here as our logging module is not thread safe
fprintf
(
stderr
,
"
\t
Obtained %zd stack frames.
\n
"
,
size
);
for
(
i
=
0
;
i
<
size
;
i
++
)
fprintf
(
stderr
,
"
\t\t
%s
\n
"
,
strings
[
i
]);
free
(
strings
);
}
#else
static
pthread_mutex_t
static_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
inline
void
dump_stacktrace
(
void
)
{;}
#endif
/* Protects static const values inside the lxc_global_config_value funtion */
static
void
static_lock
(
void
)
{
int
ret
;
if
((
ret
=
pthread_mutex_lock
(
&
static_mutex
))
!=
0
)
{
ERROR
(
"pthread_mutex_lock returned:%d %s"
,
ret
,
strerror
(
ret
));
dump_stacktrace
();
exit
(
1
);
}
}
static
void
static_unlock
(
void
)
{
int
ret
;
if
((
ret
=
pthread_mutex_unlock
(
&
static_mutex
))
!=
0
)
{
ERROR
(
"pthread_mutex_unlock returned:%d %s"
,
ret
,
strerror
(
ret
));
dump_stacktrace
();
exit
(
1
);
}
}
static
int
_recursive_rmdir_onedev
(
char
*
dirname
,
dev_t
pdev
)
static
int
_recursive_rmdir_onedev
(
char
*
dirname
,
dev_t
pdev
)
{
{
struct
dirent
dirent
,
*
direntp
;
struct
dirent
dirent
,
*
direntp
;
...
@@ -392,6 +336,7 @@ out:
...
@@ -392,6 +336,7 @@ out:
if
(
fin
)
if
(
fin
)
fclose
(
fin
);
fclose
(
fin
);
process_unlock
();
process_unlock
();
static_lock
();
static_lock
();
value
=
values
[
i
];
value
=
values
[
i
];
static_unlock
();
static_unlock
();
...
...
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