tldm-universe/Ardent/UV/gcidir/include/LOCK.h

422 lines
11 KiB
C
Raw Normal View History

2024-09-09 21:51:08 +00:00
#ifndef h_LOCK
#define h_LOCK
/******************************************************************************
*
* Declarations for uniVerse lock manager and calling functions
*
* Module %M% Version %I% Date %H%
*
* (c) Copyright 1998 Ardent Software Inc. - All Rights Reserved
* This is unpublished proprietary source code of Ardent Software Inc.
* The copyright notice above does not evidence any actual or intented
* publication of such source code.
*
*******************************************************************************
*
* Maintenence log - insert most recent change descriptions at top
*
* Date.... GTAR# WHO Description.........................................
* 05/25/99 24729 RGA Ensure 8-byte alignment for WAITERS.
* 03/25/99 24755 RGA Change all grpad to DBDADDR.
* 03/10/99 24672 RGA memset was using DBDADDR on 2nd arg.
* 11/11/98 23948 GMH Add hashdata element to readulock structure
* 10/14/98 23801 SAP Change copyrights.
* 08/07/98 22910 JBG Define HAVE_FX
* 08/04/98 22910 JBG Increase PEND_MAX
* 02/10/98 22502 CSM Added SEM_SET_FREE macro
* 12/05/97 21712 JBG Added LOCK_ESCALATE
* 06/19/97 20606 LAG Added UDRLG0SEM, UDRLG1SEM, renamed UDRSEM to
* to UDRSHMSEM for replication
* 05/29/97 20606 LAG Added UDRSEM for replication
* 12/03/96 18403 DTM Backed out previous change
* 12/02/96 18403 DTM Added information about tentative file locks
* 05/20/96 18403 DTM Added information for deadlock detection
* 05/09/96 18423 GMM Put semset/semclr back to voids on NT
* 05/13/96 18403 DTM Added information for deadlock detection
* 05/12/96 18403 DTM Added information for deadlock detection
* 03/22/96 18186 AGM Fix DBsleep for USE_SELECT == 3
* 03/14/96 18156 NXC Port 9 to IBM
* 08/23/95 17242 AGM Replace COMPUTER==WINNT test by MSWIN test
* 06/01/95 16615 PVW Move lock related defines into LOCK.h
*
*****************************************************************************/
#if (USE_SELECT == 1)
#include SY_TIME_H
EXTERN struct timeval DBtimer;
EXTERN int select();
EXTERN int LockWait;
#define DBsleep(x) { DBtimer.tv_usec = (x)*10000;\
(void) select(0,0,0,0,&DBtimer);\
}
#else
# if (USE_SELECT == 2)
/* poll timeout is in millisecs */
# define DBsleep(x) poll(0,0,(x)*10)
# else
# if (USE_SELECT == 3)
/* Sleep timeout is in millisecs */
# define DBsleep(x) Sleep((x)*10)
# else
# define DBsleep(x) sleep(x)
# endif
# endif
#endif
EXTERN int _FSEMNUM; /* file semaphore access ports */
EXTERN int _USEMNUM; /* group semaphore access ports */
EXTERN int _PSEMNUM;
EXTERN int _LFKOFF;
EXTERN int _LOKOFF;
EXTERN int _RDUOFF;
EXTERN int _ULOWNOFF;
EXTERN int _ULFKNUM; /* length of file lock table */
EXTERN int _ULOKNUM; /* length of group lock table */
EXTERN int RUCHUNK;
EXTERN char *_URDUPTR;
EXTERN int _MAXRLOCK; /* lock escalation threshold */
#define FSEM(x) (x)
#define GSEM(x) (_FSEMNUM+(x))
#define PSEM(x) (_FSEMNUM+_USEMNUM+(x))
#define SEM_FIL 1
#define SEM_GRP 2
#define SEM_OTH 3
#ifdef ASM_sem
# define LOGSEM (_FSEMNUM+_USEMNUM+_PSEMNUM)
# define STATSEM (_FSEMNUM+_USEMNUM+_PSEMNUM+1)
# define T30SEM (_FSEMNUM+_USEMNUM+_PSEMNUM+2)
# define TLOGSEM (_FSEMNUM+_USEMNUM+_PSEMNUM+3)
# define TXSEM (_FSEMNUM+_USEMNUM+_PSEMNUM+4)
# define UDRSHMSEM (_FSEMNUM+_USEMNUM+_PSEMNUM+5)
# define UDRLG0SEM (_FSEMNUM+_USEMNUM+_PSEMNUM+6)
# define UDRLG1SEM (_FSEMNUM+_USEMNUM+_PSEMNUM+7)
# define SEM_CNT 8
# define SEM_ACQUIRE( semnum, status, type )\
{\
semset(semnum);\
status = LOCK_SUCCESS;\
}
# define SEM_RELEASE( semnum, status, type )\
{\
semclr(semnum);\
status = LOCK_SUCCESS;\
}
# define SEM_SET_FREE( semnum, status, type )\
{\
semclr(semnum);\
status = LOCK_SUCCESS;\
}
#else
# define LOGSEM (_FSEMNUM+_USEMNUM)
# define STATSEM (_FSEMNUM+_USEMNUM+1)
# define T30SEM (_FSEMNUM+_USEMNUM+2)
# define TLOGSEM (_FSEMNUM+_USEMNUM+3)
# define TXSEM (_FSEMNUM+_USEMNUM+4)
# define UDRSHMSEM (_FSEMNUM+_USEMNUM+5)
# define UDRLG0SEM (_FSEMNUM+_USEMNUM+6)
# define UDRLG1SEM (_FSEMNUM+_USEMNUM+7)
# define SEM_CNT 8
EXTERN struct sembuf sop;
# define SEM_ACQUIRE( semnum, status, type )\
{\
sop.sem_num = (short) semnum;\
sop.sem_op = -1;\
sop.sem_flg = 0;\
while((status = semop(_USMFTAB,&sop,1)) && errno == EINTR);\
if (status)\
{\
switch(type)\
{\
case SEM_FIL:\
status = LOCKFAIL_FSEMACQ;\
break;\
case SEM_GRP:\
status = LOCKFAIL_GSEMACQ;\
break;\
default:\
status = LOCKFAIL_GENERAL;\
break;\
}\
}\
else\
{\
status = LOCK_SUCCESS;\
}\
}
# define SEM_RELEASE( semnum, status, type )\
{\
sop.sem_num = (short) semnum;\
sop.sem_op = 1;\
sop.sem_flg = 0;\
while((status = semop(_USMFTAB,&sop,1)) && errno == EINTR);\
if (status)\
{\
switch(type)\
{\
case SEM_FIL:\
status = LOCKFAIL_FSEMREL;\
break;\
case SEM_GRP:\
status = LOCKFAIL_GSEMREL;\
break;\
default:\
status = LOCKFAIL_GENERAL;\
break;\
}\
}\
else\
{\
status = LOCK_SUCCESS;\
}\
}
# define SEM_SET_FREE( semnum, status, type )\
{\
union semun semctl_arg;\
semctl_arg.val = 1;\
status = semctl(_USMFTAB, semnum, SETVAL, semctl_arg);\
if (status)\
{\
switch(type)\
{\
case SEM_FIL:\
status = LOCKFAIL_FSEMREL;\
break;\
case SEM_GRP:\
status = LOCKFAIL_GSEMREL;\
break;\
default:\
status = LOCKFAIL_GENERAL;\
break;\
}\
}\
else\
{\
status = LOCK_SUCCESS;\
}\
}
#endif
struct DBlatch
{
struct DBlatch *next;
DBFILE *fdesc;
DBDADDR group;
uUVLONG latchtype;
};
struct grouplock
{ uv_ino_t inode;
uUVLONG devid;
uUVLONG signa;
DBDADDR grpad;
unsigned short gw_count;
unsigned short ge_count;
unsigned short gi_count;
unsigned short gs_count;
unsigned short gr_count;
};
#define SGPLCK struct grouplock
#define CGP(x) ((SGPLCK *)(x))
typedef union lockowners FS_OWNERS;
struct filelock
{ uv_ino_t inode;
uUVLONG devid;
uUVLONG signa;
uUVLONG lword;
uUVLONG waiters;
pid_t pid;
};
#define SFLLCK struct filelock
#define CFL(x) ((SFLLCK *)(x))
struct readulock
{ uv_ino_t inode;
uUVLONG devid;
uUVLONG signa;
uUVLONG lword;
uUVLONG waiters;
DBDADDR hashdata;
pid_t pid;
DBDADDR grpad;
uint rukey[16];
};
#define SRULCK struct readulock
#define CRU(x) ((SRULCK *)(x))
#define DBLK_INIT( node )\
{\
(void) memset( (char*)node, (int)0, sizeof( SRULCK ) );\
}
#define DBLK_COPY( src, dest )\
{\
(void) memcpy( (char*)dest, (char*)src, sizeof( SRULCK ) );\
}
#define LOCK_SUCCESS 0
#define LOCK_FAILURE -1
#define LOCK_NETFAILURE -2
#define LOCKFAIL_GENERAL -1
#define LOCKFAIL_UVNETD -2
#define LOCKFAIL_GLNOHANG -3
#define LOCKFAIL_ILLEGAL -4
#define LOCKFAIL_DEADLOCK -5
#define LOCKFAIL_GSEMACQ -6
#define LOCKFAIL_GSEMREL -7
#define LOCKFAIL_FSEMACQ -8
#define LOCKFAIL_FSEMREL -9
#define LOCKFAIL_FILTAB -10
#define LOCKFAIL_FILFSCNT -11
#define LOCKFAIL_FILFSTAB -12
#define LOCKFAIL_GRPGSCNT -13
#define LOCKFAIL_GRPGICNT -14
#define LOCKFAIL_GRPGRCNT -15
#define LOCKFAIL_GRPTAB -16
#define LOCKFAIL_RECTAB -17
#define LOCKFAIL_RECRLCNT -18
#define LOCKFAIL_RECRLTAB -19
#define LOCKFAIL_GRPEXCNT -20
#define LOCK_ESCALATE -21
#define LOCK_TIMEOUT 1800
#define LOCK_DEMOTE 0x2
#define LOCK_WAIT 0x1
#define LOCK_NOWAIT 0x0
#define FLAG_DEADLOCK 0x40
#define WAITER_RETRY_COUNT 3
struct list_element
{
unsigned short status; /* hi 8-bits lock type */
/* lo 4-bits status */
unsigned short link;
int value;
pid_t pid;
};
struct list_control
{
unsigned short magic;
unsigned short head;
unsigned short free;
unsigned short count;
};
union lockowners
{
struct list_element d;
struct list_control c;
};
struct waiters_list
{
pid_t pid_waiter;
pid_t pid_owner;
uUVLONG sig_waiter;
uUVLONG sig_owner;
uv_ino_t lock_inode;
uUVLONG lock_dev;
DBDADDR lock_grpad;
int lock_type;
int status;
};
typedef struct waiters_list WAITERS;
#define SWTLCK struct waiters_list
#define CWL(x) ((SWTLCK *)(x))
typedef union lockowners READL_OWNERS;
#define LIST_INVALID -1
#define LIST_NOSPACE -2
#define LIST_ISDUP -3
#define LIST_FREE 0
#define LIST_INUSE 1
#define LIST_HEAD 2
#define LIST_DEADLOCK 4
#define LIST_READY 8
#define LIST_MAGIC 0x6c73
struct pendlatch
{ uUVLONG latch_type;
DBFILE *fdesc;
DBDADDR group;
};
#define PEND_MAX 20 /* 22910; b_tree may use 6 entries for 3 level tree */
#define CURLCK(x,y) (*((SRULCK*)(_URDUPTR+x*_RDUOFF+ y*sizeof(SRULCK))))
#define CURLCK_PTR(x,y) ((SRULCK*)(_URDUPTR+x*_RDUOFF+ y*sizeof(SRULCK)))
#define DBNETHOSTMASK 0x00ff0000
#define DBNETUSERMASK 0x00ffffff
#define DBUSERMASK 0x0000ffff
#define LOCK_ANYRU 0x00000001
#define LOCK_OTHERRU 0x00000002
#define LOCK_OTHERRL 0x00000004
#define LOCK_ANYRL 0x00000008
#define DBFILEMY 0x00010000
#define DBRECORDMY 0x00000001
#define LOCK_NONE 0x00000000
#define LOCK_FX 0x08000000 /* exclusive sql */
#define LOCK_XU 0x10000000 /* exclusive clearfile */
#define LOCK_CR 0x20000000 /* concurrent resize */
#define LOCK_XR 0x30000000 /* exclusive restructure */
#define LOCK_FSIX 0x40000000 /* intent exclusive */
#define LOCK_FS 0x80000000 /* shared */
#define LOCK_FILE 0xf8000000 /* any file lock */
#define HAVE_FX 2 /* 22910; in flock, means have a LOCK_FX */
#define GROUP_NO_LATCH 0x00000000 /* no latch */
#define GROUP_READ_LATCH 0x00010000 /* read latch */
#define GROUP_SHARED_LATCH 0x00020000 /* shared latch */
/* blocks on RU's */
#define GROUP_EXCLUSIVE_LATCH 0x00040000 /* exclusive latch */
/* blocks on RU's */
#define GROUP_WRITE_LATCH 0x00080000 /* write latch */
#define GROUP_LATCH 0x000f0000 /* any latch */
#define LOCK_MAX (unsigned short) 0x8000 /* maximum count */
#define LOCK_RL 0x00001000 /* shared */
#define LOCK_RU 0x00002000 /* exclusive */
#define LOCK_RECORD 0x00003000 /* any record lock */
#ifdef ASM_sem
#if COMPUTER == IBMrios
#define _SC_NPROCESSORS_CONF 71
EXTERN int AIX_MP; /* This value is set to 0 if a UP system or to 1 if an MP */
EXTERN int (*cs_ptr)();
typedef struct rioslock
{
int w1;
int w2;
int w3;
} RIOSLOCK;
# endif
EXTERN void semset(),semclr();
#endif
#endif /* end of LOCK.h */