ipc.c 18.6 KB
Newer Older
1 2 3
/*-------------------------------------------------------------------------
 *
 * ipc.c--
4
 *	  POSTGRES inter-process communication definitions.
5 6 7 8 9
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
10
 *	  $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.14 1997/09/08 21:46:59 momjian Exp $
11 12 13
 *
 * NOTES
 *
14 15 16 17 18 19 20 21 22 23
 *	  Currently, semaphores are used (my understanding anyway) in two
 *	  different ways:
 *		1. as mutexes on machines that don't have test-and-set (eg.
 *		   mips R3000).
 *		2. for putting processes to sleep when waiting on a lock
 *		   and waking them up when the lock is free.
 *	  The number of semaphores in (1) is fixed and those are shared
 *	  among all backends. In (2), there is 1 semaphore per process and those
 *	  are not shared with anyone else.
 *														  -ay 4/95
24 25 26 27 28 29
 *
 *-------------------------------------------------------------------------
 */
#include <sys/types.h>
#include <sys/file.h>
#include <stdio.h>
B
Bruce Momjian 已提交
30
#include <string.h>
31 32 33
#include <errno.h>


M
Marc G. Fournier 已提交
34
#include "postgres.h"
35
#include "storage/ipc.h"
36 37 38
/* In Ultrix, sem.h and shm.h must be included AFTER ipc.h */
#include <sys/sem.h>
#include <sys/shm.h>
39 40
#include "utils/memutils.h"

41 42 43 44 45
#if defined(sparc_solaris)
#include <string.h>
#include <sys/ipc.h>
#endif

M
Marc G. Fournier 已提交
46
#if defined(bsd44)
47
int			UsePrivateMemory = 1;
48

49
#else
50
int			UsePrivateMemory = 0;
51

52 53
#endif

54
static void IpcMemoryDetach(int status, char *shmaddr);
55

56
/* ----------------------------------------------------------------
57
 *						exit() handling stuff
58 59 60 61 62
 * ----------------------------------------------------------------
 */

#define MAX_ON_EXITS 20

63 64
static struct ONEXIT
{
65 66 67
	void		(*function) ();
	caddr_t		arg;
}			onexit_list[MAX_ON_EXITS];
68

69 70
static int	onexit_index;
static void IpcConfigTip(void);
71

72 73
typedef struct _PrivateMemStruct
{
74 75
	int			id;
	char	   *memptr;
76
} PrivateMem;
77

78
PrivateMem	IpcPrivateMem[16];
79 80 81

static int
PrivateMemoryCreate(IpcMemoryKey memKey,
82
					uint32 size)
83
{
84
	static int	memid = 0;
85 86 87 88 89 90 91 92 93 94

	UsePrivateMemory = 1;

	IpcPrivateMem[memid].id = memid;
	IpcPrivateMem[memid].memptr = malloc(size);
	if (IpcPrivateMem[memid].memptr == NULL)
		elog(WARN, "PrivateMemoryCreate: not enough memory to malloc");
	memset(IpcPrivateMem[memid].memptr, 0, size);		/* XXX PURIFY */

	return (memid++);
95 96
}

97
static char *
98 99
PrivateMemoryAttach(IpcMemoryId memid)
{
100
	return (IpcPrivateMem[memid].memptr);
101 102 103 104
}


/* ----------------------------------------------------------------
105
 *		exitpg
106
 *
107 108 109 110
 *		this function calls all the callbacks registered
 *		for it (to free resources) and then calls exit.
 *		This should be the only function to call exit().
 *		-cim 2/6/90
111 112
 * ----------------------------------------------------------------
 */
113
static int	exitpg_inprogress = 0;
114 115 116 117

void
exitpg(int code)
{
118
	int			i;
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

	/* ----------------
	 *	if exitpg_inprocess is true, then it means that we
	 *	are being invoked from within an on_exit() handler
	 *	and so we return immediately to avoid recursion.
	 * ----------------
	 */
	if (exitpg_inprogress)
		return;

	exitpg_inprogress = 1;

	/* ----------------
	 *	call all the callbacks registered before calling exit().
	 * ----------------
	 */
	for (i = onexit_index - 1; i >= 0; --i)
		(*onexit_list[i].function) (code, onexit_list[i].arg);

	exit(code);
139 140 141 142 143 144 145 146 147 148 149
}

