| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 #endif | 208 #endif |
| 209 } | 209 } |
| 210 | 210 |
| 211 | 211 |
| 212 class PosixMemoryMappedFile : public OS::MemoryMappedFile { | 212 class PosixMemoryMappedFile : public OS::MemoryMappedFile { |
| 213 public: | 213 public: |
| 214 PosixMemoryMappedFile(FILE* file, void* memory, int size) | 214 PosixMemoryMappedFile(FILE* file, void* memory, int size) |
| 215 : file_(file), memory_(memory), size_(size) { } | 215 : file_(file), memory_(memory), size_(size) { } |
| 216 virtual ~PosixMemoryMappedFile(); | 216 virtual ~PosixMemoryMappedFile(); |
| 217 virtual void* memory() { return memory_; } | 217 virtual void* memory() { return memory_; } |
| 218 virtual int size() { return size_; } |
| 218 private: | 219 private: |
| 219 FILE* file_; | 220 FILE* file_; |
| 220 void* memory_; | 221 void* memory_; |
| 221 int size_; | 222 int size_; |
| 222 }; | 223 }; |
| 223 | 224 |
| 224 | 225 |
| 226 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { |
| 227 FILE* file = fopen(name, "w+"); |
| 228 if (file == NULL) return NULL; |
| 229 |
| 230 fseek(file, 0, SEEK_END); |
| 231 int size = ftell(file); |
| 232 |
| 233 void* memory = |
| 234 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); |
| 235 return new PosixMemoryMappedFile(file, memory, size); |
| 236 } |
| 237 |
| 238 |
| 225 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, | 239 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, |
| 226 void* initial) { | 240 void* initial) { |
| 227 FILE* file = fopen(name, "w+"); | 241 FILE* file = fopen(name, "w+"); |
| 228 if (file == NULL) return NULL; | 242 if (file == NULL) return NULL; |
| 229 int result = fwrite(initial, size, 1, file); | 243 int result = fwrite(initial, size, 1, file); |
| 230 if (result < 1) { | 244 if (result < 1) { |
| 231 fclose(file); | 245 fclose(file); |
| 232 return NULL; | 246 return NULL; |
| 233 } | 247 } |
| 234 void* memory = | 248 void* memory = |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 return data_->thread_ != kNoThread; | 423 return data_->thread_ != kNoThread; |
| 410 } | 424 } |
| 411 | 425 |
| 412 | 426 |
| 413 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { | 427 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { |
| 414 set_name("v8:<unknown>"); | 428 set_name("v8:<unknown>"); |
| 415 } | 429 } |
| 416 | 430 |
| 417 | 431 |
| 418 Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) { | 432 Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) { |
| 419 set_names(name); | 433 set_name(name); |
| 420 } | 434 } |
| 421 | 435 |
| 422 | 436 |
| 423 Thread::~Thread() { | 437 Thread::~Thread() { |
| 424 } | 438 } |
| 425 | 439 |
| 426 | 440 |
| 427 static void* ThreadEntry(void* arg) { | 441 static void* ThreadEntry(void* arg) { |
| 428 Thread* thread = reinterpret_cast<Thread*>(arg); | 442 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 429 // This is also initialized by the first argument to pthread_create() but we | 443 // This is also initialized by the first argument to pthread_create() but we |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 } | 693 } |
| 680 | 694 |
| 681 // This sampler is no longer the active sampler. | 695 // This sampler is no longer the active sampler. |
| 682 active_sampler_ = NULL; | 696 active_sampler_ = NULL; |
| 683 active_ = false; | 697 active_ = false; |
| 684 } | 698 } |
| 685 | 699 |
| 686 #endif // ENABLE_LOGGING_AND_PROFILING | 700 #endif // ENABLE_LOGGING_AND_PROFILING |
| 687 | 701 |
| 688 } } // namespace v8::internal | 702 } } // namespace v8::internal |
| OLD | NEW |