| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Platform specific code for POSIX goes here. This is not a platform on its | 28 // Platform specific code for POSIX goes here. This is not a platform on its |
| 29 // own but contains the parts which are the same across POSIX platforms Linux, | 29 // own but contains the parts which are the same across POSIX platforms Linux, |
| 30 // Mac OS, FreeBSD and OpenBSD. | 30 // Mac OS, FreeBSD and OpenBSD. |
| 31 | 31 |
| 32 #include "platform-posix.h" | 32 #include "platform-posix.h" |
| 33 | 33 |
| 34 #include <pthread.h> |
| 35 #include <sched.h> // for sched_yield |
| 34 #include <unistd.h> | 36 #include <unistd.h> |
| 35 #include <errno.h> | 37 #include <errno.h> |
| 36 #include <time.h> | 38 #include <time.h> |
| 37 | 39 |
| 38 #include <sys/mman.h> | 40 #include <sys/mman.h> |
| 39 #include <sys/socket.h> | 41 #include <sys/socket.h> |
| 40 #include <sys/resource.h> | 42 #include <sys/resource.h> |
| 41 #include <sys/time.h> | 43 #include <sys/time.h> |
| 42 #include <sys/types.h> | 44 #include <sys/types.h> |
| 43 #include <sys/stat.h> | 45 #include <sys/stat.h> |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 OS::MemMoveFunction CreateMemMoveFunction(); | 336 OS::MemMoveFunction CreateMemMoveFunction(); |
| 335 | 337 |
| 336 // Copy memory area. No restrictions. | 338 // Copy memory area. No restrictions. |
| 337 void OS::MemMove(void* dest, const void* src, size_t size) { | 339 void OS::MemMove(void* dest, const void* src, size_t size) { |
| 338 if (size == 0) return; | 340 if (size == 0) return; |
| 339 // Note: here we rely on dependent reads being ordered. This is true | 341 // Note: here we rely on dependent reads being ordered. This is true |
| 340 // on all architectures we currently support. | 342 // on all architectures we currently support. |
| 341 (*memmove_function)(dest, src, size); | 343 (*memmove_function)(dest, src, size); |
| 342 } | 344 } |
| 343 | 345 |
| 344 #endif // V8_TARGET_ARCH_IA32 | 346 #elif defined(V8_HOST_ARCH_ARM) |
| 347 void OS::MemCopyUint16Uint8Wrapper(uint16_t* dest, |
| 348 const uint8_t* src, |
| 349 size_t chars) { |
| 350 uint16_t *limit = dest + chars; |
| 351 while (dest < limit) { |
| 352 *dest++ = static_cast<uint16_t>(*src++); |
| 353 } |
| 354 } |
| 355 |
| 356 |
| 357 OS::MemCopyUint8Function OS::memcopy_uint8_function = &OS::MemCopyUint8Wrapper; |
| 358 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function = |
| 359 &OS::MemCopyUint16Uint8Wrapper; |
| 360 // Defined in codegen-arm.cc. |
| 361 OS::MemCopyUint8Function CreateMemCopyUint8Function( |
| 362 OS::MemCopyUint8Function stub); |
| 363 OS::MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function( |
| 364 OS::MemCopyUint16Uint8Function stub); |
| 365 #endif |
| 345 | 366 |
| 346 | 367 |
| 347 void POSIXPostSetUp() { | 368 void POSIXPostSetUp() { |
| 348 #if V8_TARGET_ARCH_IA32 | 369 #if V8_TARGET_ARCH_IA32 |
| 349 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); | 370 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); |
| 350 if (generated_memmove != NULL) { | 371 if (generated_memmove != NULL) { |
| 351 memmove_function = generated_memmove; | 372 memmove_function = generated_memmove; |
| 352 } | 373 } |
| 374 #elif defined(V8_HOST_ARCH_ARM) |
| 375 OS::memcopy_uint8_function = |
| 376 CreateMemCopyUint8Function(&OS::MemCopyUint8Wrapper); |
| 377 OS::memcopy_uint16_uint8_function = |
| 378 CreateMemCopyUint16Uint8Function(&OS::MemCopyUint16Uint8Wrapper); |
| 353 #endif | 379 #endif |
| 354 init_fast_sin_function(); | 380 init_fast_sin_function(); |
| 355 init_fast_cos_function(); | 381 init_fast_cos_function(); |
| 356 init_fast_tan_function(); | 382 init_fast_tan_function(); |
| 357 init_fast_log_function(); | 383 init_fast_log_function(); |
| 358 // fast_exp is initialized lazily. | 384 // fast_exp is initialized lazily. |
| 359 init_fast_sqrt_function(); | 385 init_fast_sqrt_function(); |
| 360 } | 386 } |
| 361 | 387 |
| 362 | 388 |
| 363 // ---------------------------------------------------------------------------- | 389 // ---------------------------------------------------------------------------- |
| 364 // POSIX string support. | 390 // POSIX string support. |
| 365 // | 391 // |
| 366 | 392 |
| 367 char* OS::StrChr(char* str, int c) { | 393 char* OS::StrChr(char* str, int c) { |
| 368 return strchr(str, c); | 394 return strchr(str, c); |
| 369 } | 395 } |
| 370 | 396 |
| 371 | 397 |
| 372 void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) { | 398 void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) { |
| 373 strncpy(dest.start(), src, n); | 399 strncpy(dest.start(), src, n); |
| 374 } | 400 } |
| 375 | 401 |
| 376 | 402 |
| 377 // ---------------------------------------------------------------------------- | 403 // ---------------------------------------------------------------------------- |
| 404 // POSIX thread support. |
| 405 // |
| 406 |
| 407 void Thread::YieldCPU() { |
| 408 sched_yield(); |
| 409 } |
| 410 |
| 411 |
| 412 class POSIXMutex : public Mutex { |
| 413 public: |
| 414 POSIXMutex() { |
| 415 pthread_mutexattr_t attr; |
| 416 memset(&attr, 0, sizeof(attr)); |
| 417 int result = pthread_mutexattr_init(&attr); |
| 418 ASSERT(result == 0); |
| 419 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); |
| 420 ASSERT(result == 0); |
| 421 result = pthread_mutex_init(&mutex_, &attr); |
| 422 ASSERT(result == 0); |
| 423 result = pthread_mutexattr_destroy(&attr); |
| 424 ASSERT(result == 0); |
| 425 USE(result); |
| 426 } |
| 427 |
| 428 virtual ~POSIXMutex() { pthread_mutex_destroy(&mutex_); } |
| 429 |
| 430 virtual int Lock() { return pthread_mutex_lock(&mutex_); } |
| 431 |
| 432 virtual int Unlock() { return pthread_mutex_unlock(&mutex_); } |
| 433 |
| 434 virtual bool TryLock() { |
| 435 int result = pthread_mutex_trylock(&mutex_); |
| 436 // Return false if the lock is busy and locking failed. |
| 437 if (result == EBUSY) { |
| 438 return false; |
| 439 } |
| 440 ASSERT(result == 0); // Verify no other errors. |
| 441 return true; |
| 442 } |
| 443 |
| 444 private: |
| 445 pthread_mutex_t mutex_; // Pthread mutex for POSIX platforms. |
| 446 }; |
| 447 |
| 448 |
| 449 Mutex* OS::CreateMutex() { |
| 450 return new POSIXMutex(); |
| 451 } |
| 452 |
| 453 |
| 454 // ---------------------------------------------------------------------------- |
| 378 // POSIX socket support. | 455 // POSIX socket support. |
| 379 // | 456 // |
| 380 | 457 |
| 381 class POSIXSocket : public Socket { | 458 class POSIXSocket : public Socket { |
| 382 public: | 459 public: |
| 383 explicit POSIXSocket() { | 460 explicit POSIXSocket() { |
| 384 // Create the socket. | 461 // Create the socket. |
| 385 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 462 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 386 if (IsValid()) { | 463 if (IsValid()) { |
| 387 // Allow rapid reuse. | 464 // Allow rapid reuse. |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 return ntohl(value); | 643 return ntohl(value); |
| 567 } | 644 } |
| 568 | 645 |
| 569 | 646 |
| 570 Socket* OS::CreateSocket() { | 647 Socket* OS::CreateSocket() { |
| 571 return new POSIXSocket(); | 648 return new POSIXSocket(); |
| 572 } | 649 } |
| 573 | 650 |
| 574 | 651 |
| 575 } } // namespace v8::internal | 652 } } // namespace v8::internal |
| OLD | NEW |