/* ------------------
 * Run all of the on_exitpg routines but don't exit in the end.
 * This is used by the postmaster to re-initialize shared memory and
 * semaphores after a backend dies horribly
 * ------------------
 */
void
quasi_exitpg()
{
150
	int			i;
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

	/* ----------------
	 *	if exitpg_inprocess is true, then it means that we
	 *	are being invoked from within an on_exit() handler
	 *	and so we return immediately to avoid recursion.
	 * ----------------
	 */
	if (exitpg_inprogress)
		return;

	exitpg_inprogress = 1;

	/* ----------------
	 *	call all the callbacks registered before calling exit().
	 * ----------------
	 */
	for (i = onexit_index - 1; i >= 0; --i)
		(*onexit_list[i].function) (0, onexit_list[i].arg);

	onexit_index = 0;
	exitpg_inprogress = 0;
172 173 174
}

/* ----------------------------------------------------------------
175
 *		on_exitpg
176
 *
177 178
 *		this function adds a callback function to the list of
 *		functions invoked by exitpg().	-cim 2/6/90
179 180 181
 * ----------------------------------------------------------------
 */
int
182
			on_exitpg(void (*function) (), caddr_t arg)
183
{
184 185 186 187 188 189 190 191 192
	if (onexit_index >= MAX_ON_EXITS)
		return (-1);

	onexit_list[onexit_index].function = function;
	onexit_list[onexit_index].arg = arg;

	++onexit_index;

	return (0);
193 194 195
}

/****************************************************************************/
196 197
/*	 IPCPrivateSemaphoreKill(status, semId)									*/
/*																			*/
198 199 200
/****************************************************************************/
static void
IPCPrivateSemaphoreKill(int status,
201
						int semId)		/* caddr_t */
202
{
203
	union semun semun;
204 205

	semctl(semId, 0, IPC_RMID, semun);
206 207 208 209
}


/****************************************************************************/
210 211
/*	 IPCPrivateMemoryKill(status, shmId)									*/
/*																			*/
212 213 214
/****************************************************************************/
static void
IPCPrivateMemoryKill(int status,
215
					 int shmId) /* caddr_t */
216
{
217 218 219 220 221 222 223 224 225 226 227
	if (UsePrivateMemory)
	{
		/* free ( IpcPrivateMem[shmId].memptr ); */
	}
	else
	{
		if (shmctl(shmId, IPC_RMID, (struct shmid_ds *) NULL) < 0)
		{
			elog(NOTICE, "IPCPrivateMemoryKill: shmctl(%d, %d, 0) failed: %m",
				 shmId, IPC_RMID);
		}
228 229 230 231 232
	}
}


/****************************************************************************/
233 234 235 236
/*	 IpcSemaphoreCreate(semKey, semNum, permission, semStartValue)			*/
/*																			*/
/*	  - returns a semaphore identifier:										*/
/*																			*/
237
/* if key doesn't exist: return a new id,      status:= IpcSemIdNotExist    */
238 239 240
/* if key exists:		 return the old id,    status:= IpcSemIdExist		*/
/* if semNum > MAX :	 return # of argument, status:=IpcInvalidArgument	*/
/*																			*/
241 242 243 244
/****************************************************************************/

/*
 * Note:
245 246
 * XXX	This should be split into two different calls.	One should
 * XXX	be used to create a semaphore set.	The other to "attach" a
247 248 249
 * XXX	existing set.  It should be an error for the semaphore set
 * XXX	to to already exist or for it not to, respectively.
 *
250 251
 *		Currently, the semaphore sets are "attached" and an error
 *		is detected only when a later shared memory attach fails.
252 253 254 255
 */

IpcSemaphoreId
IpcSemaphoreCreate(IpcSemaphoreKey semKey,
256 257 258 259 260
				   int semNum,
				   int permission,
				   int semStartValue,
				   int removeOnExit,
				   int *status)
