Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 3295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3306 | 3306 |
| 3307 private: | 3307 private: |
| 3308 friend class Value; | 3308 friend class Value; |
| 3309 friend class Script; | 3309 friend class Script; |
| 3310 friend class Object; | 3310 friend class Object; |
| 3311 friend class Function; | 3311 friend class Function; |
| 3312 }; | 3312 }; |
| 3313 | 3313 |
| 3314 | 3314 |
| 3315 /** | 3315 /** |
| 3316 * Multiple threads in V8 are allowed, but only one thread at a time | 3316 * Multiple threads in V8 are allowed, but only one thread at a time |
|
Vitaly Repeshko
2011/04/15 00:29:39
This comment needs to be updated to make it clear
| |
| 3317 * is allowed to use any given V8 isolate. See Isolate class | 3317 * is allowed to use any given V8 isolate. See Isolate class |
| 3318 * comments. The definition of 'using V8 isolate' includes | 3318 * comments. The definition of 'using V8 isolate' includes |
| 3319 * accessing handles or holding onto object pointers obtained | 3319 * accessing handles or holding onto object pointers obtained |
| 3320 * from V8 handles while in the particular V8 isolate. It is up | 3320 * from V8 handles while in the particular V8 isolate. It is up |
| 3321 * to the user of V8 to ensure (perhaps with locking) that this | 3321 * to the user of V8 to ensure (perhaps with locking) that this |
| 3322 * constraint is not violated. | 3322 * constraint is not violated. |
| 3323 * | 3323 * |
| 3324 * More then one thread and multiple V8 isolates can be used | 3324 * More then one thread and multiple V8 isolates can be used |
| 3325 * without any locking if each isolate is created and accessed | 3325 * without any locking if each isolate is created and accessed |
| 3326 * by a single thread only. For example, one thread can use | 3326 * by a single thread only. For example, one thread can use |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3387 * // V8 locked again (2 levels). | 3387 * // V8 locked again (2 levels). |
| 3388 * } | 3388 * } |
| 3389 * // V8 still locked (1 level). | 3389 * // V8 still locked (1 level). |
| 3390 * } | 3390 * } |
| 3391 * // V8 Now no longer locked. | 3391 * // V8 Now no longer locked. |
| 3392 * \endcode | 3392 * \endcode |
| 3393 */ | 3393 */ |
| 3394 class V8EXPORT Unlocker { | 3394 class V8EXPORT Unlocker { |
| 3395 public: | 3395 public: |
| 3396 Unlocker(); | 3396 Unlocker(); |
| 3397 explicit Unlocker(Isolate* isolate); | |
| 3397 ~Unlocker(); | 3398 ~Unlocker(); |
| 3399 private: | |
| 3400 void Init(); | |
| 3401 internal::Isolate* isolate_; | |
| 3398 }; | 3402 }; |
| 3399 | 3403 |
| 3400 | 3404 |
| 3401 class V8EXPORT Locker { | 3405 class V8EXPORT Locker { |
| 3402 public: | 3406 public: |
| 3403 Locker(); | 3407 Locker(); |
| 3408 explicit Locker(Isolate* isolate); | |
|
Dmitry Titov
2011/04/13 00:45:10
Consider: If it was:
explicit Locker(Isolate* isol
Dmitry Lomov
2011/04/13 00:54:12
Yes, this sounds reasonable to me
On 2011/04/13 00
Dmitry Lomov
2011/04/19 01:50:47
Done.
| |
| 3404 ~Locker(); | 3409 ~Locker(); |
| 3405 | 3410 |
| 3406 /** | 3411 /** |
| 3407 * Start preemption. | 3412 * Start preemption. |
| 3408 * | 3413 * |
| 3409 * When preemption is started, a timer is fired every n milli seconds | 3414 * When preemption is started, a timer is fired every n milli seconds |
| 3410 * that will switch between multiple threads that are in contention | 3415 * that will switch between multiple threads that are in contention |
| 3411 * for the V8 lock. | 3416 * for the V8 lock. |
| 3412 */ | 3417 */ |
| 3413 static void StartPreemption(int every_n_ms); | 3418 static void StartPreemption(int every_n_ms); |
| 3414 | 3419 |
| 3415 /** | 3420 /** |
| 3416 * Stop preemption. | 3421 * Stop preemption. |
| 3417 */ | 3422 */ |
| 3418 static void StopPreemption(); | 3423 static void StopPreemption(); |
| 3419 | 3424 |
| 3420 /** | 3425 /** |
| 3421 * Returns whether or not the locker is locked by the current thread. | 3426 * Returns whether or not the locker for current isolate is locked by |
| 3427 * the current thread. | |
| 3422 */ | 3428 */ |
| 3423 static bool IsLocked(); | 3429 static bool IsLocked(); |
| 3424 | 3430 |
| 3425 /** | 3431 /** |
| 3432 * Returns whether or not the locker for a given isolate is locked by the curr ent thread. | |
|
Vitaly Repeshko
2011/04/15 00:29:39
nit: Long line.
Dmitry Lomov
2011/04/19 01:50:47
Done.
| |
| 3433 */ | |
| 3434 static bool IsLocked(Isolate * isolate); | |
|
Vitaly Repeshko
2011/04/15 00:29:39
nit: Drop space before '*'.
Dmitry Lomov
2011/04/19 01:50:47
Done.
| |
| 3435 | |
| 3436 /** | |
| 3426 * Returns whether v8::Locker is being used by this V8 instance. | 3437 * Returns whether v8::Locker is being used by this V8 instance. |
| 3427 */ | 3438 */ |
| 3428 static bool IsActive() { return active_; } | 3439 static bool IsActive() { return active_; } |
| 3429 | 3440 |
| 3430 private: | 3441 private: |
| 3442 void Init(); | |
| 3443 | |
| 3431 bool has_lock_; | 3444 bool has_lock_; |
| 3432 bool top_level_; | 3445 bool top_level_; |
| 3446 internal::Isolate* isolate_; | |
| 3433 | 3447 |
| 3434 static bool active_; | 3448 static bool active_; |
| 3435 | 3449 |
| 3436 // Disallow copying and assigning. | 3450 // Disallow copying and assigning. |
| 3437 Locker(const Locker&); | 3451 Locker(const Locker&); |
| 3438 void operator=(const Locker&); | 3452 void operator=(const Locker&); |
| 3439 }; | 3453 }; |
| 3440 | 3454 |
| 3441 | 3455 |
| 3442 /** | 3456 /** |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3991 | 4005 |
| 3992 | 4006 |
| 3993 } // namespace v8 | 4007 } // namespace v8 |
| 3994 | 4008 |
| 3995 | 4009 |
| 3996 #undef V8EXPORT | 4010 #undef V8EXPORT |
| 3997 #undef TYPE_CHECK | 4011 #undef TYPE_CHECK |
| 3998 | 4012 |
| 3999 | 4013 |
| 4000 #endif // V8_H_ | 4014 #endif // V8_H_ |
| OLD | NEW |