Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
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
钟尚武
dlib
Commits
927743a1
Commit
927743a1
authored
Jun 19, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the global mutex construction for the get_current_dir() and set_current_dir()
routines more robust.
parent
d9cd30a6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
misc_api_kernel_1.cpp
dlib/misc_api/misc_api_kernel_1.cpp
+18
-3
No files found.
dlib/misc_api/misc_api_kernel_1.cpp
View file @
927743a1
...
...
@@ -33,7 +33,22 @@ namespace dlib
namespace
{
mutex
cwd_mutex
;
mutex
&
cwd_mutex
()
{
static
mutex
m
;
return
m
;
}
// Make sure the above mutex gets constructed before main()
// starts. This way we can be pretty sure it will be constructed
// before any threads could possibly call set_current_dir() or
// get_current_dir() simultaneously.
struct
construct_cwd_mutex
{
construct_cwd_mutex
()
{
cwd_mutex
();
}
}
oaimvweoinvwe
;
}
std
::
string
get_current_dir
(
...
...
@@ -41,7 +56,7 @@ namespace dlib
{
// need to lock a mutex here because getting and setting the
// current working directory is not thread safe on windows.
auto_mutex
lock
(
cwd_mutex
);
auto_mutex
lock
(
cwd_mutex
()
);
char
buf
[
1024
];
if
(
GetCurrentDirectoryA
(
sizeof
(
buf
),
buf
)
==
0
)
{
...
...
@@ -61,7 +76,7 @@ namespace dlib
{
// need to lock a mutex here because getting and setting the
// current working directory is not thread safe on windows.
auto_mutex
lock
(
cwd_mutex
);
auto_mutex
lock
(
cwd_mutex
()
);
if
(
SetCurrentDirectory
(
new_dir
.
c_str
())
==
0
)
{
throw
set_current_dir_error
(
"Error changing current dir to '"
+
new_dir
+
"'"
);
...
...
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