261
{
262 263 264 265 266
	int			i;
	int			errStatus;
	int			semId;
	u_short		array[IPC_NMAXSEM];
	union semun semun;
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281

	/* get a semaphore if non-existent */
	/* check arguments	*/
	if (semNum > IPC_NMAXSEM || semNum <= 0)
	{
		*status = IpcInvalidArgument;
		return (2);				/* returns the number of the invalid
								 * argument   */
	}

	semId = semget(semKey, 0, 0);

	if (semId == -1)
	{
		*status = IpcSemIdNotExist;		/* there doesn't exist a semaphore */
282
#ifdef DEBUG_IPC
283 284 285 286
		fprintf(stderr, "calling semget with %d, %d , %d\n",
				semKey,
				semNum,
				IPC_CREAT | permission);
287
#endif
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
		semId = semget(semKey, semNum, IPC_CREAT | permission);

		if (semId < 0)
		{
			perror("semget");
			IpcConfigTip();
			exitpg(3);
		}
		for (i = 0; i < semNum; i++)
		{
			array[i] = semStartValue;
		}
		semun.array = array;
		errStatus = semctl(semId, 0, SETALL, semun);
		if (errStatus == -1)
		{
			perror("semctl");
			IpcConfigTip();
		}

		if (removeOnExit)
			on_exitpg(IPCPrivateSemaphoreKill, (caddr_t) semId);
310 311

	}
312 313 314 315
	else
	{
		/* there is a semaphore id for this key */
		*status = IpcSemIdExist;
316
	}
317

318
#ifdef DEBUG_IPC
319 320 321 322 323
	fprintf(stderr, "\nIpcSemaphoreCreate, status %d, returns %d\n",
			*status,
			semId);
	fflush(stdout);
	fflush(stderr);
324
#endif
325
	return (semId);
326 327 328 329
}


/****************************************************************************/
330 331 332
/*	 IpcSemaphoreSet()			- sets the initial value of the semaphore	*/
/*																			*/
/*		note: the xxx_return variables are only used for debugging.			*/
333
/****************************************************************************/
334
#ifdef NOT_USED
335
static int	IpcSemaphoreSet_return;
336 337 338 339

void
IpcSemaphoreSet(int semId, int semno, int value)
{
340 341
	int			errStatus;
	union semun semun;
342 343 344 345 346 347 348 349 350 351

	semun.val = value;
	errStatus = semctl(semId, semno, SETVAL, semun);
	IpcSemaphoreSet_return = errStatus;

	if (errStatus == -1)
	{
		perror("semctl");
		IpcConfigTip();
	}
352
}
353

354
#endif
355 356

/****************************************************************************/
357 358
/*	 IpcSemaphoreKill(key)		- removes a semaphore						*/
/*																			*/
359 360 361 362
/****************************************************************************/
void
IpcSemaphoreKill(IpcSemaphoreKey key)
{
363 364
	int			semId;
	union semun semun;
365 366 367 368 369 370

	/* kill semaphore if existent */

	semId = semget(key, 0, 0);
	if (semId != -1)
		semctl(semId, 0, IPC_RMID, semun);
371 372 373
}

/****************************************************************************/
374 375 376
/*	 IpcSemaphoreLock(semId, sem, lock) - locks a semaphore					*/
/*																			*/
/*		note: the xxx_return variables are only used for debugging.			*/
377
/****************************************************************************/
378
static int	IpcSemaphoreLock_return;
379 380 381 382

void
IpcSemaphoreLock(IpcSemaphoreId semId, int sem, int lock)
{
383 384 385
	extern int	errno;
	int			errStatus;
	struct sembuf sops;
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414

	sops.sem_op = lock;
	sops.sem_flg = 0;
	sops.sem_num = sem;

	/* ----------------
	 *	Note: if errStatus is -1 and errno == EINTR then it means we
	 *		  returned from the operation prematurely because we were
	 *		  sent a signal.  So we try and lock the semaphore again.
	 *		  I am not certain this is correct, but the semantics aren't
	 *		  clear it fixes problems with parallel abort synchronization,
	 *		  namely that after processing an abort signal, the semaphore
	 *		  call returns with -1 (and errno == EINTR) before it should.
	 *		  -cim 3/28/90
	 * ----------------
	 */
	do
	{
		errStatus = semop(semId, &sops, 1);
	} while (errStatus == -1 && errno == EINTR);

	IpcSemaphoreLock_return = errStatus;

	if (errStatus == -1)
	{
		perror("semop");
		IpcConfigTip();
		exitpg(255);
	}
415 416 417
}

