Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
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
libzmq
Commits
a91c7e71
Commit
a91c7e71
authored
6 years ago
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: warnings on violations of CERT ERR-58
Solution: declare functions noexcept
parent
0dce2233
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
20 deletions
+37
-20
atomic_counter.hpp
src/atomic_counter.hpp
+16
-7
atomic_ptr.hpp
src/atomic_ptr.hpp
+21
-13
No files found.
src/atomic_counter.hpp
View file @
a91c7e71
...
...
@@ -66,6 +66,14 @@
#include <arch/atomic.h>
#endif
#if !defined ZMQ_NOEXCEPT
#if defined ZMQ_HAVE_NOEXCEPT
#define ZMQ_NOEXCEPT noexcept
#else
#define ZMQ_NOEXCEPT
#endif
#endif
namespace
zmq
{
// This class represents an integer that can be incremented/decremented
...
...
@@ -90,15 +98,16 @@ class atomic_counter_t
public
:
typedef
uint32_t
integer_t
;
inline
atomic_counter_t
(
integer_t
value_
=
0
)
:
_value
(
value_
)
{}
inline
~
atomic_counter_t
()
{}
inline
atomic_counter_t
(
integer_t
value_
=
0
)
ZMQ_NOEXCEPT
:
_value
(
value_
)
{
}
// Set counter _value (not thread-safe).
inline
void
set
(
integer_t
value_
)
{
_value
=
value_
;
}
inline
void
set
(
integer_t
value_
)
ZMQ_NOEXCEPT
{
_value
=
value_
;
}
// Atomic addition. Returns the old _value.
inline
integer_t
add
(
integer_t
increment_
)
inline
integer_t
add
(
integer_t
increment_
)
ZMQ_NOEXCEPT
{
integer_t
old_value
;
...
...
@@ -143,7 +152,7 @@ class atomic_counter_t
}
// Atomic subtraction. Returns false if the counter drops to zero.
inline
bool
sub
(
integer_t
decrement_
)
inline
bool
sub
(
integer_t
decrement_
)
ZMQ_NOEXCEPT
{
#if defined ZMQ_ATOMIC_COUNTER_WINDOWS
LONG
delta
=
-
((
LONG
)
decrement_
);
...
...
@@ -198,7 +207,7 @@ class atomic_counter_t
#endif
}
inline
integer_t
get
()
const
{
return
_value
;
}
inline
integer_t
get
()
const
ZMQ_NOEXCEPT
{
return
_value
;
}
private
:
#if defined ZMQ_ATOMIC_COUNTER_CXX11
...
...
This diff is collapsed.
Click to expand it.
src/atomic_ptr.hpp
View file @
a91c7e71
...
...
@@ -64,6 +64,14 @@
#include <arch/atomic.h>
#endif
#if !defined ZMQ_NOEXCEPT
#if defined ZMQ_HAVE_NOEXCEPT
#define ZMQ_NOEXCEPT noexcept
#else
#define ZMQ_NOEXCEPT
#endif
#endif
namespace
zmq
{
#if !defined ZMQ_ATOMIC_PTR_CXX11
...
...
@@ -73,7 +81,7 @@ inline void *atomic_xchg_ptr (void **ptr_,
,
mutex_t
&
_sync
#endif
)
)
ZMQ_NOEXCEPT
{
#if defined ZMQ_ATOMIC_PTR_WINDOWS
return
InterlockedExchangePointer
((
PVOID
*
)
ptr_
,
val_
);
...
...
@@ -120,7 +128,7 @@ inline void *atomic_cas (void *volatile *ptr_,
,
mutex_t
&
_sync
#endif
)
)
ZMQ_NOEXCEPT
{
#if defined ZMQ_ATOMIC_PTR_WINDOWS
return
InterlockedCompareExchangePointer
((
volatile
PVOID
*
)
ptr_
,
val_
,
...
...
@@ -176,19 +184,16 @@ template <typename T> class atomic_ptr_t
{
public
:
// Initialise atomic pointer
inline
atomic_ptr_t
()
{
_ptr
=
NULL
;
}
// Destroy atomic pointer
inline
~
atomic_ptr_t
()
{}
inline
atomic_ptr_t
()
ZMQ_NOEXCEPT
{
_ptr
=
NULL
;
}
// Set value of atomic pointer in a non-threadsafe way
// Use this function only when you are sure that at most one
// thread is accessing the pointer at the moment.
inline
void
set
(
T
*
ptr_
)
{
_ptr
=
ptr_
;
}
inline
void
set
(
T
*
ptr_
)
ZMQ_NOEXCEPT
{
_ptr
=
ptr_
;
}
// Perform atomic 'exchange pointers' operation. Pointer is set
// to the 'val_' value. Old value is returned.
inline
T
*
xchg
(
T
*
val_
)
inline
T
*
xchg
(
T
*
val_
)
ZMQ_NOEXCEPT
{
#if defined ZMQ_ATOMIC_PTR_CXX11
return
_ptr
.
exchange
(
val_
,
std
::
memory_order_acq_rel
);
...
...
@@ -206,7 +211,7 @@ template <typename T> class atomic_ptr_t
// The pointer is compared to 'cmp' argument and if they are
// equal, its value is set to 'val_'. Old value of the pointer
// is returned.
inline
T
*
cas
(
T
*
cmp_
,
T
*
val_
)
inline
T
*
cas
(
T
*
cmp_
,
T
*
val_
)
ZMQ_NOEXCEPT
{
#if defined ZMQ_ATOMIC_PTR_CXX11
_ptr
.
compare_exchange_strong
(
cmp_
,
val_
,
std
::
memory_order_acq_rel
);
...
...
@@ -240,11 +245,14 @@ template <typename T> class atomic_ptr_t
struct
atomic_value_t
{
atomic_value_t
(
const
int
value_
)
:
_value
(
value_
)
{}
atomic_value_t
(
const
int
value_
)
ZMQ_NOEXCEPT
:
_value
(
value_
)
{}
atomic_value_t
(
const
atomic_value_t
&
src_
)
:
_value
(
src_
.
load
())
{}
atomic_value_t
(
const
atomic_value_t
&
src_
)
ZMQ_NOEXCEPT
:
_value
(
src_
.
load
())
{
}
void
store
(
const
int
value_
)
void
store
(
const
int
value_
)
ZMQ_NOEXCEPT
{
#if defined ZMQ_ATOMIC_PTR_CXX11
_value
.
store
(
value_
,
std
::
memory_order_release
);
...
...
@@ -258,7 +266,7 @@ struct atomic_value_t
#endif
}
int
load
()
const
int
load
()
const
ZMQ_NOEXCEPT
{
#if defined ZMQ_ATOMIC_PTR_CXX11
return
_value
.
load
(
std
::
memory_order_acquire
);
...
...
This diff is collapsed.
Click to expand it.
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