Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
43b1af72
Commit
43b1af72
authored
Feb 14, 2019
by
Cholerae Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mutex: throw system_error when constuctor failed and lock failed
Signed-off-by:
Cholerae Hu
<
choleraehyq@gmail.com
>
parent
f7aab8c9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
mutex.h
src/bthread/mutex.h
+12
-2
No files found.
src/bthread/mutex.h
View file @
43b1af72
...
@@ -42,10 +42,20 @@ namespace bthread {
...
@@ -42,10 +42,20 @@ namespace bthread {
class
Mutex
{
class
Mutex
{
public
:
public
:
typedef
bthread_mutex_t
*
native_handler_type
;
typedef
bthread_mutex_t
*
native_handler_type
;
Mutex
()
{
CHECK_EQ
(
0
,
bthread_mutex_init
(
&
_mutex
,
NULL
));
}
Mutex
()
{
int
ec
=
bthread_mutex_init
(
&
_mutex
,
NULL
);
if
(
ec
!=
0
)
{
throw
std
::
system_error
(
std
::
error_code
(
ec
,
std
::
system_category
()),
"Mutex constructor failed"
);
}
}
~
Mutex
()
{
CHECK_EQ
(
0
,
bthread_mutex_destroy
(
&
_mutex
));
}
~
Mutex
()
{
CHECK_EQ
(
0
,
bthread_mutex_destroy
(
&
_mutex
));
}
native_handler_type
native_handler
()
{
return
&
_mutex
;
}
native_handler_type
native_handler
()
{
return
&
_mutex
;
}
void
lock
()
{
bthread_mutex_lock
(
&
_mutex
);
}
void
lock
()
{
int
ec
=
bthread_mutex_lock
(
&
_mutex
);
if
(
ec
!=
0
)
{
throw
std
::
system_error
(
std
::
error_code
(
ec
,
std
::
system_category
()),
"Mutex lock failed"
);
}
}
void
unlock
()
{
bthread_mutex_unlock
(
&
_mutex
);
}
void
unlock
()
{
bthread_mutex_unlock
(
&
_mutex
);
}
bool
try_lock
()
{
return
!
bthread_mutex_trylock
(
&
_mutex
);
}
bool
try_lock
()
{
return
!
bthread_mutex_trylock
(
&
_mutex
);
}
// TODO(chenzhangyi01): Complement interfaces for C++11
// TODO(chenzhangyi01): Complement interfaces for C++11
...
...
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