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 20 matching lines...) Expand all Loading... |
31 * | 31 * |
32 * This set of documents provides reference material generated from the | 32 * This set of documents provides reference material generated from the |
33 * V8 header file, include/v8.h. | 33 * V8 header file, include/v8.h. |
34 * | 34 * |
35 * For other documentation see http://code.google.com/apis/v8/ | 35 * For other documentation see http://code.google.com/apis/v8/ |
36 */ | 36 */ |
37 | 37 |
38 #ifndef V8_H_ | 38 #ifndef V8_H_ |
39 #define V8_H_ | 39 #define V8_H_ |
40 | 40 |
| 41 // TODO(svenpanne) Remove me when the Chrome bindings are adapted. |
| 42 #define V8_DISABLE_DEPRECATIONS 1 |
| 43 |
41 #include "v8stdint.h" | 44 #include "v8stdint.h" |
42 | 45 |
43 #ifdef _WIN32 | 46 #ifdef _WIN32 |
44 | 47 |
45 // Setup for Windows DLL export/import. When building the V8 DLL the | 48 // Setup for Windows DLL export/import. When building the V8 DLL the |
46 // BUILDING_V8_SHARED needs to be defined. When building a program which uses | 49 // BUILDING_V8_SHARED needs to be defined. When building a program which uses |
47 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 | 50 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 |
48 // static library or building a program which uses the V8 static library neither | 51 // static library or building a program which uses the V8 static library neither |
49 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. | 52 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. |
50 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) | 53 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) |
(...skipping 3821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3872 friend class Script; | 3875 friend class Script; |
3873 friend class Object; | 3876 friend class Object; |
3874 friend class Function; | 3877 friend class Function; |
3875 | 3878 |
3876 Local<Value> SlowGetEmbedderData(int index); | 3879 Local<Value> SlowGetEmbedderData(int index); |
3877 void* SlowGetAlignedPointerFromEmbedderData(int index); | 3880 void* SlowGetAlignedPointerFromEmbedderData(int index); |
3878 }; | 3881 }; |
3879 | 3882 |
3880 | 3883 |
3881 /** | 3884 /** |
3882 * Multiple threads in V8 are allowed, but only one thread at a time | 3885 * Multiple threads in V8 are allowed, but only one thread at a time is allowed |
3883 * is allowed to use any given V8 isolate. See Isolate class | 3886 * to use any given V8 isolate, see the comments in the Isolate class. The |
3884 * comments. The definition of 'using V8 isolate' includes | 3887 * definition of 'using a V8 isolate' includes accessing handles or holding onto |
3885 * accessing handles or holding onto object pointers obtained | 3888 * object pointers obtained from V8 handles while in the particular V8 isolate. |
3886 * from V8 handles while in the particular V8 isolate. It is up | 3889 * It is up to the user of V8 to ensure, perhaps with locking, that this |
3887 * to the user of V8 to ensure (perhaps with locking) that this | 3890 * constraint is not violated. In addition to any other synchronization |
3888 * constraint is not violated. In addition to any other synchronization | 3891 * mechanism that may be used, the v8::Locker and v8::Unlocker classes must be |
3889 * mechanism that may be used, the v8::Locker and v8::Unlocker classes | 3892 * used to signal thead switches to V8. |
3890 * must be used to signal thead switches to V8. | |
3891 * | 3893 * |
3892 * v8::Locker is a scoped lock object. While it's | 3894 * v8::Locker is a scoped lock object. While it's active, i.e. between its |
3893 * active (i.e. between its construction and destruction) the current thread is | 3895 * construction and destruction, the current thread is allowed to use the locked |
3894 * allowed to use the locked isolate. V8 guarantees that an isolate can be | 3896 * isolate. V8 guarantees that an isolate can be locked by at most one thread at |
3895 * locked by at most one thread at any time. In other words, the scope of a | 3897 * any time. In other words, the scope of a v8::Locker is a critical section. |
3896 * v8::Locker is a critical section. | |
3897 * | 3898 * |
3898 * Sample usage: | 3899 * Sample usage: |
3899 * \code | 3900 * \code |
3900 * ... | 3901 * ... |
3901 * { | 3902 * { |
3902 * v8::Locker locker(isolate); | 3903 * v8::Locker locker(isolate); |
3903 * v8::Isolate::Scope isolate_scope(isolate); | 3904 * v8::Isolate::Scope isolate_scope(isolate); |
3904 * ... | 3905 * ... |
3905 * // Code using V8 and isolate goes here. | 3906 * // Code using V8 and isolate goes here. |
3906 * ... | 3907 * ... |
3907 * } // Destructor called here | 3908 * } // Destructor called here |
3908 * \endcode | 3909 * \endcode |
3909 * | 3910 * |
3910 * If you wish to stop using V8 in a thread A you can do this either | 3911 * If you wish to stop using V8 in a thread A you can do this either by |
3911 * by destroying the v8::Locker object as above or by constructing a | 3912 * destroying the v8::Locker object as above or by constructing a v8::Unlocker |
3912 * v8::Unlocker object: | 3913 * object: |
3913 * | 3914 * |
3914 * \code | 3915 * \code |
3915 * { | 3916 * { |
3916 * isolate->Exit(); | 3917 * isolate->Exit(); |
3917 * v8::Unlocker unlocker(isolate); | 3918 * v8::Unlocker unlocker(isolate); |
3918 * ... | 3919 * ... |
3919 * // Code not using V8 goes here while V8 can run in another thread. | 3920 * // Code not using V8 goes here while V8 can run in another thread. |
3920 * ... | 3921 * ... |
3921 * } // Destructor called here. | 3922 * } // Destructor called here. |
3922 * isolate->Enter(); | 3923 * isolate->Enter(); |
3923 * \endcode | 3924 * \endcode |
3924 * | 3925 * |
3925 * The Unlocker object is intended for use in a long-running callback | 3926 * The Unlocker object is intended for use in a long-running callback from V8, |
3926 * from V8, where you want to release the V8 lock for other threads to | 3927 * where you want to release the V8 lock for other threads to use. |
3927 * use. | |
3928 * | 3928 * |
3929 * The v8::Locker is a recursive lock. That is, you can lock more than | 3929 * The v8::Locker is a recursive lock, i.e. you can lock more than once in a |
3930 * once in a given thread. This can be useful if you have code that can | 3930 * given thread. This can be useful if you have code that can be called either |
3931 * be called either from code that holds the lock or from code that does | 3931 * from code that holds the lock or from code that does not. The Unlocker is |
3932 * not. The Unlocker is not recursive so you can not have several | 3932 * not recursive so you can not have several Unlockers on the stack at once, and |
3933 * Unlockers on the stack at once, and you can not use an Unlocker in a | 3933 * you can not use an Unlocker in a thread that is not inside a Locker's scope. |
3934 * thread that is not inside a Locker's scope. | |
3935 * | 3934 * |
3936 * An unlocker will unlock several lockers if it has to and reinstate | 3935 * An unlocker will unlock several lockers if it has to and reinstate the |
3937 * the correct depth of locking on its destruction. eg.: | 3936 * correct depth of locking on its destruction, e.g.: |
3938 * | 3937 * |
3939 * \code | 3938 * \code |
3940 * // V8 not locked. | 3939 * // V8 not locked. |
3941 * { | 3940 * { |
3942 * v8::Locker locker(isolate); | 3941 * v8::Locker locker(isolate); |
3943 * Isolate::Scope isolate_scope(isolate); | 3942 * Isolate::Scope isolate_scope(isolate); |
3944 * // V8 locked. | 3943 * // V8 locked. |
3945 * { | 3944 * { |
3946 * v8::Locker another_locker(isolate); | 3945 * v8::Locker another_locker(isolate); |
3947 * // V8 still locked (2 levels). | 3946 * // V8 still locked (2 levels). |
3948 * { | 3947 * { |
3949 * isolate->Exit(); | 3948 * isolate->Exit(); |
3950 * v8::Unlocker unlocker(isolate); | 3949 * v8::Unlocker unlocker(isolate); |
3951 * // V8 not locked. | 3950 * // V8 not locked. |
3952 * } | 3951 * } |
3953 * isolate->Enter(); | 3952 * isolate->Enter(); |
3954 * // V8 locked again (2 levels). | 3953 * // V8 locked again (2 levels). |
3955 * } | 3954 * } |
3956 * // V8 still locked (1 level). | 3955 * // V8 still locked (1 level). |
3957 * } | 3956 * } |
3958 * // V8 Now no longer locked. | 3957 * // V8 Now no longer locked. |
3959 * \endcode | 3958 * \endcode |
3960 * | |
3961 * | |
3962 */ | 3959 */ |
3963 class V8EXPORT Unlocker { | 3960 class V8EXPORT Unlocker { |
3964 public: | 3961 public: |
3965 /** | 3962 /** |
3966 * Initialize Unlocker for a given Isolate. NULL means default isolate. | 3963 * Initialize Unlocker for a given Isolate. |
3967 */ | 3964 */ |
3968 explicit Unlocker(Isolate* isolate = NULL); | 3965 V8_INLINE(explicit Unlocker(Isolate* isolate)) { Initialize(isolate); } |
| 3966 |
| 3967 /** |
| 3968 * Deprecated. Use Isolate version instead. |
| 3969 */ |
| 3970 V8_DEPRECATED(Unlocker()); |
| 3971 |
3969 ~Unlocker(); | 3972 ~Unlocker(); |
3970 private: | 3973 private: |
| 3974 void Initialize(Isolate* isolate); |
| 3975 |
3971 internal::Isolate* isolate_; | 3976 internal::Isolate* isolate_; |
3972 }; | 3977 }; |
3973 | 3978 |
3974 | 3979 |
3975 class V8EXPORT Locker { | 3980 class V8EXPORT Locker { |
3976 public: | 3981 public: |
3977 /** | 3982 /** |
3978 * Initialize Locker for a given Isolate. NULL means default isolate. | 3983 * Initialize Locker for a given Isolate. |
3979 */ | 3984 */ |
3980 explicit Locker(Isolate* isolate = NULL); | 3985 V8_INLINE(explicit Locker(Isolate* isolate)) { Initialize(isolate); } |
| 3986 |
| 3987 /** |
| 3988 * Deprecated. Use Isolate version instead. |
| 3989 */ |
| 3990 V8_DEPRECATED(Locker()); |
| 3991 |
3981 ~Locker(); | 3992 ~Locker(); |
3982 | 3993 |
3983 /** | 3994 /** |
3984 * Start preemption. | 3995 * Start preemption. |
3985 * | 3996 * |
3986 * When preemption is started, a timer is fired every n milliseconds | 3997 * When preemption is started, a timer is fired every n milliseconds |
3987 * that will switch between multiple threads that are in contention | 3998 * that will switch between multiple threads that are in contention |
3988 * for the V8 lock. | 3999 * for the V8 lock. |
3989 */ | 4000 */ |
3990 static void StartPreemption(int every_n_ms); | 4001 static void StartPreemption(int every_n_ms); |
3991 | 4002 |
3992 /** | 4003 /** |
3993 * Stop preemption. | 4004 * Stop preemption. |
3994 */ | 4005 */ |
3995 static void StopPreemption(); | 4006 static void StopPreemption(); |
3996 | 4007 |
3997 /** | 4008 /** |
3998 * Returns whether or not the locker for a given isolate, or default isolate | 4009 * Returns whether or not the locker for a given isolate, is locked by the |
3999 * if NULL is given, is locked by the current thread. | 4010 * current thread. |
4000 */ | 4011 */ |
4001 static bool IsLocked(Isolate* isolate = NULL); | 4012 static bool IsLocked(Isolate* isolate); |
4002 | 4013 |
4003 /** | 4014 /** |
4004 * Returns whether v8::Locker is being used by this V8 instance. | 4015 * Returns whether v8::Locker is being used by this V8 instance. |
4005 */ | 4016 */ |
4006 static bool IsActive(); | 4017 static bool IsActive(); |
4007 | 4018 |
4008 private: | 4019 private: |
| 4020 void Initialize(Isolate* isolate); |
| 4021 |
4009 bool has_lock_; | 4022 bool has_lock_; |
4010 bool top_level_; | 4023 bool top_level_; |
4011 internal::Isolate* isolate_; | 4024 internal::Isolate* isolate_; |
4012 | 4025 |
4013 static bool active_; | 4026 static bool active_; |
4014 | 4027 |
4015 // Disallow copying and assigning. | 4028 // Disallow copying and assigning. |
4016 Locker(const Locker&); | 4029 Locker(const Locker&); |
4017 void operator=(const Locker&); | 4030 void operator=(const Locker&); |
4018 }; | 4031 }; |
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4836 | 4849 |
4837 | 4850 |
4838 } // namespace v8 | 4851 } // namespace v8 |
4839 | 4852 |
4840 | 4853 |
4841 #undef V8EXPORT | 4854 #undef V8EXPORT |
4842 #undef TYPE_CHECK | 4855 #undef TYPE_CHECK |
4843 | 4856 |
4844 | 4857 |
4845 #endif // V8_H_ | 4858 #endif // V8_H_ |
OLD | NEW |