/****************************************************************************/
418 419 420
/*	 IpcSemaphoreUnlock(semId, sem, lock)		- unlocks a semaphore		*/
/*																			*/
/*		note: the xxx_return variables are only used for debugging.			*/
421
/****************************************************************************/
422
static int	IpcSemaphoreUnlock_return;
423 424 425 426

void
IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem, int lock)
{
427 428 429
	extern int	errno;
	int			errStatus;
	struct sembuf sops;
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459

	sops.sem_op = -lock;
	sops.sem_flg = 0;
	sops.sem_num = sem;


	/* ----------------
	 *	Note: if errStatus is -1 and errno == EINTR then it means we
	 *		  returned from the operation prematurely because we were
	 *		  sent a signal.  So we try and lock the semaphore again.
	 *		  I am not certain this is correct, but the semantics aren't
	 *		  clear it fixes problems with parallel abort synchronization,
	 *		  namely that after processing an abort signal, the semaphore
	 *		  call returns with -1 (and errno == EINTR) before it should.
	 *		  -cim 3/28/90
	 * ----------------
	 */
	do
	{
		errStatus = semop(semId, &sops, 1);
	} while (errStatus == -1 && errno == EINTR);

	IpcSemaphoreUnlock_return = errStatus;

	if (errStatus == -1)
	{
		perror("semop");
		IpcConfigTip();
		exitpg(255);
	}
460 461 462
}

int
463
IpcSemaphoreGetCount(IpcSemaphoreId semId, int sem)
464
{
465 466
	int			semncnt;
	union semun dummy;			/* for Solaris */
467 468 469

	semncnt = semctl(semId, sem, GETNCNT, dummy);
	return semncnt;
470 471 472
}

int
473
IpcSemaphoreGetValue(IpcSemaphoreId semId, int sem)
474
{
475 476
	int			semval;
	union semun dummy;			/* for Solaris */
477 478 479

	semval = semctl(semId, sem, GETVAL, dummy);
	return semval;
480 481 482
}

/****************************************************************************/
483 484 485 486
/*	 IpcMemoryCreate(memKey)												*/
/*																			*/
/*	  - returns the memory identifier, if creation succeeds					*/
/*		returns IpcMemCreationFailed, if failure							*/
487 488 489 490 491
/****************************************************************************/

IpcMemoryId
IpcMemoryCreate(IpcMemoryKey memKey, uint32 size, int permission)
{
492
	IpcMemoryId shmid;
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516

	if (memKey == PrivateIPCKey)
	{
		/* private */
		shmid = PrivateMemoryCreate(memKey, size);
	}
	else
	{
		shmid = shmget(memKey, size, IPC_CREAT | permission);
	}

	if (shmid < 0)
	{
		fprintf(stderr, "IpcMemoryCreate: memKey=%d , size=%d , permission=%d",
				memKey, size, permission);
		perror("IpcMemoryCreate: shmget(..., create, ...) failed");
		IpcConfigTip();
		return (IpcMemCreationFailed);
	}

	/* if (memKey == PrivateIPCKey) */
	on_exitpg(IPCPrivateMemoryKill, (caddr_t) shmid);

	return (shmid);
517 518 519
}

/****************************************************************************/
520 521
/*	IpcMemoryIdGet(memKey, size)	returns the shared memory Id			*/
/*									or IpcMemIdGetFailed					*/
522 523 524 525
/****************************************************************************/
IpcMemoryId
IpcMemoryIdGet(IpcMemoryKey memKey, uint32 size)
{
526
	IpcMemoryId shmid;
527 528 529 530 531 532 533 534 535 536 537 538 539

	shmid = shmget(memKey, size, 0);

	if (shmid < 0)
	{
		fprintf(stderr, "IpcMemoryIdGet: memKey=%d , size=%d , permission=%d",
				memKey, size, 0);
		perror("IpcMemoryIdGet:  shmget() failed");
		IpcConfigTip();
		return (IpcMemIdGetFailed);
	}

	return (shmid);
540 541 542
}

