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
7cb076e5
Commit
7cb076e5
authored
Apr 29, 2010
by
Steven McCoy
Committed by
Martin Sustrik
Apr 29, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Defer NetBSD atomic ops to GCC builtins. Revert Sun atomic ops #define.
parent
ad6fa9d0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
47 deletions
+92
-47
atomic_bitmap.hpp
src/atomic_bitmap.hpp
+48
-24
atomic_counter.hpp
src/atomic_counter.hpp
+27
-15
atomic_ptr.hpp
src/atomic_ptr.hpp
+17
-8
No files found.
src/atomic_bitmap.hpp
View file @
7cb076e5
...
...
@@ -34,8 +34,10 @@
#define ZMQ_ATOMIC_BITMAP_SPARC
#elif defined ZMQ_HAVE_WINDOWS
#define ZMQ_ATOMIC_BITMAP_WINDOWS
#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD)
#define ZMQ_ATOMIC_BITMAP_SYSTEM
#elif defined sun
#define ZMQ_ATOMIC_COUNTER_SUN
#elif defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
#define ZMQ_ATOMIC_COUNTER_GNU
#else
#define ZMQ_ATOMIC_BITMAP_MUTEX
#endif
...
...
@@ -44,7 +46,7 @@
#include "mutex.hpp"
#elif defined ZMQ_ATOMIC_BITMAP_WINDOWS
#include "windows.hpp"
#elif defined ZMQ_ATOMIC_BITMAP_S
YSTEM
#elif defined ZMQ_ATOMIC_BITMAP_S
UN
#include <atomic.h>
#endif
...
...
@@ -89,7 +91,16 @@ namespace zmq
return
(
oldval
&
(
bitmap_t
(
1
)
<<
reset_index_
))
?
true
:
false
;
}
#elif defined ZMQ_ATOMIC_BITMAP_SYSTEM
#elif defined ZMQ_ATOMIC_BITMAP_GNU
while
(
true
)
{
bitmap_t
oldval
=
value
;
bitmap_t
newval
=
(
oldval
|
(
bitmap_t
(
1
)
<<
set_index_
))
&
~
(
bitmap_t
(
1
)
<<
reset_index_
);
if
(
__sync_val_compare_and_swap
(
&
value
,
oldval
,
newval
)
==
oldval
)
return
(
oldval
&
(
bitmap_t
(
1
)
<<
reset_index_
))
?
true
:
false
;
}
#elif defined ZMQ_ATOMIC_BITMAP_SUN
while
(
true
)
{
bitmap_t
oldval
=
value
;
bitmap_t
newval
=
(
oldval
|
(
bitmap_t
(
1
)
<<
set_index_
))
&
...
...
@@ -119,14 +130,14 @@ namespace zmq
bitmap_t
tmp
;
bitmap_t
oldval
;
__asm__
volatile
(
"ld
[%5], %2
\n\t
"
"1:
\n\t
"
"or
%2, %0, %3
\n\t
"
"and
%3, %1, %3
\n\t
"
"cas
[%5], %2, %3
\n\t
"
"cmp
%2, %3
\n\t
"
"bne,a,pn %%icc, 1b
\n\t
"
"mov
%3, %2
\n\t
"
"ld
[%5], %2
\n\t
"
"1:
\n\t
"
"or
%2, %0, %3
\n\t
"
"and
%3, %1, %3
\n\t
"
"cas
[%5], %2, %3
\n\t
"
"cmp
%2, %3
\n\t
"
"bne,a,pn %%icc, 1b
\n\t
"
"mov
%3, %2
\n\t
"
:
"+r"
(
set_val
),
"+r"
(
reset_val
),
"=&r"
(
tmp
),
"=&r"
(
oldval
),
"+m"
(
*
valptr
)
:
"r"
(
valptr
)
...
...
@@ -150,7 +161,9 @@ namespace zmq
bitmap_t
oldval
;
#if defined ZMQ_ATOMIC_BITMAP_WINDOWS
oldval
=
InterlockedExchange
((
volatile
LONG
*
)
&
value
,
newval_
);
#elif defined ZMQ_ATOMIC_BITMAP_SYSTEM
#elif defined ZMQ_ATOMIC_BITMAP_GNU
oldval
=
__sync_lock_test_and_set
(
&
value
,
newval_
);
#elif defined ZMQ_ATOMIC_BITMAP_SUN
oldval
=
atomic_swap_32
(
&
value
,
newval_
);
#elif defined ZMQ_ATOMIC_BITMAP_X86
oldval
=
newval_
;
...
...
@@ -201,7 +214,14 @@ namespace zmq
newval
,
oldval
)
==
(
LONG
)
oldval
)
return
oldval
;
}
#elif defined ZMQ_ATOMIC_BITMAP_SYSTEM
#elif defined ZMQ_ATOMIC_BITMAP_GNU
while
(
true
)
{
bitmap_t
oldval
=
value
;
bitmap_t
newval
=
oldval
==
0
?
thenval_
:
elseval_
;
if
(
__sync_val_compare_and_swap
(
&
value
,
oldval
,
newval
)
==
oldval
)
return
oldval
;
}
#elif defined ZMQ_ATOMIC_BITMAP_SUN
while
(
true
)
{
bitmap_t
oldval
=
value
;
bitmap_t
newval
=
oldval
==
0
?
thenval_
:
elseval_
;
...
...
@@ -230,14 +250,14 @@ namespace zmq
bitmap_t
tmp
;
bitmap_t
prev
;
__asm__
__volatile__
(
"ld
[%3], %0
\n\t
"
"mov
0, %1
\n\t
"
"cas
[%3], %1, %4
\n\t
"
"cmp
%0, %1
\n\t
"
"be,a,pn %%icc,1f
\n\t
"
"ld
[%3], %0
\n\t
"
"cas
[%3], %0, %5
\n\t
"
"1:
\n\t
"
"ld
[%3], %0
\n\t
"
"mov
0, %1
\n\t
"
"cas
[%3], %1, %4
\n\t
"
"cmp
%0, %1
\n\t
"
"be,a,pn %%icc,1f
\n\t
"
"ld
[%3], %0
\n\t
"
"cas
[%3], %0, %5
\n\t
"
"1:
\n\t
"
:
"=&r"
(
tmp
),
"=&r"
(
prev
),
"+m"
(
*
ptrin
)
:
"r"
(
ptrin
),
"r"
(
thenval_
),
"r"
(
elseval_
)
:
"cc"
);
...
...
@@ -270,8 +290,11 @@ namespace zmq
#if defined ZMQ_ATOMIC_BITMAP_WINDOWS
#undef ZMQ_ATOMIC_BITMAP_WINDOWS
#endif
#if defined ZMQ_ATOMIC_BITMAP_SYSTEM
#undef ZMQ_ATOMIC_BITMAP_SYSTEM
#if defined ZMQ_ATOMIC_BITMAP_GNU
#undef ZMQ_ATOMIC_BITMAP_GNU
#endif
#if defined ZMQ_ATOMIC_BITMAP_SUN
#undef ZMQ_ATOMIC_BITMAP_SUN
#endif
#if defined ZMQ_ATOMIC_BITMAP_X86
#undef ZMQ_ATOMIC_BITMAP_X86
...
...
@@ -284,3 +307,4 @@ namespace zmq
#endif
#endif
src/atomic_counter.hpp
View file @
7cb076e5
...
...
@@ -31,8 +31,10 @@
#define ZMQ_ATOMIC_COUNTER_SPARC
#elif defined ZMQ_HAVE_WINDOWS
#define ZMQ_ATOMIC_COUNTER_WINDOWS
#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD)
#define ZMQ_ATOMIC_COUNTER_SYSTEM
#elif defined sun
#define ZMQ_ATOMIC_COUNTER_SUN
#elif defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
#define ZMQ_ATOMIC_COUNTER_GNU
#else
#define ZMQ_ATOMIC_COUNTER_MUTEX
#endif
...
...
@@ -41,7 +43,7 @@
#include "mutex.hpp"
#elif defined ZMQ_ATOMIC_COUNTER_WINDOWS
#include "windows.hpp"
#elif defined ZMQ_ATOMIC_COUNTER_S
YSTEM
#elif defined ZMQ_ATOMIC_COUNTER_S
UN
#include <atomic.h>
#endif
...
...
@@ -79,25 +81,27 @@ namespace zmq
#if defined ZMQ_ATOMIC_COUNTER_WINDOWS
old_value
=
InterlockedExchangeAdd
((
LONG
*
)
&
value
,
increment_
);
#elif defined ZMQ_ATOMIC_COUNTER_SYSTEM
#elif defined ZMQ_ATOMIC_COUNTER_GNU
old_value
=
__sync_fetch_and_add
(
&
value
,
increment_
);
#elif defined ZMQ_ATOMIC_COUNTER_SUN
integer_t
new_value
=
atomic_add_32_nv
(
&
value
,
increment_
);
old_value
=
new_value
-
increment_
;
#elif defined ZMQ_ATOMIC_COUNTER_X86
__asm__
volatile
(
"lock; xadd %0, %1
\n\t
"
"lock; xadd %0, %1
\n\t
"
:
"=r"
(
old_value
),
"=m"
(
value
)
:
"0"
(
increment_
),
"m"
(
value
)
:
"cc"
,
"memory"
);
#elif defined ZMQ_ATOMIC_COUNTER_SPARC
integer_t
tmp
;
__asm__
volatile
(
"ld [%4], %0
\n\t
"
"1:
\n\t
"
"add %0, %3, %1
\n\t
"
"cas [%4], %0, %1
\n\t
"
"cmp %0, %1
\n\t
"
"bne,a,pn %%icc, 1b
\n\t
"
"mov %1, %0
\n\t
"
"ld [%4], %0
\n\t
"
"1:
\n\t
"
"add %0, %3, %1
\n\t
"
"cas [%4], %0, %1
\n\t
"
"cmp %0, %1
\n\t
"
"bne,a,pn %%icc, 1b
\n\t
"
"mov %1, %0
\n\t
"
:
"=&r"
(
old_value
),
"=&r"
(
tmp
),
"=m"
(
value
)
:
"r"
(
increment_
),
"r"
(
&
value
)
:
"cc"
,
"memory"
);
...
...
@@ -119,7 +123,11 @@ namespace zmq
LONG
delta
=
-
((
LONG
)
decrement
);
integer_t
old
=
InterlockedExchangeAdd
((
LONG
*
)
&
value
,
delta
);
return
old
-
decrement
!=
0
;
#elif defined ZMQ_ATOMIC_COUNTER_SYSTEM
#elif defined ZMQ_ATOMIC_COUNTER_GNU
int32_t
delta
=
-
((
int32_t
)
decrement
);
integer_t
nv
=
__sync_fetch_and_add
(
&
value
,
delta
);
return
nv
!=
0
;
#elif defined ZMQ_ATOMIC_COUNTER_SUN
int32_t
delta
=
-
((
int32_t
)
decrement
);
integer_t
nv
=
atomic_add_32_nv
(
&
value
,
delta
);
return
nv
!=
0
;
...
...
@@ -180,8 +188,11 @@ namespace zmq
#if defined ZMQ_ATOMIC_COUNTER_WINDOWS
#undef ZMQ_ATOMIC_COUNTER_WINDOWS
#endif
#if defined ZMQ_ATOMIC_COUNTER_SYSTEM
#undef ZMQ_ATOMIC_COUNTER_SYSTEM
#if defined ZMQ_ATOMIC_COUNTER_GNU
#undef ZMQ_ATOMIC_COUNTER_GNU
#endif
#if defined ZMQ_ATOMIC_COUNTER_SUN
#undef ZMQ_ATOMIC_COUNTER_SUN
#endif
#if defined ZMQ_ATOMIC_COUNTER_X86
#undef ZMQ_ATOMIC_COUNTER_X86
...
...
@@ -194,3 +205,4 @@ namespace zmq
#endif
#endif
src/atomic_ptr.hpp
View file @
7cb076e5
...
...
@@ -17,7 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ZMQ_ATOMIC_PTR_HPP_INCLUDED__
#define __ZMQ_ATOMIC_PTR_HPP_INCLUDED__
...
...
@@ -31,8 +30,10 @@
#define ZMQ_ATOMIC_PTR_SPARC
#elif defined ZMQ_HAVE_WINDOWS
#define ZMQ_ATOMIC_PTR_WINDOWS
#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD)
#define ZMQ_ATOMIC_PTR_SYSTEM
#elif defined sun
#define ZMQ_ATOMIC_COUNTER_SUN
#elif defined( __GNUC__ ) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
#define ZMQ_ATOMIC_COUNTER_GNU
#else
#define ZMQ_ATOMIC_PTR_MUTEX
#endif
...
...
@@ -41,7 +42,7 @@
#include "mutex.hpp"
#elif defined ZMQ_ATOMIC_PTR_WINDOWS
#include "windows.hpp"
#elif defined ZMQ_ATOMIC_PTR_S
YSTEM
#elif defined ZMQ_ATOMIC_PTR_S
UN
#include <atomic.h>
#endif
...
...
@@ -79,7 +80,9 @@ namespace zmq
{
#if defined ZMQ_ATOMIC_PTR_WINDOWS
return
(
T
*
)
InterlockedExchangePointer
((
PVOID
*
)
&
ptr
,
val_
);
#elif defined ZMQ_ATOMIC_PTR_SYSTEM
#elif defined ZMQ_ATOMIC_PTR_GNU
return
(
T
*
)
__sync_lock_test_and_set
(
&
ptr
,
val_
);
#elif defined ZMQ_ATOMIC_PTR_SUN
return
(
T
*
)
atomic_swap_ptr
(
&
ptr
,
val_
);
#elif defined ZMQ_ATOMIC_PTR_X86
T
*
old
;
...
...
@@ -125,7 +128,9 @@ namespace zmq
#if defined ZMQ_ATOMIC_PTR_WINDOWS
return
(
T
*
)
InterlockedCompareExchangePointer
(
(
volatile
PVOID
*
)
&
ptr
,
val_
,
cmp_
);
#elif defined ZMQ_ATOMIC_PTR_SYSTEM
#elif defined ZMQ_ATOMIC_PTR_GNU
return
(
T
*
)
__sync_val_compare_and_swap
(
&
ptr
,
cmp_
,
val_
);
#elif defined ZMQ_ATOMIC_PTR_SUN
return
(
T
*
)
atomic_cas_ptr
(
&
ptr
,
cmp_
,
val_
);
#elif defined ZMQ_ATOMIC_PTR_X86
T
*
old
;
...
...
@@ -173,8 +178,11 @@ namespace zmq
#if defined ZMQ_ATOMIC_PTR_WINDOWS
#undef ZMQ_ATOMIC_PTR_WINDOWS
#endif
#if defined ZMQ_ATOMIC_PTR_SYSTEM
#undef ZMQ_ATOMIC_PTR_SYSTEM
#if defined ZMQ_ATOMIC_PTR_GNU
#undef ZMQ_ATOMIC_PTR_GNU
#endif
#if defined ZMQ_ATOMIC_PTR_SUN
#undef ZMQ_ATOMIC_PTR_SUN
#endif
#if defined ZMQ_ATOMIC_PTR_X86
#undef ZMQ_ATOMIC_PTR_X86
...
...
@@ -187,3 +195,4 @@ namespace zmq
#endif
#endif
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