| OLD | NEW |
| 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 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1599 */ | 1599 */ |
| 1600 V8EXPORT void SetIndexedPropertiesToExternalArrayData( | 1600 V8EXPORT void SetIndexedPropertiesToExternalArrayData( |
| 1601 void* data, | 1601 void* data, |
| 1602 ExternalArrayType array_type, | 1602 ExternalArrayType array_type, |
| 1603 int number_of_elements); | 1603 int number_of_elements); |
| 1604 V8EXPORT bool HasIndexedPropertiesInExternalArrayData(); | 1604 V8EXPORT bool HasIndexedPropertiesInExternalArrayData(); |
| 1605 V8EXPORT void* GetIndexedPropertiesExternalArrayData(); | 1605 V8EXPORT void* GetIndexedPropertiesExternalArrayData(); |
| 1606 V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); | 1606 V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); |
| 1607 V8EXPORT int GetIndexedPropertiesExternalArrayDataLength(); | 1607 V8EXPORT int GetIndexedPropertiesExternalArrayDataLength(); |
| 1608 | 1608 |
| 1609 /** |
| 1610 * Call an Object as a function if a callback is set by the |
| 1611 * ObjectTemplate::SetCallAsFunctionHandler method. |
| 1612 */ |
| 1613 V8EXPORT Local<Value> CallAsFunction(Handle<Object> recv, |
| 1614 int argc, |
| 1615 Handle<Value> argv[]); |
| 1616 |
| 1617 /** |
| 1618 * Call an Object as a consturctor if a callback is set by the |
| 1619 * ObjectTemplate::SetCallAsFunctionHandler method. |
| 1620 * Note: This method behaves like the Function::NewInstance method. |
| 1621 */ |
| 1622 V8EXPORT Local<Value> CallAsConstructor(int argc, |
| 1623 Handle<Value> argv[]); |
| 1624 |
| 1609 V8EXPORT static Local<Object> New(); | 1625 V8EXPORT static Local<Object> New(); |
| 1610 static inline Object* Cast(Value* obj); | 1626 static inline Object* Cast(Value* obj); |
| 1611 private: | 1627 private: |
| 1612 V8EXPORT Object(); | 1628 V8EXPORT Object(); |
| 1613 V8EXPORT static void CheckCast(Value* obj); | 1629 V8EXPORT static void CheckCast(Value* obj); |
| 1614 V8EXPORT Local<Value> CheckedGetInternalField(int index); | 1630 V8EXPORT Local<Value> CheckedGetInternalField(int index); |
| 1615 V8EXPORT void* SlowGetPointerFromInternalField(int index); | 1631 V8EXPORT void* SlowGetPointerFromInternalField(int index); |
| 1616 | 1632 |
| 1617 /** | 1633 /** |
| 1618 * If quick access to the internal field is possible this method | 1634 * If quick access to the internal field is possible this method |
| (...skipping 1759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3378 | 3394 |
| 3379 /** | 3395 /** |
| 3380 * Multiple threads in V8 are allowed, but only one thread at a time | 3396 * Multiple threads in V8 are allowed, but only one thread at a time |
| 3381 * is allowed to use any given V8 isolate. See Isolate class | 3397 * is allowed to use any given V8 isolate. See Isolate class |
| 3382 * comments. The definition of 'using V8 isolate' includes | 3398 * comments. The definition of 'using V8 isolate' includes |
| 3383 * accessing handles or holding onto object pointers obtained | 3399 * accessing handles or holding onto object pointers obtained |
| 3384 * from V8 handles while in the particular V8 isolate. It is up | 3400 * from V8 handles while in the particular V8 isolate. It is up |
| 3385 * to the user of V8 to ensure (perhaps with locking) that this | 3401 * to the user of V8 to ensure (perhaps with locking) that this |
| 3386 * constraint is not violated. | 3402 * constraint is not violated. |
| 3387 * | 3403 * |
| 3388 * More then one thread and multiple V8 isolates can be used | 3404 * v8::Locker is a scoped lock object. While it's |
| 3389 * without any locking if each isolate is created and accessed | 3405 * active (i.e. between its construction and destruction) the current thread is |
| 3390 * by a single thread only. For example, one thread can use | 3406 * allowed to use the locked isolate. V8 guarantees that an isolate can be locke
d |
| 3391 * multiple isolates or multiple threads can each create and run | 3407 * by at most one thread at any time. In other words, the scope of a v8::Locker
is |
| 3392 * their own isolate. | 3408 * a critical section. |
| 3393 * | 3409 * |
| 3394 * If you wish to start using V8 isolate in more then one thread | 3410 * Sample usage: |
| 3395 * you can do this by constructing a v8::Locker object to guard | 3411 * \code |
| 3396 * access to the isolate. After the code using V8 has completed | |
| 3397 * for the current thread you can call the destructor. This can | |
| 3398 * be combined with C++ scope-based construction as follows | |
| 3399 * (assumes the default isolate that is used if not specified as | |
| 3400 * a parameter for the Locker): | |
| 3401 * | |
| 3402 * \code | |
| 3403 * ... | 3412 * ... |
| 3404 * { | 3413 * { |
| 3405 * v8::Locker locker; | 3414 * v8::Locker locker(isolate); |
| 3415 * v8::Isolate::Scope isolate_scope(isolate); |
| 3406 * ... | 3416 * ... |
| 3407 * // Code using V8 goes here. | 3417 * // Code using V8 and isolate goes here. |
| 3408 * ... | 3418 * ... |
| 3409 * } // Destructor called here | 3419 * } // Destructor called here |
| 3410 * \endcode | 3420 * \endcode |
| 3411 * | 3421 * |
| 3412 * If you wish to stop using V8 in a thread A you can do this by either | 3422 * If you wish to stop using V8 in a thread A you can do this by either |
| 3413 * by destroying the v8::Locker object as above or by constructing a | 3423 * by destroying the v8::Locker object as above or by constructing a |
| 3414 * v8::Unlocker object: | 3424 * v8::Unlocker object: |
| 3415 * | 3425 * |
| 3416 * \code | 3426 * \code |
| 3417 * { | 3427 * { |
| 3418 * v8::Unlocker unlocker; | 3428 * isolate->Exit(); |
| 3429 * v8::Unlocker unlocker(isolate); |
| 3419 * ... | 3430 * ... |
| 3420 * // Code not using V8 goes here while V8 can run in another thread. | 3431 * // Code not using V8 goes here while V8 can run in another thread. |
| 3421 * ... | 3432 * ... |
| 3422 * } // Destructor called here. | 3433 * } // Destructor called here. |
| 3434 * isolate->Enter(); |
| 3423 * \endcode | 3435 * \endcode |
| 3424 * | 3436 * |
| 3425 * The Unlocker object is intended for use in a long-running callback | 3437 * The Unlocker object is intended for use in a long-running callback |
| 3426 * from V8, where you want to release the V8 lock for other threads to | 3438 * from V8, where you want to release the V8 lock for other threads to |
| 3427 * use. | 3439 * use. |
| 3428 * | 3440 * |
| 3429 * The v8::Locker is a recursive lock. That is, you can lock more than | 3441 * The v8::Locker is a recursive lock. That is, you can lock more than |
| 3430 * once in a given thread. This can be useful if you have code that can | 3442 * once in a given thread. This can be useful if you have code that can |
| 3431 * be called either from code that holds the lock or from code that does | 3443 * be called either from code that holds the lock or from code that does |
| 3432 * not. The Unlocker is not recursive so you can not have several | 3444 * not. The Unlocker is not recursive so you can not have several |
| 3433 * Unlockers on the stack at once, and you can not use an Unlocker in a | 3445 * Unlockers on the stack at once, and you can not use an Unlocker in a |
| 3434 * thread that is not inside a Locker's scope. | 3446 * thread that is not inside a Locker's scope. |
| 3435 * | 3447 * |
| 3436 * An unlocker will unlock several lockers if it has to and reinstate | 3448 * An unlocker will unlock several lockers if it has to and reinstate |
| 3437 * the correct depth of locking on its destruction. eg.: | 3449 * the correct depth of locking on its destruction. eg.: |
| 3438 * | 3450 * |
| 3439 * \code | 3451 * \code |
| 3440 * // V8 not locked. | 3452 * // V8 not locked. |
| 3441 * { | 3453 * { |
| 3442 * v8::Locker locker; | 3454 * v8::Locker locker(isolate); |
| 3455 * Isolate::Scope isolate_scope(isolate); |
| 3443 * // V8 locked. | 3456 * // V8 locked. |
| 3444 * { | 3457 * { |
| 3445 * v8::Locker another_locker; | 3458 * v8::Locker another_locker(isolate); |
| 3446 * // V8 still locked (2 levels). | 3459 * // V8 still locked (2 levels). |
| 3447 * { | 3460 * { |
| 3448 * v8::Unlocker unlocker; | 3461 * isolate->Exit(); |
| 3462 * v8::Unlocker unlocker(isolate); |
| 3449 * // V8 not locked. | 3463 * // V8 not locked. |
| 3450 * } | 3464 * } |
| 3465 * isolate->Enter(); |
| 3451 * // V8 locked again (2 levels). | 3466 * // V8 locked again (2 levels). |
| 3452 * } | 3467 * } |
| 3453 * // V8 still locked (1 level). | 3468 * // V8 still locked (1 level). |
| 3454 * } | 3469 * } |
| 3455 * // V8 Now no longer locked. | 3470 * // V8 Now no longer locked. |
| 3456 * \endcode | 3471 * \endcode |
| 3472 * |
| 3473 * |
| 3457 */ | 3474 */ |
| 3458 class V8EXPORT Unlocker { | 3475 class V8EXPORT Unlocker { |
| 3459 public: | 3476 public: |
| 3460 Unlocker(); | 3477 /** |
| 3478 * Initialize Unlocker for a given Isolate. NULL means default isolate. |
| 3479 */ |
| 3480 explicit Unlocker(Isolate* isolate = NULL); |
| 3461 ~Unlocker(); | 3481 ~Unlocker(); |
| 3482 private: |
| 3483 internal::Isolate* isolate_; |
| 3462 }; | 3484 }; |
| 3463 | 3485 |
| 3464 | 3486 |
| 3465 class V8EXPORT Locker { | 3487 class V8EXPORT Locker { |
| 3466 public: | 3488 public: |
| 3467 Locker(); | 3489 /** |
| 3490 * Initialize Locker for a given Isolate. NULL means default isolate. |
| 3491 */ |
| 3492 explicit Locker(Isolate* isolate = NULL); |
| 3468 ~Locker(); | 3493 ~Locker(); |
| 3469 | 3494 |
| 3470 /** | 3495 /** |
| 3471 * Start preemption. | 3496 * Start preemption. |
| 3472 * | 3497 * |
| 3473 * When preemption is started, a timer is fired every n milli seconds | 3498 * When preemption is started, a timer is fired every n milli seconds |
| 3474 * that will switch between multiple threads that are in contention | 3499 * that will switch between multiple threads that are in contention |
| 3475 * for the V8 lock. | 3500 * for the V8 lock. |
| 3476 */ | 3501 */ |
| 3477 static void StartPreemption(int every_n_ms); | 3502 static void StartPreemption(int every_n_ms); |
| 3478 | 3503 |
| 3479 /** | 3504 /** |
| 3480 * Stop preemption. | 3505 * Stop preemption. |
| 3481 */ | 3506 */ |
| 3482 static void StopPreemption(); | 3507 static void StopPreemption(); |
| 3483 | 3508 |
| 3484 /** | 3509 /** |
| 3485 * Returns whether or not the locker is locked by the current thread. | 3510 * Returns whether or not the locker for a given isolate, or default isolate i
f NULL is given, |
| 3511 * is locked by the current thread. |
| 3486 */ | 3512 */ |
| 3487 static bool IsLocked(); | 3513 static bool IsLocked(Isolate* isolate = NULL); |
| 3488 | 3514 |
| 3489 /** | 3515 /** |
| 3490 * Returns whether v8::Locker is being used by this V8 instance. | 3516 * Returns whether v8::Locker is being used by this V8 instance. |
| 3491 */ | 3517 */ |
| 3492 static bool IsActive() { return active_; } | 3518 static bool IsActive() { return active_; } |
| 3493 | 3519 |
| 3494 private: | 3520 private: |
| 3495 bool has_lock_; | 3521 bool has_lock_; |
| 3496 bool top_level_; | 3522 bool top_level_; |
| 3523 internal::Isolate* isolate_; |
| 3497 | 3524 |
| 3498 static bool active_; | 3525 static bool active_; |
| 3499 | 3526 |
| 3500 // Disallow copying and assigning. | 3527 // Disallow copying and assigning. |
| 3501 Locker(const Locker&); | 3528 Locker(const Locker&); |
| 3502 void operator=(const Locker&); | 3529 void operator=(const Locker&); |
| 3503 }; | 3530 }; |
| 3504 | 3531 |
| 3505 | 3532 |
| 3506 /** | 3533 /** |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4055 | 4082 |
| 4056 | 4083 |
| 4057 } // namespace v8 | 4084 } // namespace v8 |
| 4058 | 4085 |
| 4059 | 4086 |
| 4060 #undef V8EXPORT | 4087 #undef V8EXPORT |
| 4061 #undef TYPE_CHECK | 4088 #undef TYPE_CHECK |
| 4062 | 4089 |
| 4063 | 4090 |
| 4064 #endif // V8_H_ | 4091 #endif // V8_H_ |
| OLD | NEW |