Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: third_party/tcmalloc/chromium/src/windows/port.h

Issue 9666033: Experiment for updating the tcmalloc chromium branch to r144 (gperftools 2.0). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 substracting two size_t's to an int 68 * 4244: otherwise we get problems when subtracting 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
73 */ 74 */
74 #ifdef _MSC_VER 75 #ifdef _MSC_VER
75 #pragma warning(disable:4018 4244 4288 4267 4290 4996) 76 #pragma warning(disable:4018 4244 4288 4267 4290 4996 4146)
76 #endif 77 #endif
77 78
78 #ifndef __cplusplus 79 #ifndef __cplusplus
79 /* MSVC does not support C99 */ 80 /* MSVC does not support C99 */
80 # if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L 81 # if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
81 # ifdef _MSC_VER 82 # ifdef _MSC_VER
82 # define inline __inline 83 # define inline __inline
83 # else 84 # else
84 # define inline static 85 # define inline static
85 # endif 86 # endif
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 else 159 else
159 return GetLastError(); 160 return GetLastError();
160 } 161 }
161 162
162 EXTERN_C int perftools_pthread_once(pthread_once_t *once_control, 163 EXTERN_C int perftools_pthread_once(pthread_once_t *once_control,
163 void (*init_routine)(void)); 164 void (*init_routine)(void));
164 165
165 #endif /* __cplusplus */ 166 #endif /* __cplusplus */
166 #endif /* HAVE_PTHREAD */ 167 #endif /* HAVE_PTHREAD */
167 168
169 inline void sched_yield(void) {
170 Sleep(0);
171 }
172
168 /* 173 /*
169 * __declspec(thread) isn't usable in a dll opened via LoadLibrary(). 174 * __declspec(thread) isn't usable in a dll opened via LoadLibrary().
170 * But it doesn't work to LoadLibrary() us anyway, because of all the 175 * But it doesn't work to LoadLibrary() us anyway, because of all the
171 * things we need to do before main()! So this kind of TLS is safe for us. 176 * things we need to do before main()! So this kind of TLS is safe for us.
172 */ 177 */
173 #define __thread __declspec(thread) 178 #define __thread __declspec(thread)
174 179
175 /* 180 /*
176 * This code is obsolete, but I keep it around in case we are ever in 181 * This code is obsolete, but I keep it around in case we are ever in
177 * an environment where we can't or don't want to use google spinlocks 182 * 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
253 #ifndef HAVE_MMAP /* not true for MSVC, but may be true for msys */ 258 #ifndef HAVE_MMAP /* not true for MSVC, but may be true for msys */
254 #define MAP_FAILED 0 259 #define MAP_FAILED 0
255 #define MREMAP_FIXED 2 /* the value in linux, though it doesn't really matter */ 260 #define MREMAP_FIXED 2 /* the value in linux, though it doesn't really matter */
256 /* These, when combined with the mmap invariants below, yield the proper action */ 261 /* These, when combined with the mmap invariants below, yield the proper action */
257 #define PROT_READ PAGE_READWRITE 262 #define PROT_READ PAGE_READWRITE
258 #define PROT_WRITE PAGE_READWRITE 263 #define PROT_WRITE PAGE_READWRITE
259 #define MAP_ANONYMOUS MEM_RESERVE 264 #define MAP_ANONYMOUS MEM_RESERVE
260 #define MAP_PRIVATE MEM_COMMIT 265 #define MAP_PRIVATE MEM_COMMIT
261 #define MAP_SHARED MEM_RESERVE /* value of this #define is 100% arbitrary */ 266 #define MAP_SHARED MEM_RESERVE /* value of this #define is 100% arbitrary */
262 267
263 #if __STDC__ 268 #if __STDC__ && !defined(__MINGW32__)
264 typedef _off_t off_t; 269 typedef _off_t off_t;
265 #endif 270 #endif
266 271
267 /* VirtualAlloc only replaces for mmap when certain invariants are kept. */ 272 /* VirtualAlloc only replaces for mmap when certain invariants are kept. */
268 inline void *mmap(void *addr, size_t length, int prot, int flags, 273 inline void *mmap(void *addr, size_t length, int prot, int flags,
269 int fd, off_t offset) { 274 int fd, off_t offset) {
270 if (addr == NULL && fd == -1 && offset == 0 && 275 if (addr == NULL && fd == -1 && offset == 0 &&
271 prot == (PROT_READ|PROT_WRITE) && flags == (MAP_PRIVATE|MAP_ANONYMOUS)) { 276 prot == (PROT_READ|PROT_WRITE) && flags == (MAP_PRIVATE|MAP_ANONYMOUS)) {
272 return VirtualAlloc(0, length, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); 277 return VirtualAlloc(0, length, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
273 } else { 278 } else {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 } 370 }
366 inline off_t lseek(int fd, off_t offset, int whence) { 371 inline off_t lseek(int fd, off_t offset, int whence) {
367 return _lseek(fd, offset, whence); 372 return _lseek(fd, offset, whence);
368 } 373 }
369 inline char *getcwd(char *buf, size_t size) { 374 inline char *getcwd(char *buf, size_t size) {
370 return _getcwd(buf, size); 375 return _getcwd(buf, size);
371 } 376 }
372 inline int mkdir(const char *pathname, int) { 377 inline int mkdir(const char *pathname, int) {
373 return _mkdir(pathname); 378 return _mkdir(pathname);
374 } 379 }
375 #endif
376 380
377 inline FILE *popen(const char *command, const char *type) { 381 inline FILE *popen(const char *command, const char *type) {
378 return _popen(command, type); 382 return _popen(command, type);
379 } 383 }
380 inline int pclose(FILE *stream) { 384 inline int pclose(FILE *stream) {
381 return _pclose(stream); 385 return _pclose(stream);
382 } 386 }
387 #endif
383 388
384 EXTERN_C PERFTOOLS_DLL_DECL void WriteToStderr(const char* buf, int len); 389 EXTERN_C PERFTOOLS_DLL_DECL void WriteToStderr(const char* buf, int len);
385 390
386 /* ----------------------------------- SYSTEM/PROCESS */ 391 /* ----------------------------------- SYSTEM/PROCESS */
387 392
388 typedef int pid_t; 393 typedef int pid_t;
389 #if __STDC__ 394 #if __STDC__ && !defined(__MINGW32__)
390 inline pid_t getpid(void) { return _getpid(); } 395 inline pid_t getpid(void) { return _getpid(); }
391 #endif 396 #endif
392 inline pid_t getppid(void) { return 0; } 397 inline pid_t getppid(void) { return 0; }
393 398
394 /* Handle case when poll is used to simulate sleep. */ 399 /* Handle case when poll is used to simulate sleep. */
395 inline int poll(struct pollfd* fds, int nfds, int timeout) { 400 inline int poll(struct pollfd* fds, int nfds, int timeout) {
396 assert(fds == NULL); 401 assert(fds == NULL);
397 assert(nfds == 0); 402 assert(nfds == 0);
398 Sleep(timeout); 403 Sleep(timeout);
399 return 0; 404 return 0;
400 } 405 }
401 406
402 EXTERN_C int getpagesize(); /* in port.cc */ 407 EXTERN_C int getpagesize(); /* in port.cc */
403 408
404 /* ----------------------------------- OTHER */ 409 /* ----------------------------------- OTHER */
405 410
406 inline void srandom(unsigned int seed) { srand(seed); } 411 inline void srandom(unsigned int seed) { srand(seed); }
407 inline long random(void) { return rand(); } 412 inline long random(void) { return rand(); }
408 inline unsigned int sleep(unsigned int seconds) { 413 inline unsigned int sleep(unsigned int seconds) {
409 Sleep(seconds * 1000); 414 Sleep(seconds * 1000);
410 return 0; 415 return 0;
411 } 416 }
412 417
418 // mingw64 seems to define timespec (though mingw.org mingw doesn't),
419 // protected by the _TIMESPEC_DEFINED macro.
420 #ifndef _TIMESPEC_DEFINED
413 struct timespec { 421 struct timespec {
414 int tv_sec; 422 int tv_sec;
415 int tv_nsec; 423 int tv_nsec;
416 }; 424 };
425 #endif
417 426
418 inline int nanosleep(const struct timespec *req, struct timespec *rem) { 427 inline int nanosleep(const struct timespec *req, struct timespec *rem) {
419 Sleep(req->tv_sec * 1000 + req->tv_nsec / 1000000); 428 Sleep(req->tv_sec * 1000 + req->tv_nsec / 1000000);
420 return 0; 429 return 0;
421 } 430 }
422 431
423 #ifndef __MINGW32__ 432 #ifndef __MINGW32__
424 inline long long int strtoll(const char *nptr, char **endptr, int base) { 433 inline long long int strtoll(const char *nptr, char **endptr, int base) {
425 return _strtoi64(nptr, endptr, base); 434 return _strtoi64(nptr, endptr, base);
426 } 435 }
(...skipping 29 matching lines...) Expand all
456 */ 465 */
457 #define GOOGLE_MAYBE_THREADS_H_ 1 466 #define GOOGLE_MAYBE_THREADS_H_ 1
458 467
459 468
460 #endif /* _WIN32 */ 469 #endif /* _WIN32 */
461 470
462 #undef inline 471 #undef inline
463 #undef EXTERN_C 472 #undef EXTERN_C
464 473
465 #endif /* GOOGLE_BASE_WINDOWS_H_ */ 474 #endif /* GOOGLE_BASE_WINDOWS_H_ */
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/windows/patch_functions.cc ('k') | third_party/tcmalloc/chromium/src/windows/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698