1: # include <ingres.h>
2: # include <aux.h>
3: # include <tree.h>
4: # include "globs.h"
5: # include <lock.h>
6: # include <sccs.h>
7:
8: SCCSID(@(#)lockit.c 8.1 12/31/84)
9:
10: /*
11: ** LOCKIT -- sets relation locks for integrity locking
12: **
13: ** Parameters:
14: ** root- the root of a query tree;
15: ** resvar- index of variable to be updated.
16: **
17: */
18: lockit(root, resvar)
19: QTREE *root;
20: int resvar;
21: {
22: register QTREE *r;
23: register int i, j;
24: long vlist[MAXRANGE];
25: int bmap, cv;
26: char mode;
27: int skvr;
28: int redo;
29: DESC *d, *openr1();
30: long restid;
31: int k;
32:
33: r = root;
34: bmap = r->sym.value.sym_root.lvarm | r->sym.value.sym_root.rvarm;
35: if (resvar >= 0)
36: bmap |= 01 << resvar;
37: else
38: restid = -1;
39: i = 0;
40: /* put relids of relations to be locked into vlist
41: check for and remove duplicates */
42: for (j = 0; j < MAXRANGE; j++)
43: if (bmap & (01 << j))
44: {
45: d = openr1(j);
46: if (j == resvar)
47: restid = d->reltid.ltid;
48: for (k = 0; k < i; k++)
49: if (vlist[k] == d->reltid.ltid)
50: break;
51: if (k == i)
52: vlist[i++] = d->reltid.ltid;
53: }
54: cv = i;
55: /*
56: * set the locks: set the first lock with the sleep option
57: * set other locks checking for failure;
58: * if failure, release all locks, sleep on blocking
59: * lock.
60: */
61: skvr = -1;
62: do
63: {
64: /* skvr is the index of the relation already locked
65: try to lock the remaining relations */
66: redo = FALSE;
67: for (i = 0; i < cv; i++)
68: if (i != skvr)
69: {
70: if (restid == vlist[i])
71: mode = M_EXCL;
72: else
73: mode = M_SHARE;
74: if (setrll(A_RTN, vlist[i], mode) < 0)
75: /* a lock request failed */
76: {
77: unlall(); /* release all locks */
78: setrll(A_SLP, vlist[i], mode);
79: /* wait on problem lock*/
80: skvr = i;
81: redo = TRUE;
82: break; /* reset the other locks */
83: }
84: }
85: }
86: while (redo);
87: }
Defined functions
lockit
defined in line
8; used 1 times