本文整理汇总了C++中pg_usleep函数的典型用法代码示例。如果您正苦于以下问题:C++ pg_usleep函数的具体用法?C++ pg_usleep怎么用?C++ pg_usleep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pg_usleep函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StreamBatchWaitAndRemove
void StreamBatchWaitAndRemove(StreamBatch *batch)
{
int cycle = 0;
while (!StreamBatchAllAcked(batch))
{
if (cycle % CHECK_CRASH_CYCLES == 0)
{
int num_crashes = num_cq_crashes(batch);
cycle = 0;
if (num_crashes == 0)
continue;
// All tuples have been read, and we've received acks from all workers that didn't crash.
if (StreamBatchAllRead(batch) &&
batch->num_wacks >= (batch->num_tups * (bms_num_members(batch->readers) - num_crashes)))
break;
}
pg_usleep(SLEEP_MS * 1000);
cycle++;
}
ShmemDynFree(batch);
}
示例2: initializeJavaVM
static jint initializeJavaVM(JVMOptList *optList)
{
jint jstat;
JavaVMInitArgs vm_args;
if(pljava_debug)
{
elog(INFO, "Backend pid = %d. Attach the debugger and set pljava_debug to false to continue", getpid());
while(pljava_debug)
pg_usleep(1000000L);
}
vm_args.nOptions = optList->size;
vm_args.options = optList->options;
vm_args.version = JNI_VERSION_1_4;
vm_args.ignoreUnrecognized = JNI_FALSE;
elog(DEBUG2, "creating Java virtual machine");
jstat = JNI_createVM(&s_javaVM, &vm_args);
if(jstat == JNI_OK && JNI_exceptionCheck())
{
JNI_exceptionDescribe();
JNI_exceptionClear();
jstat = JNI_ERR;
}
JVMOptList_delete(optList);
return jstat;
}
示例3: terminate_group
static void
terminate_group(ContQueryProcGroup *grp)
{
bool found;
int i;
grp->active = true;
for (i = 0; i < TOTAL_SLOTS; i++)
{
ContQueryProc *proc = &grp->procs[i];
/* Wake up processes, so they can see the terminate flag. */
SetLatch(proc->latch);
/* Let workers crash now as well in case we force terminate them. */
ChangeBackgroundWorkerRestartState(&proc->handle, true, 0);
}
/* Wait for a bit and then force terminate any processes that are still alive. */
pg_usleep(Max(ContQuerySchedulerShmem->params.max_wait, MIN_WAIT_TERMINATE_MS) * 1000);
for (i = 0; i < TOTAL_SLOTS; i++)
{
ContQueryProc *proc = &grp->procs[i];
TerminateBackgroundWorker(&proc->handle);
}
hash_search(ContQuerySchedulerShmem->proc_table, &grp->db_oid, HASH_REMOVE, &found);
Assert(found);
TupleBufferDrain(WorkerTupleBuffer, grp->db_oid);
TupleBufferDrain(CombinerTupleBuffer, grp->db_oid);
}
示例4: perform_spin_delay
/*
* Wait while spinning on a contended spinlock.
*/
void
perform_spin_delay(SpinDelayStatus *status)
{
/* CPU-specific delay each time through the loop */
SPIN_DELAY();
/* Block the process every spins_per_delay tries */
if (++(status->spins) >= spins_per_delay)
{
if (++(status->delays) > NUM_DELAYS)
s_lock_stuck(status->file, status->line, status->func);
if (status->cur_delay == 0) /* first time to delay? */
status->cur_delay = MIN_DELAY_USEC;
pg_usleep(status->cur_delay);
#if defined(S_LOCK_TEST)
fprintf(stdout, "*");
fflush(stdout);
#endif
/* increase delay by a random fraction between 1X and 2X */
status->cur_delay += (int) (status->cur_delay *
((double) random() / (double) MAX_RANDOM_VALUE) + 0.5);
/* wrap back to minimum delay when max is exceeded */
if (status->cur_delay > MAX_DELAY_USEC)
status->cur_delay = MIN_DELAY_USEC;
status->spins = 0;
}
}
示例5: pgrename
/*
* pgrename
*/
int
pgrename(const char *from, const char *to)
{
int loops = 0;
/*
* We need to loop because even though PostgreSQL uses flags that
* allow rename while the file is open, other applications might have
* the file open without those flags. However, we won't wait
* indefinitely for someone else to close the file.
*/
#if defined(WIN32) && !defined(__CYGWIN__)
while (!MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING))
#else
while (rename(from, to) < 0)
#endif
{
#if defined(WIN32) && !defined(__CYGWIN__)
if (GetLastError() != ERROR_ACCESS_DENIED)
#else
if (errno != EACCES)
#endif
/* set errno? */
return -1;
if (++loops > 300) /* time out after 30 sec */
return -1;
pg_usleep(100000); /* us */
}
return 0;
}
示例6: cdbdisp_waitThreads
/*
* Synchronize threads to finish for this process to die. Dispatching
* threads need to acknowledge that we are dying, otherwise the main
* thread will cleanup memory contexts which could cause process crash
* while the threads are touching stale pointers. Threads will check
* proc_exit_inprogress and immediately stops once it's found to be true.
*/
void
cdbdisp_waitThreads(void)
{
int i,
max_retry;
long interval = 10 * 1000; /* 10 msec */
/*
* Just in case to avoid to be stuck in the final stage of process
* lifecycle, insure by setting time limit. If it exceeds, it probably
* means some threads are stuck and not progressing, in which case
* we can go ahead and cleanup things anyway. The duration should be
* longer than the select timeout in thread_DispatchWait.
*/
max_retry = (DISPATCH_WAIT_TIMEOUT_SEC + 10) * 1000000L / interval;
/*
* This is supposed to be called after the flag is set.
*/
Assert(proc_exit_inprogress);
for (i = 0; i < max_retry; i++)
{
if (RunningThreadCount == 0)
break;
pg_usleep(interval);
}
}
示例7: pgunlink
/*
* pgunlink
*/
int
pgunlink(const char *path)
{
int loops = 0;
/* Is this loop even necessary now that we have win32_open()? */
while (unlink(path))
{
if (errno != EACCES)
/* set errno? */
return -1;
pg_usleep(100000); /* us */
if (loops == 30)
#ifndef FRONTEND
elog(LOG, "could not unlink \"%s\", continuing to try",
path);
#else
fprintf(stderr, "could not unlink \"%s\", continuing to try\n",
path);
#endif
loops++;
}
if (loops > 30)
#ifndef FRONTEND
elog(LOG, "completed unlink of \"%s\"", path);
#else
fprintf(stderr, "completed unlink of \"%s\"\n", path);
#endif
return 0;
}
示例8: WaitExceedsMaxStandbyDelay
/*
* Standby wait logic for ResolveRecoveryConflictWithVirtualXIDs.
* We wait here for a while then return. If we decide we can't wait any
* more then we return true, if we can wait some more return false.
*/
static bool
WaitExceedsMaxStandbyDelay(void)
{
TimestampTz ltime;
/* Are we past the limit time? */
ltime = GetStandbyLimitTime();
if (ltime && GetCurrentTimestamp() >= ltime)
return true;
/*
* Sleep a bit (this is essential to avoid busy-waiting).
*/
pg_usleep(standbyWait_us);
/*
* Progressively increase the sleep times, but not to more than 1s, since
* pg_usleep isn't interruptable on some platforms.
*/
standbyWait_us *= 2;
if (standbyWait_us > 1000000)
standbyWait_us = 1000000;
return false;
}
示例9: RestoreWALFileForRecovery
/*
* RestoreWALFileForRecovery()
*
* Perform the action required to restore the file from archive
*/
static bool
RestoreWALFileForRecovery(void)
{
int rc = 0;
int numretries = 0;
if (debug)
{
fprintf(stderr, "running restore: ");
fflush(stderr);
}
while (numretries <= maxretries)
{
rc = system(restoreCommand);
if (rc == 0)
{
if (debug)
{
fprintf(stderr, "OK\n");
fflush(stderr);
}
return true;
}
pg_usleep(numretries++ * sleeptime * 1000000L);
}
/*
* Allow caller to add additional info
*/
if (debug)
fprintf(stderr, "not restored\n");
return false;
}
示例10: ResolveRecoveryConflictWithDatabase
void
ResolveRecoveryConflictWithDatabase(Oid dbid)
{
/*
* We don't do ResolveRecoveryConflictWithVirtualXIDs() here since that
* only waits for transactions and completely idle sessions would block
* us. This is rare enough that we do this as simply as possible: no wait,
* just force them off immediately.
*
* No locking is required here because we already acquired
* AccessExclusiveLock. Anybody trying to connect while we do this will
* block during InitPostgres() and then disconnect when they see the
* database has been removed.
*/
while (CountDBBackends(dbid) > 0)
{
CancelDBBackends(dbid, PROCSIG_RECOVERY_CONFLICT_DATABASE, true);
/*
* Wait awhile for them to die so that we avoid flooding an
* unresponsive backend when system is heavily loaded.
*/
pg_usleep(10000);
}
}
示例11: ForgetRelationFsyncRequests
/*
* ForgetRelationFsyncRequests -- ensure any fsyncs for a rel are forgotten
*/
void
ForgetRelationFsyncRequests(RelFileNode rnode)
{
if (pendingOpsTable)
{
/* standalone backend or startup process: fsync state is local */
RememberFsyncRequest(rnode, FORGET_RELATION_FSYNC);
}
else if (IsUnderPostmaster)
{
/*
* Notify the bgwriter about it. If we fail to queue the revoke
* message, we have to sleep and try again ... ugly, but hopefully
* won't happen often.
*
* XXX should we CHECK_FOR_INTERRUPTS in this loop? Escaping with
* an error would leave the no-longer-used file still present on
* disk, which would be bad, so I'm inclined to assume that the
* bgwriter will always empty the queue soon.
*/
while (!ForwardFsyncRequest(rnode, FORGET_RELATION_FSYNC))
pg_usleep(10000L); /* 10 msec seems a good number */
/*
* Note we don't wait for the bgwriter to actually absorb the
* revoke message; see mdsync() for the implications.
*/
}
}
示例12: FileRepPrimary_RunResyncWorker
/*
* FileRepPrimary_RunResyncWorker()
*
*/
static int
FileRepPrimary_RunResyncWorker(void)
{
int status = STATUS_OK;
FileRepResyncHashEntry_s *entry = NULL;
ChangeTrackingRequest *request = NULL;
FileRep_InsertConfigLogEntry("run resync worker");
while (1) {
FileRepSubProcess_ProcessSignals();
if (! (FileRepSubProcess_GetState() == FileRepStateReady &&
dataState == DataStateInResync))
{
break;
}
entry = FileRepPrimary_GetResyncEntry(&request);
if (entry == NULL && request == NULL) {
pg_usleep(100000L); /* 100 ms */
continue;
}
Assert(! (entry != NULL && request != NULL));
if (entry != NULL)
{
status = FileRepPrimary_ResyncWrite(entry);
if (status == STATUS_OK)
{
if (entry->mirrorBufpoolResyncChangedPageCount == 0)
{
entry->mirrorBufpoolResyncChangedPageCount = (entry->mirrorAppendOnlyNewEof - entry->mirrorAppendOnlyLossEof) / BLCKSZ;
}
status = FileRepResync_UpdateEntry(entry);
}
}
if (request != NULL)
{
status = FileRepPrimary_ResyncBufferPoolIncrementalWrite(request);
request = NULL;
}
if (status != STATUS_OK)
{
break;
}
}
return status;
}
示例13: FileRead
int
FileRead(File file, char *buffer, int amount)
{
int returnCode;
Assert(FileIsValid(file));
DO_DB(elog(LOG, "FileRead: %d (%s) " INT64_FORMAT " %d %p",
file, VfdCache[file].fileName,
VfdCache[file].seekPos, amount, buffer));
if (Debug_filerep_print)
(elog(LOG, "FileRead: %d (%s) " INT64_FORMAT " %d %p",
file, VfdCache[file].fileName,
VfdCache[file].seekPos, amount, buffer));
returnCode = FileAccess(file);
if (returnCode < 0)
return returnCode;
retry:
returnCode = read(VfdCache[file].fd, buffer, amount);
if (returnCode >= 0)
VfdCache[file].seekPos += returnCode;
else
{
/*
* Windows may run out of kernel buffers and return "Insufficient
* system resources" error. Wait a bit and retry to solve it.
*
* It is rumored that EINTR is also possible on some Unix filesystems,
* in which case immediate retry is indicated.
*/
#ifdef WIN32
DWORD error = GetLastError();
switch (error)
{
case ERROR_NO_SYSTEM_RESOURCES:
pg_usleep(1000L);
errno = EINTR;
break;
default:
_dosmaperr(error);
break;
}
#endif
/* OK to retry if interrupted */
if (errno == EINTR)
goto retry;
/* Trouble, so assume we don't know the file position anymore */
VfdCache[file].seekPos = FileUnknownPos;
}
return returnCode;
}
示例14: LWLockTryLockWaiting
static void
LWLockTryLockWaiting(
PGPROC *proc,
LWLockId lockid,
LWLockMode mode)
{
volatile LWLock *lock = &(LWLockArray[lockid].lock);
int milliseconds = 0;
int exclusivePid;
while(true)
{
pg_usleep(5000L);
if (PGSemaphoreTryLock(&proc->sem))
{
if (milliseconds >= 750)
elog(LOG, "Done waiting on lockid %d", lockid);
return;
}
milliseconds += 5;
if (milliseconds == 750)
{
int l;
int count = 0;
char buffer[200];
SpinLockAcquire(&lock->mutex);
if (lock->exclusive > 0)
exclusivePid = lock->exclusivePid;
else
exclusivePid = 0;
SpinLockRelease(&lock->mutex);
memcpy(buffer, "none", 5);
for (l = 0; l < num_held_lwlocks; l++)
{
if (l == 0)
count += sprintf(&buffer[count],"(");
else
count += sprintf(&buffer[count],", ");
count += sprintf(&buffer[count],
"lockid %d",
held_lwlocks[l]);
}
if (num_held_lwlocks > 0)
count += sprintf(&buffer[count],")");
elog(LOG, "Waited .75 seconds on lockid %d with no success. Exclusive pid %d. Already held: %s",
lockid, exclusivePid, buffer);
}
}
}
示例15: FileRepPrimary_StartResyncWorker
/*
* FileRepPrimary_StartResyncWorker()
*/
void
FileRepPrimary_StartResyncWorker(void)
{
int status = STATUS_OK;
FileRep_InsertConfigLogEntry("start resync worker");
Insist(fileRepRole == FileRepPrimaryRole);
while (1) {
if (status != STATUS_OK)
{
FileRep_SetSegmentState(SegmentStateFault, FaultTypeMirror);
FileRepSubProcess_SetState(FileRepStateFault);
}
/*
* We are waiting for following conditions to move forward:
*
* Database is running
* And
* if dataState is InResync, we wait for FileRepSubProcess to Ready state
* else don't wait
*/
while (!isDatabaseRunning() ||
!(dataState == DataStateInResync ? FileRepSubProcess_GetState() == FileRepStateReady : true))
{
FileRepSubProcess_ProcessSignals();
if (FileRepSubProcess_GetState() == FileRepStateShutdown ||
FileRepSubProcess_GetState() == FileRepStateShutdownBackends)
{
break;
}
pg_usleep(50000L); /* 50 ms */
}
if (FileRepSubProcess_GetState() == FileRepStateShutdown ||
FileRepSubProcess_GetState() == FileRepStateShutdownBackends) {
break;
}
FileRepSubProcess_InitHeapAccess();
status = FileRepPrimary_RunResyncWorker();
if (status != STATUS_OK) {
continue;
}
break;
} // while(1)
}