Method and apparatus for providing dynamic locks for global resources
AssigneeSun Microsystems, Inc.
InventorPrabahar Jeyaram
Life of this patent
Estimating the term…
Abstract
One embodiment of the present invention provides a system that facilitates applying a dynamic lock to a range of a resource within a computer system. Upon receiving a request to lock to the range of the resource from a thread, the system examines an active lock pool to determine if the range of the resource is currently locked. If not, the system retrieves a dynamic lock from a free lock pool. Next, the system sets resource information in the dynamic lock so that the dynamic lock is associated with the resource. The system also sets owner information in the dynamic lock so that the dynamic lock is associated with the thread that is requesting the dynamic lock. Finally, the system adds the dynamic lock to the active lock pool.
Claims17
A method for applying a dynamic lock to a range of a resource within a computer system, comprising:
- receiving a request to lock to the range of the resource from a thread in the computer system, wherein the range of the resource is a portion of the resource;
- examining an active lock pool to determine if the range of the resource is currently locked, wherein the active lock pool is organized as a hash table and wherein examining the active lock pool involves performing a hash lookup into the active lock pool based on the range of the resource,
- if the hash lookup returns an active lock, determining whether the active lock is associated with the range of the resource by retrieving resource information from the active lock and comparing the resource information with the range of the resource;
- and
- if the range of the resource is not currently locked,
- retrieving the dynamic lock from a free lock pool,
- setting resource information in the dynamic lock so that the dynamic lock is associated with the range of the resource,
- setting owner information in the dynamic lock so that the dynamic lock is associated with the thread that is requesting the dynamic lock, and
- adding the dynamic lock to the active lock pool;
- whereby locking the range of the resource protects the locked portion of the resource without preventing other threads from locking and accessing other portions of the resource.
A computer-readable storage medium storing instructions that when executed by a computer cause the computer to perform a method for applying a dynamic lock to a range of a resource within a computer system, the method comprising:
- receiving a request to lock to the range of the resource from a thread in the computer system, wherein the range of the resource is a portion of the resource;
- examining an active lock pool to determine if the range of the resource is currently locked, wherein the active lock pool is organized as a hash table and wherein examining the active lock pool involves performing a hash lookup into the active lock pool based on the range of the resources and
- wherein the hash lookup returns and active lock, the method further comprises determining whether the active lock is associated with the range of the resource by retrieving resource information from the active lock and comparing the resource information with the range of the resource;
- if the range of the resource is not currently locked,
- retrieving the dynamic lock from a free lock pool,
- setting resource information in the dynamic lock so that the dynamic lock is associated with the range of the resource,
- setting owner information in the dynamic lock so that the dynamic lock is associated with the thread that is requesting the dynamic lock, and
- adding the dynamic lock to the active lock pool;
- whereby locking the range of the resource protects the locked portion of the resource without preventing other threads from locking and accessing other portions of the resource.
A apparatus for applying a dynamic lock to a range of a resource within a computer system, comprising:
- a processor;
- a receiving mechanism configured to receive a request to lock to the range of the resource from a thread in the computer system, wherein the range of the resource is a portion of the resource;
- an examining mechanism configured to examine an active lock pool to determine if the range of the resource is currently locked, wherein the active lock pool is organized as a hash table and wherein the examining mechanism is further configured to perform a hash lookup into the active lock pool based on the range of the resource;
- and
- wherein if the hash lookup returns an active lock, the examining mechanism is configured to retrieve resource information from the active lock and compare the resource information with the range of the resource to determine whether the active lock is associated with the range of the resource;
- a locking mechanism, wherein if the range of the resource is not currently locked, the locking mechanism is configured to,
- retrieve the dynamic lock from a free lock pool,
- set resource information in the dynamic lock so that the dynamic lock is associated with the range of the resource,
- set owner information in the dynamic lock so that the dynamic lock is associated with the thread that is requesting the dynamic lock, and to
- add the dynamic lock to the active lock pool;
- whereby locking the range of the resource protects the locked portion of the resource without preventing other threads from locking and accessing other portions of the resource.
A computer system for applying a dynamic lock to a range of a resource, comprising:
- a processor;
- a memory;
- an operating system that supports multiple threads;
- an active lock pool within the operating system, wherein the active lock pool is organized as a hash table;
- a free lock pool within the operating system;
- a receiving mechanism within the operating system that is configured to receive a request to lock to the range of the resource from a thread, wherein the range of the resource is a portion of the resource;
- an examining mechanism within the operating system configured to perform a hash lookup into the active lock pool based on the range of the resource to determine if the range of the resource is currently locked;
- and
- wherein if the hash lookup returns an active lock the examining mechanism is configured to retrieve resource information from the active lock and compare the resource information with the range of the resource to determine whether the active lock is associated with the range of the resource;
- a locking mechanism within the operating system, wherein if the range of the resource is not currently locked the locking mechanism is configured to,
- retrieve the dynamic lock from the free lock pool,
- set resource information in the dynamic lock so that the dynamic lock is associated with the range of the resource,
- set owner information in the dynamic lock so that the dynamic lock is associated with the thread that is requesting the dynamic lock, and to
- add the dynamic lock to the active lock pool.
- whereby locking the range of the resource protects the locked portion of the resource without preventing other threads from locking and accessing other portions of the resource.
Dependencies are inferred from the claim text.