/****************************************************************************/
543 544 545
/*	IpcMemoryDetach(status, shmaddr)	removes a shared memory segment		*/
/*										from a backend address space		*/
/*	(only called by backends running under the postmaster)					*/
546
/****************************************************************************/
547
static void
548 549
IpcMemoryDetach(int status, char *shmaddr)
{
550 551 552 553
	if (shmdt(shmaddr) < 0)
	{
		elog(NOTICE, "IpcMemoryDetach: shmdt(0x%x): %m", shmaddr);
	}
554 555 556
}

/****************************************************************************/
557 558 559 560 561
/*	IpcMemoryAttach(memId)	  returns the adress of shared memory			*/
/*							  or IpcMemAttachFailed							*/
/*																			*/
/* CALL IT:  addr = (struct <MemoryStructure> *) IpcMemoryAttach(memId);	*/
/*																			*/
562
/****************************************************************************/
563
char	   *
564 565
IpcMemoryAttach(IpcMemoryId memId)
{
566
	char	   *memAddress;
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588

	if (UsePrivateMemory)
	{
		memAddress = (char *) PrivateMemoryAttach(memId);
	}
	else
	{
		memAddress = (char *) shmat(memId, 0, 0);
	}

	/* if ( *memAddress == -1) { XXX ??? */
	if (memAddress == (char *) -1)
	{
		perror("IpcMemoryAttach: shmat() failed");
		IpcConfigTip();
		return (IpcMemAttachFailed);
	}

	if (!UsePrivateMemory)
		on_exitpg(IpcMemoryDetach, (caddr_t) memAddress);

	return ((char *) memAddress);
589 590 591 592
}


/****************************************************************************/
593 594
/*	IpcMemoryKill(memKey)				removes a shared memory segment		*/
/*	(only called by the postmaster and standalone backends)					*/
595 596 597
/****************************************************************************/
void
IpcMemoryKill(IpcMemoryKey memKey)
598
{
599
	IpcMemoryId shmid;
600 601 602 603 604 605 606 607

	if (!UsePrivateMemory && (shmid = shmget(memKey, 0, 0)) >= 0)
	{
		if (shmctl(shmid, IPC_RMID, (struct shmid_ds *) NULL) < 0)
		{
			elog(NOTICE, "IpcMemoryKill: shmctl(%d, %d, 0) failed: %m",
				 shmid, IPC_RMID);
		}
608
	}
609
}
610 611 612

#ifdef HAS_TEST_AND_SET
/* ------------------
613 614 615
 *	use hardware locks to replace semaphores for sequent machines
 *	to avoid costs of swapping processes and to provide unlimited
 *	supply of locks.
616 617
 * ------------------
 */
618 619 620
static SLock *SLockArray = NULL;
static SLock **FreeSLockPP;
static int *UnusedSLockIP;
621 622 623
static slock_t *SLockMemoryLock;
static IpcMemoryId SLockMemoryId = -1;

624 625
struct ipcdummy
{								/* to get alignment/size right */
626 627 628 629
	SLock	   *free;
	int			unused;
	slock_t		memlock;
	SLock		slocks[NSLOCKS];
630
};
631
static int	SLockMemorySize = sizeof(struct ipcdummy);
632 633 634 635

void
CreateAndInitSLockMemory(IPCKey key)
{
636 637
	int			id;
	SLock	   *slckP;
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656

	SLockMemoryId = IpcMemoryCreate(key,
									SLockMemorySize,
									0700);
	AttachSLockMemory(key);
	*FreeSLockPP = NULL;
	*UnusedSLockIP = (int) FIRSTFREELOCKID;
	for (id = 0; id < (int) FIRSTFREELOCKID; id++)
	{
		slckP = &(SLockArray[id]);
		S_INIT_LOCK(&(slckP->locklock));
		slckP->flag = NOLOCK;
		slckP->nshlocks = 0;
		S_INIT_LOCK(&(slckP->shlock));
		S_INIT_LOCK(&(slckP->exlock));
		S_INIT_LOCK(&(slckP->comlock));
		slckP->next = NULL;
	}
	return;
657 658 659 660 661
}

