| OLD | NEW |
| 1 /* Copyright (c) 2007, Google Inc. | 1 /* Copyright (c) 2007, Google Inc. |
| 2 * All rights reserved. | 2 * All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #include <process.h> /* for _getpid */ | 58 #include <process.h> /* for _getpid */ |
| 59 #include <limits.h> /* for PATH_MAX */ | 59 #include <limits.h> /* for PATH_MAX */ |
| 60 #include <stdarg.h> /* for va_list */ | 60 #include <stdarg.h> /* for va_list */ |
| 61 #include <stdio.h> /* need this to override stdio's (v)snprintf */ | 61 #include <stdio.h> /* need this to override stdio's (v)snprintf */ |
| 62 #include <sys/types.h> /* for _off_t */ | 62 #include <sys/types.h> /* for _off_t */ |
| 63 #include <assert.h> | 63 #include <assert.h> |
| 64 #include <stdlib.h> /* for rand, srand, _strtoxxx */ | 64 #include <stdlib.h> /* for rand, srand, _strtoxxx */ |
| 65 | 65 |
| 66 /* | 66 /* |
| 67 * 4018: signed/unsigned mismatch is common (and ok for signed_i < unsigned_i) | 67 * 4018: signed/unsigned mismatch is common (and ok for signed_i < unsigned_i) |
| 68 * 4244: otherwise we get problems when subtracting two size_t's to an int | 68 * 4244: otherwise we get problems when substracting two size_t's to an int |
| 69 * 4288: VC++7 gets confused when a var is defined in a loop and then after it | 69 * 4288: VC++7 gets confused when a var is defined in a loop and then after it |
| 70 * 4267: too many false positives for "conversion gives possible data loss" | 70 * 4267: too many false positives for "conversion gives possible data loss" |
| 71 * 4290: it's ok windows ignores the "throw" directive | 71 * 4290: it's ok windows ignores the "throw" directive |
| 72 * 4996: Yes, we're ok using "unsafe" functions like vsnprintf and getenv() | 72 * 4996: Yes, we're ok using "unsafe" functions like vsnprintf and getenv() |
| 73 * 4146: internal_logging.cc intentionally negates an unsigned value | |
| 74 */ | 73 */ |
| 75 #ifdef _MSC_VER | 74 #ifdef _MSC_VER |
| 76 #pragma warning(disable:4018 4244 4288 4267 4290 4996 4146) | 75 #pragma warning(disable:4018 4244 4288 4267 4290 4996) |
| 77 #endif | 76 #endif |
| 78 | 77 |
| 79 #ifndef __cplusplus | 78 #ifndef __cplusplus |
| 80 /* MSVC does not support C99 */ | 79 /* MSVC does not support C99 */ |
| 81 # if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L | 80 # if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L |
| 82 # ifdef _MSC_VER | 81 # ifdef _MSC_VER |
| 83 # define inline __inline | 82 # define inline __inline |
| 84 # else | 83 # else |
| 85 # define inline static | 84 # define inline static |
| 86 # endif | 85 # endif |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 else | 158 else |
| 160 return GetLastError(); | 159 return GetLastError(); |
| 161 } | 160 } |
| 162 | 161 |
| 163 EXTERN_C int perftools_pthread_once(pthread_once_t *once_control, | 162 EXTERN_C int perftools_pthread_once(pthread_once_t *once_control, |
| 164 void (*init_routine)(void)); | 163 void (*init_routine)(void)); |
| 165 | 164 |
| 166 #endif /* __cplusplus */ | 165 #endif /* __cplusplus */ |
| 167 #endif /* HAVE_PTHREAD */ | 166 #endif /* HAVE_PTHREAD */ |
| 168 | 167 |
| 169 inline void sched_yield(void) { | |
| 170 Sleep(0); | |
| 171 } | |
| 172 | |
| 173 /* | 168 /* |
| 174 * __declspec(thread) isn't usable in a dll opened via LoadLibrary(). | 169 * __declspec(thread) isn't usable in a dll opened via LoadLibrary(). |
| 175 * But it doesn't work to LoadLibrary() us anyway, because of all the | 170 * But it doesn't work to LoadLibrary() us anyway, because of all the |
| 176 * things we need to do before main()! So this kind of TLS is safe for us. | 171 * things we need to do before main()! So this kind of TLS is safe for us. |
| 177 */ | 172 */ |
| 178 #define __thread __declspec(thread) | 173 #define __thread __declspec(thread) |
| 179 | 174 |
| 180 /* | 175 /* |
| 181 * This code is obsolete, but I keep it around in case we are ever in | 176 * This code is obsolete, but I keep it around in case we are ever in |
| 182 * an environment where we can't or don't want to use google spinlocks | 177 * an environment where we can't or don't want to use google spinlocks |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 #ifndef HAVE_MMAP /* not true for MSVC, but may be true for msys */ | 253 #ifndef HAVE_MMAP /* not true for MSVC, but may be true for msys */ |
| 259 #define MAP_FAILED 0 | 254 #define MAP_FAILED 0 |
| 260 #define MREMAP_FIXED 2 /* the value in linux, though it doesn't really matter
*/ | 255 #define MREMAP_FIXED 2 /* the value in linux, though it doesn't really matter
*/ |
| 261 /* These, when combined with the mmap invariants below, yield the proper action
*/ | 256 /* These, when combined with the mmap invariants below, yield the proper action
*/ |
| 262 #define PROT_READ PAGE_READWRITE | 257 #define PROT_READ PAGE_READWRITE |
| 263 #define PROT_WRITE PAGE_READWRITE | 258 #define PROT_WRITE PAGE_READWRITE |
| 264 #define MAP_ANONYMOUS MEM_RESERVE | 259 #define MAP_ANONYMOUS MEM_RESERVE |
| 265 #define MAP_PRIVATE MEM_COMMIT | 260 #define MAP_PRIVATE MEM_COMMIT |
| 266 #define MAP_SHARED MEM_RESERVE /* value of this #define is 100% arbitrary
*/ | 261 #define MAP_SHARED MEM_RESERVE /* value of this #define is 100% arbitrary
*/ |
| 267 | 262 |
| 268 #if __STDC__ && !defined(__MINGW32__) | 263 #if __STDC__ |
| 269 typedef _off_t off_t; | 264 typedef _off_t off_t; |
| 270 #endif | 265 #endif |
| 271 | 266 |
| 272 /* VirtualAlloc only replaces for mmap when certain invariants are kept. */ | 267 /* VirtualAlloc only replaces for mmap when certain invariants are kept. */ |
| 273 inline void *mmap(void *addr, size_t length, int prot, int flags, | 268 inline void *mmap(void *addr, size_t length, int prot, int flags, |
| 274 int fd, off_t offset) { | 269 int fd, off_t offset) { |
| 275 if (addr == NULL && fd == -1 && offset == 0 && | 270 if (addr == NULL && fd == -1 && offset == 0 && |
| 276 prot == (PROT_READ|PROT_WRITE) && flags == (MAP_PRIVATE|MAP_ANONYMOUS)) { | 271 prot == (PROT_READ|PROT_WRITE) && flags == (MAP_PRIVATE|MAP_ANONYMOUS)) { |
| 277 return VirtualAlloc(0, length, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | 272 return VirtualAlloc(0, length, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); |
| 278 } else { | 273 } else { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 365 } |
| 371 inline off_t lseek(int fd, off_t offset, int whence) { | 366 inline off_t lseek(int fd, off_t offset, int whence) { |
| 372 return _lseek(fd, offset, whence); | 367 return _lseek(fd, offset, whence); |
| 373 } | 368 } |
| 374 inline char *getcwd(char *buf, size_t size) { | 369 inline char *getcwd(char *buf, size_t size) { |
| 375 return _getcwd(buf, size); | 370 return _getcwd(buf, size); |
| 376 } | 371 } |
| 377 inline int mkdir(const char *pathname, int) { | 372 inline int mkdir(const char *pathname, int) { |
| 378 return _mkdir(pathname); | 373 return _mkdir(pathname); |
| 379 } | 374 } |
| 375 #endif |
| 380 | 376 |
| 381 inline FILE *popen(const char *command, const char *type) { | 377 inline FILE *popen(const char *command, const char *type) { |
| 382 return _popen(command, type); | 378 return _popen(command, type); |
| 383 } | 379 } |
| 384 inline int pclose(FILE *stream) { | 380 inline int pclose(FILE *stream) { |
| 385 return _pclose(stream); | 381 return _pclose(stream); |
| 386 } | 382 } |
| 387 #endif | |
| 388 | 383 |
| 389 EXTERN_C PERFTOOLS_DLL_DECL void WriteToStderr(const char* buf, int len); | 384 EXTERN_C PERFTOOLS_DLL_DECL void WriteToStderr(const char* buf, int len); |
| 390 | 385 |
| 391 /* ----------------------------------- SYSTEM/PROCESS */ | 386 /* ----------------------------------- SYSTEM/PROCESS */ |
| 392 | 387 |
| 393 typedef int pid_t; | 388 typedef int pid_t; |
| 394 #if __STDC__ && !defined(__MINGW32__) | 389 #if __STDC__ |
| 395 inline pid_t getpid(void) { return _getpid(); } | 390 inline pid_t getpid(void) { return _getpid(); } |
| 396 #endif | 391 #endif |
| 397 inline pid_t getppid(void) { return 0; } | 392 inline pid_t getppid(void) { return 0; } |
| 398 | 393 |
| 399 /* Handle case when poll is used to simulate sleep. */ | 394 /* Handle case when poll is used to simulate sleep. */ |
| 400 inline int poll(struct pollfd* fds, int nfds, int timeout) { | 395 inline int poll(struct pollfd* fds, int nfds, int timeout) { |
| 401 assert(fds == NULL); | 396 assert(fds == NULL); |
| 402 assert(nfds == 0); | 397 assert(nfds == 0); |
| 403 Sleep(timeout); | 398 Sleep(timeout); |
| 404 return 0; | 399 return 0; |
| 405 } | 400 } |
| 406 | 401 |
| 407 EXTERN_C int getpagesize(); /* in port.cc */ | 402 EXTERN_C int getpagesize(); /* in port.cc */ |
| 408 | 403 |
| 409 /* ----------------------------------- OTHER */ | 404 /* ----------------------------------- OTHER */ |
| 410 | 405 |
| 411 inline void srandom(unsigned int seed) { srand(seed); } | 406 inline void srandom(unsigned int seed) { srand(seed); } |
| 412 inline long random(void) { return rand(); } | 407 inline long random(void) { return rand(); } |
| 413 inline unsigned int sleep(unsigned int seconds) { | 408 inline unsigned int sleep(unsigned int seconds) { |
| 414 Sleep(seconds * 1000); | 409 Sleep(seconds * 1000); |
| 415 return 0; | 410 return 0; |
| 416 } | 411 } |
| 417 | 412 |
| 418 // mingw64 seems to define timespec (though mingw.org mingw doesn't), | |
| 419 // protected by the _TIMESPEC_DEFINED macro. | |
| 420 #ifndef _TIMESPEC_DEFINED | |
| 421 struct timespec { | 413 struct timespec { |
| 422 int tv_sec; | 414 int tv_sec; |
| 423 int tv_nsec; | 415 int tv_nsec; |
| 424 }; | 416 }; |
| 425 #endif | |
| 426 | 417 |
| 427 inline int nanosleep(const struct timespec *req, struct timespec *rem) { | 418 inline int nanosleep(const struct timespec *req, struct timespec *rem) { |
| 428 Sleep(req->tv_sec * 1000 + req->tv_nsec / 1000000); | 419 Sleep(req->tv_sec * 1000 + req->tv_nsec / 1000000); |
| 429 return 0; | 420 return 0; |
| 430 } | 421 } |
| 431 | 422 |
| 432 #ifndef __MINGW32__ | 423 #ifndef __MINGW32__ |
| 433 inline long long int strtoll(const char *nptr, char **endptr, int base) { | 424 inline long long int strtoll(const char *nptr, char **endptr, int base) { |
| 434 return _strtoi64(nptr, endptr, base); | 425 return _strtoi64(nptr, endptr, base); |
| 435 } | 426 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 465 */ | 456 */ |
| 466 #define GOOGLE_MAYBE_THREADS_H_ 1 | 457 #define GOOGLE_MAYBE_THREADS_H_ 1 |
| 467 | 458 |
| 468 | 459 |
| 469 #endif /* _WIN32 */ | 460 #endif /* _WIN32 */ |
| 470 | 461 |
| 471 #undef inline | 462 #undef inline |
| 472 #undef EXTERN_C | 463 #undef EXTERN_C |
| 473 | 464 |
| 474 #endif /* GOOGLE_BASE_WINDOWS_H_ */ | 465 #endif /* GOOGLE_BASE_WINDOWS_H_ */ |
| OLD | NEW |