Index: src/backend/commands/vacuum.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/commands/vacuum.c,v
retrieving revision 1.324
diff -c -r1.324 vacuum.c
*** src/backend/commands/vacuum.c	11 Feb 2006 23:31:33 -0000	1.324
--- src/backend/commands/vacuum.c	15 Feb 2006 11:00:13 -0000
***************
*** 37,42 ****
--- 37,43 ----
  #include "miscadmin.h"
  #include "postmaster/autovacuum.h"
  #include "storage/freespace.h"
+ #include "storage/lwlock.h"
  #include "storage/procarray.h"
  #include "storage/smgr.h"
  #include "tcop/pquery.h"
***************
*** 3441,3447 ****
  		if (msec > VacuumCostDelay * 4)
  			msec = VacuumCostDelay * 4;
  
! 		pg_usleep(msec * 1000L);
  
  		VacuumCostBalance = 0;
  
--- 3442,3451 ----
  		if (msec > VacuumCostDelay * 4)
  			msec = VacuumCostDelay * 4;
  
!         if (LWLockNumHeldByMe() == 0)
!     		pg_usleep(msec * 1000L);
!         else
! 			elog(WARNING, "losing sleep because internal locks are held");
  
  		VacuumCostBalance = 0;
  
Index: src/backend/storage/lmgr/lwlock.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/storage/lmgr/lwlock.c,v
retrieving revision 1.37
diff -c -r1.37 lwlock.c
*** src/backend/storage/lmgr/lwlock.c	29 Dec 2005 18:08:05 -0000	1.37
--- src/backend/storage/lmgr/lwlock.c	15 Feb 2006 11:00:14 -0000
***************
*** 604,606 ****
--- 604,612 ----
  	}
  	return false;
  }
+ 
+ int
+ LWLockNumHeldByMe(void)
+ {
+     return num_held_lwlocks;
+ }
Index: src/include/storage/lwlock.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/storage/lwlock.h,v
retrieving revision 1.26
diff -c -r1.26 lwlock.h
*** src/include/storage/lwlock.h	19 Jan 2006 04:45:38 -0000	1.26
--- src/include/storage/lwlock.h	15 Feb 2006 11:00:18 -0000
***************
*** 70,75 ****
--- 70,76 ----
  extern void LWLockRelease(LWLockId lockid);
  extern void LWLockReleaseAll(void);
  extern bool LWLockHeldByMe(LWLockId lockid);
+ extern int  LWLockNumHeldByMe(void);
  
  extern int	NumLWLocks(void);
  extern Size LWLockShmemSize(void);
