Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
b9223347
Commit
b9223347
authored
7 years ago
by
David G. Quintas
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #11539 from dgquintas/alarm_non_copyable
Make grpc::Alarm non-copyable
parents
e81586bc
ab1ff6b0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/grpc++/alarm.h
+19
-2
19 additions, 2 deletions
include/grpc++/alarm.h
test/cpp/common/alarm_cpp_test.cc
+31
-0
31 additions, 0 deletions
test/cpp/common/alarm_cpp_test.cc
with
50 additions
and
2 deletions
include/grpc++/alarm.h
+
19
−
2
View file @
b9223347
...
@@ -52,8 +52,25 @@ class Alarm : private GrpcLibraryCodegen {
...
@@ -52,8 +52,25 @@ class Alarm : private GrpcLibraryCodegen {
alarm_
(
grpc_alarm_create
(
cq
->
cq
(),
TimePoint
<
T
>
(
deadline
).
raw_time
(),
alarm_
(
grpc_alarm_create
(
cq
->
cq
(),
TimePoint
<
T
>
(
deadline
).
raw_time
(),
static_cast
<
void
*>
(
&
tag_
)))
{}
static_cast
<
void
*>
(
&
tag_
)))
{}
/// Alarms aren't copyable.
Alarm
(
const
Alarm
&
)
=
delete
;
Alarm
&
operator
=
(
const
Alarm
&
)
=
delete
;
/// Alarms are movable.
Alarm
(
Alarm
&&
rhs
)
:
tag_
(
rhs
.
tag_
),
alarm_
(
rhs
.
alarm_
)
{
rhs
.
alarm_
=
nullptr
;
}
Alarm
&
operator
=
(
Alarm
&&
rhs
)
{
tag_
=
rhs
.
tag_
;
alarm_
=
rhs
.
alarm_
;
rhs
.
alarm_
=
nullptr
;
return
*
this
;
}
/// Destroy the given completion queue alarm, cancelling it in the process.
/// Destroy the given completion queue alarm, cancelling it in the process.
~
Alarm
()
{
grpc_alarm_destroy
(
alarm_
);
}
~
Alarm
()
{
if
(
alarm_
!=
nullptr
)
grpc_alarm_destroy
(
alarm_
);
}
/// Cancel a completion queue alarm. Calling this function over an alarm that
/// Cancel a completion queue alarm. Calling this function over an alarm that
/// has already fired has no effect.
/// has already fired has no effect.
...
@@ -73,7 +90,7 @@ class Alarm : private GrpcLibraryCodegen {
...
@@ -73,7 +90,7 @@ class Alarm : private GrpcLibraryCodegen {
};
};
AlarmEntry
tag_
;
AlarmEntry
tag_
;
grpc_alarm
*
const
alarm_
;
// owned
grpc_alarm
*
alarm_
;
// owned
};
};
}
// namespace grpc
}
// namespace grpc
...
...
This diff is collapsed.
Click to expand it.
test/cpp/common/alarm_cpp_test.cc
+
31
−
0
View file @
b9223347
...
@@ -40,6 +40,37 @@ TEST(AlarmTest, RegularExpiry) {
...
@@ -40,6 +40,37 @@ TEST(AlarmTest, RegularExpiry) {
EXPECT_EQ
(
junk
,
output_tag
);
EXPECT_EQ
(
junk
,
output_tag
);
}
}
TEST
(
AlarmTest
,
MoveConstructor
)
{
CompletionQueue
cq
;
void
*
junk
=
reinterpret_cast
<
void
*>
(
1618033
);
Alarm
first
(
&
cq
,
grpc_timeout_seconds_to_deadline
(
1
),
junk
);
Alarm
second
(
std
::
move
(
first
));
void
*
output_tag
;
bool
ok
;
const
CompletionQueue
::
NextStatus
status
=
cq
.
AsyncNext
(
(
void
**
)
&
output_tag
,
&
ok
,
grpc_timeout_seconds_to_deadline
(
2
));
EXPECT_EQ
(
status
,
CompletionQueue
::
GOT_EVENT
);
EXPECT_TRUE
(
ok
);
EXPECT_EQ
(
junk
,
output_tag
);
}
TEST
(
AlarmTest
,
MoveAssignment
)
{
CompletionQueue
cq
;
void
*
junk
=
reinterpret_cast
<
void
*>
(
1618033
);
Alarm
first
(
&
cq
,
grpc_timeout_seconds_to_deadline
(
1
),
junk
);
Alarm
second
(
std
::
move
(
first
));
first
=
std
::
move
(
second
);
void
*
output_tag
;
bool
ok
;
const
CompletionQueue
::
NextStatus
status
=
cq
.
AsyncNext
(
(
void
**
)
&
output_tag
,
&
ok
,
grpc_timeout_seconds_to_deadline
(
2
));
EXPECT_EQ
(
status
,
CompletionQueue
::
GOT_EVENT
);
EXPECT_TRUE
(
ok
);
EXPECT_EQ
(
junk
,
output_tag
);
}
TEST
(
AlarmTest
,
RegularExpiryChrono
)
{
TEST
(
AlarmTest
,
RegularExpiryChrono
)
{
CompletionQueue
cq
;
CompletionQueue
cq
;
void
*
junk
=
reinterpret_cast
<
void
*>
(
1618033
);
void
*
junk
=
reinterpret_cast
<
void
*>
(
1618033
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment