diff --git a/Makefile b/Makefile index eb1efdf7513..69e3c679aaa 100644 --- a/Makefile +++ b/Makefile @@ -550,6 +550,7 @@ LIBGPR_SRC = \ src/core/support/string_win32.c \ src/core/support/sync.c \ src/core/support/sync_posix.c \ + src/core/support/sync_win32.c \ src/core/support/thd_posix.c \ src/core/support/thd_win32.c \ src/core/support/time.c \ diff --git a/build.json b/build.json index 3769fe991a7..e185d668fcc 100644 --- a/build.json +++ b/build.json @@ -34,6 +34,7 @@ "src/core/support/string_win32.c", "src/core/support/sync.c", "src/core/support/sync_posix.c", + "src/core/support/sync_win32.c", "src/core/support/thd_posix.c", "src/core/support/thd_win32.c", "src/core/support/time.c", diff --git a/include/grpc/support/atm_win32.h b/include/grpc/support/atm_win32.h index 9b2f0e84bae..d32ffd46a29 100644 --- a/include/grpc/support/atm_win32.h +++ b/include/grpc/support/atm_win32.h @@ -57,18 +57,27 @@ static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) { static __inline int gpr_atm_no_barrier_cas(gpr_atm *p, gpr_atm o, gpr_atm n) { /* InterlockedCompareExchangePointerNoFence() not available on vista or windows7 */ - return o == (gpr_atm)InterlockedCompareExchangePointerAcquire(p, (void *)n, - (void *)o); +#ifdef GPR_ARCH_64 + return o == (gpr_atm)InterlockedCompareExchangeAcquire64(p, n, o); +#else + return o == (gpr_atm)InterlockedCompareExchangeAcquire(p, n, o); +#endif } static __inline int gpr_atm_acq_cas(gpr_atm *p, gpr_atm o, gpr_atm n) { - return o == (gpr_atm)InterlockedCompareExchangePointerAcquire(p, (void *)n, - (void *)o); +#ifdef GPR_ARCH_64 + return o == (gpr_atm)InterlockedCompareExchangeAcquire64(p, n, o); +#else + return o == (gpr_atm)InterlockedCompareExchangeAcquire(p, n, o); +#endif } static __inline int gpr_atm_rel_cas(gpr_atm *p, gpr_atm o, gpr_atm n) { - return o == (gpr_atm)InterlockedCompareExchangePointerRelease(p, (void *)n, - (void *)o); +#ifdef GPR_ARCH_64 + return o == (gpr_atm)InterlockedCompareExchangeRelease64(p, n, o); +#else + return o == (gpr_atm)InterlockedCompareExchangeRelease(p, n, o); +#endif } static __inline gpr_atm gpr_atm_no_barrier_fetch_add(gpr_atm *p, @@ -86,9 +95,12 @@ static __inline gpr_atm gpr_atm_full_fetch_add(gpr_atm *p, gpr_atm delta) { gpr_atm old; do { old = *p; - } while (old != (gpr_atm)InterlockedCompareExchangePointer( - p, (void *)(old + delta), (void *)old)); +#ifdef GPR_ARCH_64 + } while (old != (gpr_atm)InterlockedCompareExchange64(p, old + delta, old)); +#else + } while (old != (gpr_atm)InterlockedCompareExchange(p, old + delta, old)); +#endif return old; } -#endif /* __GRPC_SUPPORT_ATM_WIN32_H__ */ +#endif /* __GRPC_SUPPORT_ATM_WIN32_H__ */ diff --git a/src/core/support/histogram.c b/src/core/support/histogram.c index a3ecd3e1528..c5e56080492 100644 --- a/src/core/support/histogram.c +++ b/src/core/support/histogram.c @@ -127,7 +127,7 @@ void gpr_histogram_add(gpr_histogram *h, double x) { } int gpr_histogram_merge(gpr_histogram *dst, gpr_histogram *src) { - int i; + size_t i; if ((dst->num_buckets != src->num_buckets) || (dst->multiplier != src->multiplier)) { /* Fail because these histograms don't match */ @@ -152,8 +152,8 @@ static double threshold_for_count_below(gpr_histogram *h, double count_below) { double count_so_far; double lower_bound; double upper_bound; - int lower_idx; - int upper_idx; + size_t lower_idx; + size_t upper_idx; GPR_ASSERT(h->count >= 1); diff --git a/src/core/support/log_win32.c b/src/core/support/log_win32.c index f5710fa1794..fb2fc0c2395 100644 --- a/src/core/support/log_win32.c +++ b/src/core/support/log_win32.c @@ -40,8 +40,8 @@ #include /* Simple starter implementation */ -void gpr_log(char *file, int line, gpr_log_severity severity, char *format, - ...) { +void gpr_log(const char *file, int line, gpr_log_severity severity, + const char *format, ...) { va_list args; va_start(args, format); diff --git a/src/core/support/string_win32.c b/src/core/support/string_win32.c index 74b10280eb6..1c4c8547dc9 100644 --- a/src/core/support/string_win32.c +++ b/src/core/support/string_win32.c @@ -50,7 +50,7 @@ int gpr_asprintf(char **strp, const char *format, ...) { /* Determine the length. */ va_start(args, format); - ret = vscprintf(format, args); + ret = _vscprintf(format, args); va_end(args); if (!(0 <= ret && ret < ~(size_t)0)) { *strp = NULL; diff --git a/src/core/support/sync_posix.c b/src/core/support/sync_posix.c index 257a7fbf4eb..7f0e4a95a43 100644 --- a/src/core/support/sync_posix.c +++ b/src/core/support/sync_posix.c @@ -33,6 +33,10 @@ /* Posix gpr synchroization support code. */ +#include + +#ifdef GPR_POSIX_SYNC + #include #include #include @@ -80,3 +84,5 @@ void gpr_cv_broadcast(gpr_cv *cv) { void gpr_once_init(gpr_once *once, void (*init_function)(void)) { GPR_ASSERT(pthread_once(once, init_function) == 0); } + +#endif /* GRP_POSIX_SYNC */ diff --git a/src/core/support/sync_win32.c b/src/core/support/sync_win32.c index 63dd4eb708c..eadaa970c98 100644 --- a/src/core/support/sync_win32.c +++ b/src/core/support/sync_win32.c @@ -33,6 +33,10 @@ /* Win32 code for gpr synchronization support. */ +#include + +#ifdef GPR_WIN32 + #define _WIN32_WINNT 0x0600 #include #include @@ -107,7 +111,7 @@ static void *dummy; struct run_once_func_arg { void (*init_function)(void); }; -static int run_once_func(gpr_once *once, void *v, void **pv) { +static BOOL CALLBACK run_once_func(gpr_once *once, void *v, void **pv) { struct run_once_func_arg *arg = v; (*arg->init_function)(); return 1; @@ -116,5 +120,7 @@ static int run_once_func(gpr_once *once, void *v, void **pv) { void gpr_once_init(gpr_once *once, void (*init_function)(void)) { struct run_once_func_arg arg; arg.init_function = init_function; - InitOnceExecuteOnce(once, &run_once_func, &arg, &dummy); + InitOnceExecuteOnce(once, run_once_func, &arg, &dummy); } + +#endif /* GPR_WIN32 */ diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c index d9abe2dde1b..b9fe5123350 100644 --- a/src/core/support/time_win32.c +++ b/src/core/support/time_win32.c @@ -42,8 +42,8 @@ gpr_timespec gpr_now(void) { gpr_timespec now_tv; - struct __timeb64 now_tb; - _ftime64_s(&now_tb); + struct __timeb32 now_tb; + _ftime32_s(&now_tb); now_tv.tv_sec = now_tb.time; now_tv.tv_nsec = now_tb.millitm * 1000000; return now_tv; diff --git a/templates/vsprojects/vs2013/vcxproj_defs.include b/templates/vsprojects/vs2013/vcxproj_defs.include index 37fe97d4eaa..fea86ddf361 100644 --- a/templates/vsprojects/vs2013/vcxproj_defs.include +++ b/templates/vsprojects/vs2013/vcxproj_defs.include @@ -47,6 +47,7 @@ project_dict = dict([(p.name, p) for p in projects]) true v120 Unicode + $(Configuration)\$(ProjectName)\ ${get_configuration_type(project.is_library)} @@ -54,6 +55,7 @@ project_dict = dict([(p.name, p) for p in projects]) v120 true Unicode + $(Configuration)\$(ProjectName)\ @@ -71,7 +73,7 @@ project_dict = dict([(p.name, p) for p in projects]) NotUsing Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) @@ -87,7 +89,7 @@ project_dict = dict([(p.name, p) for p in projects]) MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) diff --git a/vsprojects/vs2013/gpr.vcxproj b/vsprojects/vs2013/gpr.vcxproj index f4b30534a64..a7b07c21a32 100644 --- a/vsprojects/vs2013/gpr.vcxproj +++ b/vsprojects/vs2013/gpr.vcxproj @@ -21,6 +21,7 @@ true v120 Unicode + $(Configuration)\$(ProjectName)\ StaticLibrary @@ -28,6 +29,7 @@ v120 true Unicode + $(Configuration)\$(ProjectName)\ @@ -45,7 +47,7 @@ NotUsing Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) @@ -61,7 +63,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) @@ -143,6 +145,8 @@ + + diff --git a/vsprojects/vs2013/gpr_cancellable_test.vcxproj b/vsprojects/vs2013/gpr_cancellable_test.vcxproj index 447d3b78022..890541a86fc 100644 --- a/vsprojects/vs2013/gpr_cancellable_test.vcxproj +++ b/vsprojects/vs2013/gpr_cancellable_test.vcxproj @@ -21,6 +21,7 @@ true v120 Unicode + $(Configuration)\$(ProjectName)\ Application @@ -28,6 +29,7 @@ v120 true Unicode + $(Configuration)\$(ProjectName)\ @@ -45,7 +47,7 @@ NotUsing Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) @@ -61,7 +63,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) diff --git a/vsprojects/vs2013/gpr_cmdline_test.vcxproj b/vsprojects/vs2013/gpr_cmdline_test.vcxproj index 0ff731c2935..705bd87fc1d 100644 --- a/vsprojects/vs2013/gpr_cmdline_test.vcxproj +++ b/vsprojects/vs2013/gpr_cmdline_test.vcxproj @@ -21,6 +21,7 @@ true v120 Unicode + $(Configuration)\$(ProjectName)\ Application @@ -28,6 +29,7 @@ v120 true Unicode + $(Configuration)\$(ProjectName)\ @@ -45,7 +47,7 @@ NotUsing Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) @@ -61,7 +63,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) diff --git a/vsprojects/vs2013/gpr_log_test.vcxproj b/vsprojects/vs2013/gpr_log_test.vcxproj index 9354773be44..d1d1f0ad139 100644 --- a/vsprojects/vs2013/gpr_log_test.vcxproj +++ b/vsprojects/vs2013/gpr_log_test.vcxproj @@ -21,6 +21,7 @@ true v120 Unicode + $(Configuration)\$(ProjectName)\ Application @@ -28,6 +29,7 @@ v120 true Unicode + $(Configuration)\$(ProjectName)\ @@ -45,7 +47,7 @@ NotUsing Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) @@ -61,7 +63,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) diff --git a/vsprojects/vs2013/grpc.vcxproj b/vsprojects/vs2013/grpc.vcxproj index 85c36be9ca2..993dff3a667 100644 --- a/vsprojects/vs2013/grpc.vcxproj +++ b/vsprojects/vs2013/grpc.vcxproj @@ -21,6 +21,7 @@ true v120 Unicode + $(Configuration)\$(ProjectName)\ StaticLibrary @@ -28,6 +29,7 @@ v120 true Unicode + $(Configuration)\$(ProjectName)\ @@ -45,7 +47,7 @@ NotUsing Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) @@ -61,7 +63,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) diff --git a/vsprojects/vs2013/grpc_test_util.vcxproj b/vsprojects/vs2013/grpc_test_util.vcxproj index 8fee039bb7c..6c131f54d15 100644 --- a/vsprojects/vs2013/grpc_test_util.vcxproj +++ b/vsprojects/vs2013/grpc_test_util.vcxproj @@ -21,6 +21,7 @@ true v120 Unicode + $(Configuration)\$(ProjectName)\ StaticLibrary @@ -28,6 +29,7 @@ v120 true Unicode + $(Configuration)\$(ProjectName)\ @@ -45,7 +47,7 @@ NotUsing Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories) @@ -61,7 +63,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;_USE_32BIT_TIME_T;%(PreprocessorDefinitions) true $(SolutionDir)\..\..;$(SolutionDir)\..\..\include;%(AdditionalIncludeDirectories)