Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stunserver
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Stunserver
Commits
6563707a
Commit
6563707a
authored
Feb 25, 2013
by
jselbie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for compiler target i386
parent
198791c0
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
211 additions
and
15 deletions
+211
-15
common/Makefile
common/Makefile
+1
-1
common/atomichelpers.cpp
common/atomichelpers.cpp
+79
-0
common/atomichelpers.h
common/atomichelpers.h
+41
-0
common/refcountobject.cpp
common/refcountobject.cpp
+1
-10
common/refcountobject.h
common/refcountobject.h
+0
-2
stuncore/stunbuilder.cpp
stuncore/stunbuilder.cpp
+2
-1
testcode/Makefile
testcode/Makefile
+1
-1
testcode/testatomichelpers.cpp
testcode/testatomichelpers.cpp
+50
-0
testcode/testatomichelpers.h
testcode/testatomichelpers.h
+33
-0
testcode/testcode.cpp
testcode/testcode.cpp
+3
-0
No files found.
common/Makefile
View file @
6563707a
include
../common.inc
PROJECT_TARGET
:=
libcommon.a
PROJECT_SRCS
:=
cmdlineparser.cpp common.cpp fasthash.cpp getconsolewidth.cpp getmillisecondcounter.cpp logger.cpp prettyprint.cpp refcountobject.cpp stringhelper.cpp
PROJECT_SRCS
:=
atomichelpers.cpp
cmdlineparser.cpp common.cpp fasthash.cpp getconsolewidth.cpp getmillisecondcounter.cpp logger.cpp prettyprint.cpp refcountobject.cpp stringhelper.cpp
PROJECT_OBJS
:=
$(
subst
.cpp,.o,
$(PROJECT_SRCS)
)
INCLUDES
:=
$(BOOST_INCLUDE)
PRECOMP_H_GCH
:=
commonincludes.hpp.gch
...
...
common/atomichelpers.cpp
0 → 100644
View file @
6563707a
/*
Copyright 2011 John Selbie
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "commonincludes.hpp"
#ifdef ATOMICS_ARE_DEFINED
extern
"C"
unsigned
int
xadd_4
(
volatile
void
*
pVal
,
unsigned
int
inc
)
{
unsigned
int
result
;
unsigned
int
*
pValInt
=
(
unsigned
int
*
)
pVal
;
asm
volatile
(
"lock; xaddl %%eax, %2;"
:
"=a"
(
result
)
:
"a"
(
inc
),
"m"
(
*
pValInt
)
:
"memory"
);
return
(
result
);
}
extern
"C"
unsigned
int
__sync_add_and_fetch_4
(
volatile
void
*
pVal
,
unsigned
int
inc
)
{
return
(
xadd_4
(
pVal
,
inc
)
+
inc
);
}
extern
"C"
unsigned
int
__sync_sub_and_fetch_4
(
volatile
void
*
pVal
,
unsigned
int
inc
)
{
return
(
xadd_4
(
pVal
,
-
inc
)
-
inc
);
}
extern
"C"
unsigned
int
__sync_fetch_and_add_4
(
volatile
void
*
pVal
,
unsigned
int
inc
)
{
return
xadd_4
(
pVal
,
inc
);
}
extern
"C"
unsigned
int
__sync_fetch_and_sub_4
(
volatile
void
*
pVal
,
unsigned
int
inc
)
{
return
xadd_4
(
pVal
,
-
inc
);
}
#ifdef __GNUC__
#pragma message "atomichelpers.cpp: Defining sync_add_and_fetch helpers for i386 compile"
#endif
#endif
int
AtomicIncrement
(
int
*
pInt
)
{
COMPILE_TIME_ASSERT
(
sizeof
(
int
)
==
4
);
// InterlockedIncrement
return
__sync_add_and_fetch
(
pInt
,
1
);
}
int
AtomicDecrement
(
int
*
pInt
)
{
// InterlockedDecrement
return
__sync_sub_and_fetch
(
pInt
,
1
);
}
common/atomichelpers.h
0 → 100644
View file @
6563707a
/*
Copyright 2013 John Selbie
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef ATOMICHELPERS_H
#define ATOMICHELPERS_H
typedef
unsigned
int
(
*
xaddFunctionType
)(
volatile
void
*
,
unsigned
int
);
#if defined(i386) || defined(__i386__) || defined(__i386)
#define ATOMICS_ARE_DEFINED
extern
"C"
unsigned
int
xadd_4
(
volatile
void
*
pVal
,
unsigned
int
inc
);
extern
"C"
unsigned
int
__sync_add_and_fetch_4
(
volatile
void
*
pVal
,
unsigned
int
inc
);
extern
"C"
unsigned
int
__sync_sub_and_fetch_4
(
volatile
void
*
pVal
,
unsigned
int
inc
);
extern
"C"
unsigned
int
__sync_fetch_and_add_4
(
volatile
void
*
pVal
,
unsigned
int
inc
);
extern
"C"
unsigned
int
__sync_fetch_and_sub_4
(
volatile
void
*
pVal
,
unsigned
int
inc
);
#endif
int
AtomicIncrement
(
int
*
pInt
);
int
AtomicDecrement
(
int
*
pInt
);
#endif
/* ATOMICHELPERS_H */
common/refcountobject.cpp
View file @
6563707a
...
...
@@ -18,17 +18,8 @@
#include "commonincludes.hpp"
#include "refcountobject.h"
int
AtomicIncrement
(
int
*
pInt
)
{
// InterlockedIncrement
return
__sync_add_and_fetch
(
pInt
,
1
);
}
int
AtomicDecrement
(
int
*
pInt
)
{
// InterlockedDecrement
return
__sync_sub_and_fetch
(
pInt
,
1
);
}
#include "atomichelpers.h"
CBasicRefCount
::
CBasicRefCount
()
...
...
common/refcountobject.h
View file @
6563707a
...
...
@@ -21,8 +21,6 @@
int
AtomicIncrement
(
int
*
pInt
);
int
AtomicDecrement
(
int
*
pInt
);
class
IRefCounted
...
...
stuncore/stunbuilder.cpp
View file @
6563707a
...
...
@@ -19,6 +19,7 @@
#include "commonincludes.hpp"
#include "stringhelper.h"
#include "atomichelpers.h"
#include "stunbuilder.h"
#include <boost/crc.hpp>
...
...
@@ -118,7 +119,7 @@ HRESULT CStunMessageBuilder::AddRandomTransactionId(StunTransactionId* pTransId)
entropy
^=
getpid
();
entropy
^=
reinterpret_cast
<
uintptr_t
>
(
this
);
entropy
^=
time
(
NULL
);
entropy
^=
__sync_fetch_and_add
(
&
g_sequence_number
,
1
);
entropy
^=
AtomicIncrement
(
&
g_sequence_number
);
}
#endif
...
...
testcode/Makefile
View file @
6563707a
include
../common.inc
PROJECT_TARGET
:=
stuntestcode
PROJECT_OBJS
:=
testbuilder.o testclientlogic.o testcmdline.o testcode.o testdatastream.o testfasthash.o testintegrity.o testmessagehandler.o testpolling.o testreader.o testrecvfromex.o
PROJECT_OBJS
:=
test
atomichelpers.o test
builder.o testclientlogic.o testcmdline.o testcode.o testdatastream.o testfasthash.o testintegrity.o testmessagehandler.o testpolling.o testreader.o testrecvfromex.o
INCLUDES
:=
$(BOOST_INCLUDE)
$(OPENSSL_INCLUDE)
-I
../common
-I
../stuncore
-I
../networkutils
LIB_PATH
:=
-L
../networkutils
-L
../stuncore
-L
../common
...
...
testcode/testatomichelpers.cpp
0 → 100644
View file @
6563707a
/*
Copyright 2013 John Selbie
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "commonincludes.hpp"
#include "testatomichelpers.h"
#include "atomichelpers.h"
HRESULT
CTestAtomicHelpers
::
Run
()
{
HRESULT
hr
=
S_OK
;
int
value
=
-
2000
;
int
nextexpected
=
-
2000
;
int
result
=
0
;
while
(
value
<
2000
)
{
nextexpected
++
;
result
=
AtomicIncrement
(
&
value
);
ChkIf
(
result
!=
nextexpected
,
E_UNEXPECTED
);
ChkIf
(
result
!=
value
,
E_UNEXPECTED
);
}
value
=
2000
;
nextexpected
=
2000
;
while
(
value
>
-
2000
)
{
nextexpected
--
;
result
=
AtomicDecrement
(
&
value
);
ChkIf
(
result
!=
nextexpected
,
E_UNEXPECTED
);
ChkIf
(
result
!=
value
,
E_UNEXPECTED
);
}
Cleanup:
return
hr
;
}
\ No newline at end of file
testcode/testatomichelpers.h
0 → 100644
View file @
6563707a
/*
Copyright 2013 John Selbie
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef TESTATOMICHELPERS_H
#define TESTATOMICHELPERS_H
#include "unittest.h"
class
CTestAtomicHelpers
:
public
IUnitTest
{
public:
virtual
HRESULT
Run
();
UT_DECLARE_TEST_NAME
(
"CTestAtomicHelpers"
);
};
#endif
/* TESTATOMICHELPERS_H */
testcode/testcode.cpp
View file @
6563707a
...
...
@@ -32,6 +32,7 @@
#include "prettyprint.h"
#include "polling.h"
#include "testpolling.h"
#include "testatomichelpers.h"
void
ReaderFuzzTest
()
{
...
...
@@ -82,6 +83,7 @@ void RunUnitTests()
boost
::
shared_ptr
<
CTestRecvFromExIPV6
>
spTestRecvFromEx6
(
new
CTestRecvFromExIPV6
);
boost
::
shared_ptr
<
CTestFastHash
>
spTestFastHash
(
new
CTestFastHash
);
boost
::
shared_ptr
<
CTestPolling
>
spTestPolling
(
new
CTestPolling
);
boost
::
shared_ptr
<
CTestAtomicHelpers
>
spTestAtomicHelpers
(
new
CTestAtomicHelpers
);
vecTests
.
push_back
(
spTestDataStream
.
get
());
vecTests
.
push_back
(
spTestReader
.
get
());
...
...
@@ -94,6 +96,7 @@ void RunUnitTests()
vecTests
.
push_back
(
spTestRecvFromEx6
.
get
());
vecTests
.
push_back
(
spTestFastHash
.
get
());
vecTests
.
push_back
(
spTestPolling
.
get
());
vecTests
.
push_back
(
spTestAtomicHelpers
.
get
());
for
(
size_t
index
=
0
;
index
<
vecTests
.
size
();
index
++
)
...
...
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