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