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

Side by Side Diff: src/platform.h

Issue 9455088: Remove static initializers in v8. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address Florian's comments. 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
« no previous file with comments | « src/log.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"
82 #include "platform-tls.h" 83 #include "platform-tls.h"
83 #include "utils.h" 84 #include "utils.h"
84 #include "v8globals.h" 85 #include "v8globals.h"
85 86
86 namespace v8 { 87 namespace v8 {
87 namespace internal { 88 namespace internal {
88 89
89 // Use AtomicWord for a machine-sized pointer. It is assumed that 90 // Use AtomicWord for a machine-sized pointer. It is assumed that
90 // reads and writes of naturally aligned values of this type are atomic. 91 // reads and writes of naturally aligned values of this type are atomic.
91 typedef intptr_t AtomicWord; 92 typedef intptr_t AtomicWord;
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 516
516 // Unlocks the given mutex. The mutex is assumed to be locked and owned by 517 // Unlocks the given mutex. The mutex is assumed to be locked and owned by
517 // the calling thread on entrance. 518 // the calling thread on entrance.
518 virtual int Unlock() = 0; 519 virtual int Unlock() = 0;
519 520
520 // Tries to lock the given mutex. Returns whether the mutex was 521 // Tries to lock the given mutex. Returns whether the mutex was
521 // successfully locked. 522 // successfully locked.
522 virtual bool TryLock() = 0; 523 virtual bool TryLock() = 0;
523 }; 524 };
524 525
526 struct CreateMutexTrait {
527 static Mutex* Create() {
528 return OS::CreateMutex();
529 }
530 };
531
532 // POD Mutex initialized lazily (i.e. the first time Pointer() is called).
533 // Usage:
534 // static LazyMutex my_mutex = LAZY_MUTEX_INITIALIZER;
535 //
536 // void my_function() {
537 // ScopedLock my_lock(my_mutex.Pointer());
538 // // Do something.
539 // }
540 //
541 typedef LazyDynamicInstance<Mutex, CreateMutexTrait>::type LazyMutex;
542
543 #define LAZY_MUTEX_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER
525 544
526 // ---------------------------------------------------------------------------- 545 // ----------------------------------------------------------------------------
527 // ScopedLock 546 // ScopedLock
528 // 547 //
529 // Stack-allocated ScopedLocks provide block-scoped locking and 548 // Stack-allocated ScopedLocks provide block-scoped locking and
530 // unlocking of a mutex. 549 // unlocking of a mutex.
531 class ScopedLock { 550 class ScopedLock {
532 public: 551 public:
533 explicit ScopedLock(Mutex* mutex): mutex_(mutex) { 552 explicit ScopedLock(Mutex* mutex): mutex_(mutex) {
534 ASSERT(mutex_ != NULL); 553 ASSERT(mutex_ != NULL);
(...skipping 29 matching lines...) Expand all
564 // Suspends the calling thread until the counter is non zero or the timeout 583 // Suspends the calling thread until the counter is non zero or the timeout
565 // time has passed. If timeout happens the return value is false and the 584 // time has passed. If timeout happens the return value is false and the
566 // counter is unchanged. Otherwise the semaphore counter is decremented and 585 // counter is unchanged. Otherwise the semaphore counter is decremented and
567 // true is returned. The timeout value is specified in microseconds. 586 // true is returned. The timeout value is specified in microseconds.
568 virtual bool Wait(int timeout) = 0; 587 virtual bool Wait(int timeout) = 0;
569 588
570 // Increments the semaphore counter. 589 // Increments the semaphore counter.
571 virtual void Signal() = 0; 590 virtual void Signal() = 0;
572 }; 591 };
573 592
593 template <int InitialValue>
594 struct CreateSemaphoreTrait {
595 static Semaphore* Create() {
596 return OS::CreateSemaphore(InitialValue);
597 }
598 };
599
600 // POD Semaphore initialized lazily (i.e. the first time Pointer() is called).
601 // Usage:
602 // // The following semaphore starts at 0.
603 // static LazySemaphore<0>::type my_semaphore = LAZY_SEMAPHORE_INITIALIZER;
604 //
605 // void my_function() {
606 // // Do something with my_semaphore.Pointer().
607 // }
608 //
609 template <int InitialValue>
610 struct LazySemaphore {
611 typedef typename LazyDynamicInstance<
612 Semaphore, CreateSemaphoreTrait<InitialValue> >::type type;
613 };
614
615 #define LAZY_SEMAPHORE_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER
616
574 617
575 // ---------------------------------------------------------------------------- 618 // ----------------------------------------------------------------------------
576 // Socket 619 // Socket
577 // 620 //
578 621
579 class Socket { 622 class Socket {
580 public: 623 public:
581 virtual ~Socket() {} 624 virtual ~Socket() {}
582 625
583 // Server initialization. 626 // Server initialization.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 Atomic32 active_; 740 Atomic32 active_;
698 PlatformData* data_; // Platform specific data. 741 PlatformData* data_; // Platform specific data.
699 int samples_taken_; // Counts stack samples taken. 742 int samples_taken_; // Counts stack samples taken.
700 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); 743 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
701 }; 744 };
702 745
703 746
704 } } // namespace v8::internal 747 } } // namespace v8::internal
705 748
706 #endif // V8_PLATFORM_H_ 749 #endif // V8_PLATFORM_H_
OLDNEW
« no previous file with comments | « src/log.cc ('k') | src/platform-cygwin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698