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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 else | 158 else |
159 return GetLastError(); | 159 return GetLastError(); |
160 } | 160 } |
161 | 161 |
162 EXTERN_C int perftools_pthread_once(pthread_once_t *once_control, | 162 EXTERN_C int perftools_pthread_once(pthread_once_t *once_control, |
163 void (*init_routine)(void)); | 163 void (*init_routine)(void)); |
164 | 164 |
165 #endif /* __cplusplus */ | 165 #endif /* __cplusplus */ |
166 #endif /* HAVE_PTHREAD */ | 166 #endif /* HAVE_PTHREAD */ |
167 | 167 |
| 168 inline void sched_yield(void) { |
| 169 Sleep(0); |
| 170 } |
| 171 |
168 /* | 172 /* |
169 * __declspec(thread) isn't usable in a dll opened via LoadLibrary(). | 173 * __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 | 174 * 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. | 175 * things we need to do before main()! So this kind of TLS is safe for us. |
172 */ | 176 */ |
173 #define __thread __declspec(thread) | 177 #define __thread __declspec(thread) |
174 | 178 |
175 /* | 179 /* |
176 * This code is obsolete, but I keep it around in case we are ever in | 180 * 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 | 181 * 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... |
253 #ifndef HAVE_MMAP /* not true for MSVC, but may be true for msys */ | 257 #ifndef HAVE_MMAP /* not true for MSVC, but may be true for msys */ |
254 #define MAP_FAILED 0 | 258 #define MAP_FAILED 0 |
255 #define MREMAP_FIXED 2 /* the value in linux, though it doesn't really matter
*/ | 259 #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
*/ | 260 /* These, when combined with the mmap invariants below, yield the proper action
*/ |
257 #define PROT_READ PAGE_READWRITE | 261 #define PROT_READ PAGE_READWRITE |
258 #define PROT_WRITE PAGE_READWRITE | 262 #define PROT_WRITE PAGE_READWRITE |
259 #define MAP_ANONYMOUS MEM_RESERVE | 263 #define MAP_ANONYMOUS MEM_RESERVE |
260 #define MAP_PRIVATE MEM_COMMIT | 264 #define MAP_PRIVATE MEM_COMMIT |
261 #define MAP_SHARED MEM_RESERVE /* value of this #define is 100% arbitrary
*/ | 265 #define MAP_SHARED MEM_RESERVE /* value of this #define is 100% arbitrary
*/ |
262 | 266 |
263 #if __STDC__ | 267 #if __STDC__ && !defined(__MINGW32__) |
264 typedef _off_t off_t; | 268 typedef _off_t off_t; |
265 #endif | 269 #endif |
266 | 270 |
267 /* VirtualAlloc only replaces for mmap when certain invariants are kept. */ | 271 /* VirtualAlloc only replaces for mmap when certain invariants are kept. */ |
268 inline void *mmap(void *addr, size_t length, int prot, int flags, | 272 inline void *mmap(void *addr, size_t length, int prot, int flags, |
269 int fd, off_t offset) { | 273 int fd, off_t offset) { |
270 if (addr == NULL && fd == -1 && offset == 0 && | 274 if (addr == NULL && fd == -1 && offset == 0 && |
271 prot == (PROT_READ|PROT_WRITE) && flags == (MAP_PRIVATE|MAP_ANONYMOUS)) { | 275 prot == (PROT_READ|PROT_WRITE) && flags == (MAP_PRIVATE|MAP_ANONYMOUS)) { |
272 return VirtualAlloc(0, length, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | 276 return VirtualAlloc(0, length, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); |
273 } else { | 277 } else { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 } | 369 } |
366 inline off_t lseek(int fd, off_t offset, int whence) { | 370 inline off_t lseek(int fd, off_t offset, int whence) { |
367 return _lseek(fd, offset, whence); | 371 return _lseek(fd, offset, whence); |
368 } | 372 } |
369 inline char *getcwd(char *buf, size_t size) { | 373 inline char *getcwd(char *buf, size_t size) { |
370 return _getcwd(buf, size); | 374 return _getcwd(buf, size); |
371 } | 375 } |
372 inline int mkdir(const char *pathname, int) { | 376 inline int mkdir(const char *pathname, int) { |
373 return _mkdir(pathname); | 377 return _mkdir(pathname); |
374 } | 378 } |
375 #endif | |
376 | 379 |
377 inline FILE *popen(const char *command, const char *type) { | 380 inline FILE *popen(const char *command, const char *type) { |
378 return _popen(command, type); | 381 return _popen(command, type); |
379 } | 382 } |
380 inline int pclose(FILE *stream) { | 383 inline int pclose(FILE *stream) { |
381 return _pclose(stream); | 384 return _pclose(stream); |
382 } | 385 } |
| 386 #endif |
383 | 387 |
384 EXTERN_C PERFTOOLS_DLL_DECL void WriteToStderr(const char* buf, int len); | 388 EXTERN_C PERFTOOLS_DLL_DECL void WriteToStderr(const char* buf, int len); |
385 | 389 |
386 /* ----------------------------------- SYSTEM/PROCESS */ | 390 /* ----------------------------------- SYSTEM/PROCESS */ |
387 | 391 |
388 typedef int pid_t; | 392 typedef int pid_t; |
389 #if __STDC__ | 393 #if __STDC__ && !defined(__MINGW32__) |
390 inline pid_t getpid(void) { return _getpid(); } | 394 inline pid_t getpid(void) { return _getpid(); } |
391 #endif | 395 #endif |
392 inline pid_t getppid(void) { return 0; } | 396 inline pid_t getppid(void) { return 0; } |
393 | 397 |
394 /* Handle case when poll is used to simulate sleep. */ | 398 /* Handle case when poll is used to simulate sleep. */ |
395 inline int poll(struct pollfd* fds, int nfds, int timeout) { | 399 inline int poll(struct pollfd* fds, int nfds, int timeout) { |
396 assert(fds == NULL); | 400 assert(fds == NULL); |
397 assert(nfds == 0); | 401 assert(nfds == 0); |
398 Sleep(timeout); | 402 Sleep(timeout); |
399 return 0; | 403 return 0; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 */ | 460 */ |
457 #define GOOGLE_MAYBE_THREADS_H_ 1 | 461 #define GOOGLE_MAYBE_THREADS_H_ 1 |
458 | 462 |
459 | 463 |
460 #endif /* _WIN32 */ | 464 #endif /* _WIN32 */ |
461 | 465 |
462 #undef inline | 466 #undef inline |
463 #undef EXTERN_C | 467 #undef EXTERN_C |
464 | 468 |
465 #endif /* GOOGLE_BASE_WINDOWS_H_ */ | 469 #endif /* GOOGLE_BASE_WINDOWS_H_ */ |
OLD | NEW |