Skip to content

Commit dbfd063

Browse files
author
Giovanny Gutiérrez
committed
Windows fixes, compiling using Visual Studio 2015
1 parent ea631fd commit dbfd063

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

raftinc/allocate.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* that reference the alignments.
4141
*/
4242

43-
#if defined __AVX__ || __AVX2__
43+
#if defined __AVX__ || __AVX2__ || _WIN64
4444
#define ALLOC_ALIGN_WIDTH 32
4545
#else
4646
#define ALLOC_ALIGN_WIDTH 16

raftinc/blocked.hpp

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,50 @@
2222
#include <cstdint>
2323
#include <cassert>
2424

25+
#ifdef _MSC_VER
26+
# if (_MSC_VER >= 1800)
27+
# define __alignas_is_defined 1
28+
# endif
29+
# if (_MSC_VER >= 1900)
30+
# define __alignof_is_defined 1
31+
# endif
32+
#else
33+
# include <cstdalign> // __alignas/of_is_defined directly from the implementation
34+
#endif
35+
36+
37+
#ifdef __alignas_is_defined
38+
# define ALIGN(X) alignas(X)
39+
#else
40+
# pragma message("C++11 alignas unsupported :( Falling back to compiler attributes")
41+
# ifdef __GNUG__
42+
# define ALIGN(X) __attribute__ ((aligned(X)))
43+
# elif defined(_MSC_VER)
44+
# define ALIGN(X) __declspec(align(X))
45+
# else
46+
# error Unknown compiler, unknown alignment attribute!
47+
# endif
48+
#endif
49+
50+
#ifdef __alignof_is_defined
51+
# define ALIGNOF(X) alignof(x)
52+
#else
53+
# pragma message("C++11 alignof unsupported :( Falling back to compiler attributes")
54+
# ifdef __GNUG__
55+
# define ALIGNOF(X) __alignof__ (X)
56+
# elif defined(_MSC_VER)
57+
# define ALIGNOF(X) __alignof(X)
58+
# else
59+
# error Unknown compiler, unknown alignment attribute!
60+
# endif
61+
#endif
62+
63+
2564
/**
2665
* FIXME...should probably align these to cache line then
2766
* zero extend pad for producer/consumer.
2867
*/
29-
struct Blocked
68+
struct ALIGN(64) Blocked
3069
{
3170
using value_type = std::uint32_t;
3271
using whole_type = std::uint64_t;
@@ -59,9 +98,7 @@ struct Blocked
5998

6099
char pad[ L1D_CACHE_LINE_SIZE - sizeof( whole_type ) ];
61100
}
62-
#if __APPLE__ || __linux
63-
__attribute__ (( aligned( 64 )))
64-
#endif
101+
65102
;
66103

67104
#endif /* END _BLOCKED_HPP_ */

raftinc/bufferdata.tcc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ template < class T > struct Data< T,
9696
}
9797
#elif (defined _WIN64 ) || (defined _WIN32)
9898
//FIXME, we need to test this on Win sys before making live
99-
(this)->store = reinterpret_cast< T* >( _aligned_malloc( align,
100-
(this)->length_store ) );
99+
(this)->store = reinterpret_cast< T* >( _aligned_malloc( (this)->length_store,align) );
101100
#else
102101
/**
103102
* would use the array allocate, but well...we'd have to
@@ -171,7 +170,11 @@ template < class T > struct Data< T,
171170
//FREE USED HERE
172171
if( ! (this)->external_alloc )
173172
{
173+
#if (defined _WIN64 ) || (defined _WIN32)
174+
_aligned_free( (this)->store );
175+
#else
174176
free( (this)->store );
177+
#endif
175178
}
176179
free( (this)->signal );
177180
}
@@ -227,8 +230,7 @@ template < class T >
227230
}
228231
#elif (defined _WIN64 ) || (defined _WIN32)
229232
//FIXME, we need to test this on Win sys before making live
230-
(this)->store = reinterpret_cast< type_t* >( _aligned_malloc( align,
231-
(this)->length_store ) );
233+
(this)->store = reinterpret_cast< type_t* >( _aligned_malloc((this)->length_store, align));
232234
#else
233235
/**
234236
* would use the array allocate, but well...we'd have to
@@ -295,7 +297,11 @@ template < class T >
295297
//FREE USED HERE
296298
if( ! (this)->external_alloc )
297299
{
300+
#if (defined _WIN64 ) || (defined _WIN32)
301+
_aligned_free( (this)->store );
302+
#else
298303
free( (this)->store );
304+
#endif
299305
}
300306
free( (this)->signal );
301307
}

0 commit comments

Comments
 (0)