DBA Data[Home] [Help]

PACKAGE: SYS.USER_LOCK

Source


1 package user_lock is
2 
3   --  DESCRIPTION
4   --    These routines allow the user to request, convert and release locks.
5   --    The locks are managed by the rdbms lock management services.  All
6   --    lock ids are prepended with the 'UL' prefix so that they cannot
7   --    conflict with DBMS locks.  A sleep procedure is also provided which
8   --    causes the caller to sleep for the given interval (expressed in
9   --    tens of milliseconds.
10   --
11   --  NOTES
12   --    It is up to the clients to agree on the use of these locks.  The lock
13   --    identifier is a number in the range of 1 to approx. 2 billion.  
14   --    Locks persist for the session and any outstanding locks are released
15   --    when the session terminates.
16 
17   function  request(id number, lockmode number, timeout number, global number)
18             return number;
19   -- Returns:
20   --    0 success
21   --    1 timeout
22   --    2 deadlock
23   --    3 parameter error
24 
25   function convert(id number, lockmode number, timeout number) return number;
26   -- Returns:
27   --    0 success
28   --    1 timeout
29   --    2 deadlock
30   --    3 parameter error
31   --    4 don't own lock 'id'
32 
33   function release(id number) return number;
34   -- Returns:
35   --    0 success
36   --    4 don't own lock 'id'
37 
38   procedure sleep(tens_of_millisecs number);
39 
40   -- PARAMETERS:
41 
42   -- lockid - this can be in the range of 0 to about 2 billion
43 
44   -- lockmodes
45   nl_mode  constant number := 1;
46   ss_mode  constant number := 2;
47   sx_mode  constant number := 3;
48   s_mode   constant number := 4;
49   ssx_mode constant number := 5;
50   x_mode   constant number := 6;
51 
52   --  LOCK COMPATIBILITY RULES:
53   --
54   --  When another process holds "held", an attempt to get "get" does
55   --  the following:
56   --
57   --  held  get->  NL   SS   SX   S    SSX  X
58   --  NL           SUCC SUCC SUCC SUCC SUCC SUCC
59   --  SS           SUCC SUCC SUCC SUCC SUCC fail
60   --  SX           SUCC SUCC SUCC fail fail fail
61   --  S            SUCC SUCC fail SUCC fail fail
62   --  SSX          SUCC SUCC fail fail fail fail
63   --  X            SUCC fail fail fail fail fail
64 
65   -- global means multi-instance (parallel server)
66   local    constant number := 0;
67   global   constant number := 1;
68 
69   -- maxwait means wait forever
70   maxwait  constant number := 32767;
71 end;