void
AttachSLockMemory(IPCKey key)
{
662 663 664 665 666 667 668 669 670
	struct ipcdummy *slockM;

	if (SLockMemoryId == -1)
		SLockMemoryId = IpcMemoryIdGet(key, SLockMemorySize);
	if (SLockMemoryId == -1)
		elog(FATAL, "SLockMemory not in shared memory");
	slockM = (struct ipcdummy *) IpcMemoryAttach(SLockMemoryId);
	if (slockM == IpcMemAttachFailed)
		elog(FATAL, "AttachSLockMemory: could not attach segment");
671
	FreeSLockPP = (SLock **) &(slockM->free);
672
	UnusedSLockIP = (int *) &(slockM->unused);
673
	SLockMemoryLock = (slock_t *) &(slockM->memlock);
674
	S_INIT_LOCK(SLockMemoryLock);
675
	SLockArray = (SLock *) &(slockM->slocks[0]);
676
	return;
677 678 679 680 681 682
}


#ifdef LOCKDEBUG
#define PRINT_LOCK(LOCK) printf("(locklock = %d, flag = %d, nshlocks = %d, \
shlock = %d, exlock =%d)\n", LOCK->locklock, \
683 684
								LOCK->flag, LOCK->nshlocks, LOCK->shlock, \
								LOCK->exlock)
685 686 687 688 689
#endif

void
ExclusiveLock(int lockid)
{
690
	SLock	   *slckP;
691 692

	slckP = &(SLockArray[lockid]);
693
#ifdef LOCKDEBUG
694 695 696
	printf("ExclusiveLock(%d)\n", lockid);
	printf("IN: ");
	PRINT_LOCK(slckP);
697
#endif
698 699 700 701
ex_try_again:
	S_LOCK(&(slckP->locklock));
	switch (slckP->flag)
	{
702 703 704 705 706
		case NOLOCK:
			slckP->flag = EXCLUSIVELOCK;
			S_LOCK(&(slckP->exlock));
			S_LOCK(&(slckP->shlock));
			S_UNLOCK(&(slckP->locklock));
707
#ifdef LOCKDEBUG
708 709
			printf("OUT: ");
			PRINT_LOCK(slckP);
710
#endif
711 712 713 714 715 716 717
			return;
		case SHAREDLOCK:
		case EXCLUSIVELOCK:
			S_UNLOCK(&(slckP->locklock));
			S_LOCK(&(slckP->exlock));
			S_UNLOCK(&(slckP->exlock));
			goto ex_try_again;
718
	}
719 720 721 722 723
}

void
ExclusiveUnlock(int lockid)
{
724
	SLock	   *slckP;
725 726

	slckP = &(SLockArray[lockid]);
727
#ifdef LOCKDEBUG
728 729 730
	printf("ExclusiveUnlock(%d)\n", lockid);
	printf("IN: ");
	PRINT_LOCK(slckP);
731
#endif
732 733 734 735 736 737 738 739 740 741 742 743 744 745
	S_LOCK(&(slckP->locklock));
	/* -------------
	 *	give favor to read processes
	 * -------------
	 */
	slckP->flag = NOLOCK;
	if (slckP->nshlocks > 0)
	{
		while (slckP->nshlocks > 0)
		{
			S_UNLOCK(&(slckP->shlock));
			S_LOCK(&(slckP->comlock));
		}
		S_UNLOCK(&(slckP->shlock));
746
	}
747 748 749 750 751 752
	else
	{
		S_UNLOCK(&(slckP->shlock));
	}
	S_UNLOCK(&(slckP->exlock));
	S_UNLOCK(&(slckP->locklock));
753
#ifdef LOCKDEBUG
754 755
	printf("OUT: ");
	PRINT_LOCK(slckP);
756
#endif
757
	return;
758 759 760 761 762
}

bool
LockIsFree(int lockid)
{
763
	return (SLockArray[lockid].flag == NOLOCK);
764 765
}

766
#endif							/* HAS_TEST_AND_SET */
767 768

static void
769
IpcConfigTip(void)
770
{
771 772 773
	fprintf(stderr, "This type of error is usually caused by improper\n");
	fprintf(stderr, "shared memory or System V IPC semaphore configuration.\n");
	fprintf(stderr, "See the FAQ for more detailed information\n");
774
}