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

Side by Side Diff: src/platform.h

Issue 9836108: Rollback of r11015, r11014, r11011, r11010 in trunk branch. (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Finish file upload Created 8 years, 8 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
« no previous file with comments | « src/once.cc ('k') | src/platform-cygwin.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 int strncasecmp(const char* s1, const char* s2, int n); 72 int strncasecmp(const char* s1, const char* s2, int n);
73 73
74 #endif // _MSC_VER 74 #endif // _MSC_VER
75 75
76 // Random is missing on both Visual Studio and MinGW. 76 // Random is missing on both Visual Studio and MinGW.
77 int random(); 77 int random();
78 78
79 #endif // WIN32 79 #endif // WIN32
80 80
81 #include "atomicops.h" 81 #include "atomicops.h"
82 #include "lazy-instance.h"
83 #include "platform-tls.h" 82 #include "platform-tls.h"
84 #include "utils.h" 83 #include "utils.h"
85 #include "v8globals.h" 84 #include "v8globals.h"
86 85
87 namespace v8 { 86 namespace v8 {
88 namespace internal { 87 namespace internal {
89 88
90 // Use AtomicWord for a machine-sized pointer. It is assumed that 89 // Use AtomicWord for a machine-sized pointer. It is assumed that
91 // reads and writes of naturally aligned values of this type are atomic. 90 // reads and writes of naturally aligned values of this type are atomic.
92 typedef intptr_t AtomicWord; 91 typedef intptr_t AtomicWord;
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 522
524 // Unlocks the given mutex. The mutex is assumed to be locked and owned by 523 // Unlocks the given mutex. The mutex is assumed to be locked and owned by
525 // the calling thread on entrance. 524 // the calling thread on entrance.
526 virtual int Unlock() = 0; 525 virtual int Unlock() = 0;
527 526
528 // Tries to lock the given mutex. Returns whether the mutex was 527 // Tries to lock the given mutex. Returns whether the mutex was
529 // successfully locked. 528 // successfully locked.
530 virtual bool TryLock() = 0; 529 virtual bool TryLock() = 0;
531 }; 530 };
532 531
533 struct CreateMutexTrait {
534 static Mutex* Create() {
535 return OS::CreateMutex();
536 }
537 };
538
539 // POD Mutex initialized lazily (i.e. the first time Pointer() is called).
540 // Usage:
541 // static LazyMutex my_mutex = LAZY_MUTEX_INITIALIZER;
542 //
543 // void my_function() {
544 // ScopedLock my_lock(my_mutex.Pointer());
545 // // Do something.
546 // }
547 //
548 typedef LazyDynamicInstance<Mutex, CreateMutexTrait>::type LazyMutex;
549
550 #define LAZY_MUTEX_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER
551 532
552 // ---------------------------------------------------------------------------- 533 // ----------------------------------------------------------------------------
553 // ScopedLock 534 // ScopedLock
554 // 535 //
555 // Stack-allocated ScopedLocks provide block-scoped locking and 536 // Stack-allocated ScopedLocks provide block-scoped locking and
556 // unlocking of a mutex. 537 // unlocking of a mutex.
557 class ScopedLock { 538 class ScopedLock {
558 public: 539 public:
559 explicit ScopedLock(Mutex* mutex): mutex_(mutex) { 540 explicit ScopedLock(Mutex* mutex): mutex_(mutex) {
560 ASSERT(mutex_ != NULL); 541 ASSERT(mutex_ != NULL);
(...skipping 29 matching lines...) Expand all
590 // Suspends the calling thread until the counter is non zero or the timeout 571 // Suspends the calling thread until the counter is non zero or the timeout
591 // time has passed. If timeout happens the return value is false and the 572 // time has passed. If timeout happens the return value is false and the
592 // counter is unchanged. Otherwise the semaphore counter is decremented and 573 // counter is unchanged. Otherwise the semaphore counter is decremented and
593 // true is returned. The timeout value is specified in microseconds. 574 // true is returned. The timeout value is specified in microseconds.
594 virtual bool Wait(int timeout) = 0; 575 virtual bool Wait(int timeout) = 0;
595 576
596 // Increments the semaphore counter. 577 // Increments the semaphore counter.
597 virtual void Signal() = 0; 578 virtual void Signal() = 0;
598 }; 579 };
599 580
600 template <int InitialValue>
601 struct CreateSemaphoreTrait {
602 static Semaphore* Create() {
603 return OS::CreateSemaphore(InitialValue);
604 }
605 };
606
607 // POD Semaphore initialized lazily (i.e. the first time Pointer() is called).
608 // Usage:
609 // // The following semaphore starts at 0.
610 // static LazySemaphore<0>::type my_semaphore = LAZY_SEMAPHORE_INITIALIZER;
611 //
612 // void my_function() {
613 // // Do something with my_semaphore.Pointer().
614 // }
615 //
616 template <int InitialValue>
617 struct LazySemaphore {
618 typedef typename LazyDynamicInstance<
619 Semaphore, CreateSemaphoreTrait<InitialValue> >::type type;
620 };
621
622 #define LAZY_SEMAPHORE_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER
623
624 581
625 // ---------------------------------------------------------------------------- 582 // ----------------------------------------------------------------------------
626 // Socket 583 // Socket
627 // 584 //
628 585
629 class Socket { 586 class Socket {
630 public: 587 public:
631 virtual ~Socket() {} 588 virtual ~Socket() {}
632 589
633 // Server initialization. 590 // Server initialization.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 Atomic32 active_; 704 Atomic32 active_;
748 PlatformData* data_; // Platform specific data. 705 PlatformData* data_; // Platform specific data.
749 int samples_taken_; // Counts stack samples taken. 706 int samples_taken_; // Counts stack samples taken.
750 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); 707 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
751 }; 708 };
752 709
753 710
754 } } // namespace v8::internal 711 } } // namespace v8::internal
755 712
756 #endif // V8_PLATFORM_H_ 713 #endif // V8_PLATFORM_H_
OLDNEW
« no previous file with comments | « src/once.cc ('k') | src/platform-cygwin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698