char *osi_LogSaveString(osi_log_t *logp, char *s) { char *saveplace; if (!logp) return s; if (!logp->enabled) return s; if (s == NULL) return NULL; thrd_EnterCrit(&logp->cs); saveplace = logp->stringsp[logp->stringindex]; if (strlen(s) >= OSI_LOG_STRINGSIZE) StringCbPrintfA(saveplace, OSI_LOG_STRINGSIZE, "...%s", s + strlen(s) - (OSI_LOG_STRINGSIZE - 4)); else StringCbCopyA(saveplace, OSI_LOG_STRINGSIZE, s); logp->stringindex++; if (logp->stringindex >= logp->maxstringindex) logp->stringindex = 0; thrd_LeaveCrit(&logp->cs); return saveplace; }
wchar_t *osi_LogSaveStringW(osi_log_t *logp, wchar_t *s) { wchar_t *saveplace; if (!logp) return s; if (!logp->enabled) return s; if (s == NULL) return NULL; thrd_EnterCrit(&logp->cs); saveplace = (wchar_t *) (logp->stringsp[logp->stringindex]); if (wcslen(s)*sizeof(wchar_t) >= OSI_LOG_STRINGSIZE) StringCbPrintfW(saveplace, OSI_LOG_STRINGSIZE, L"...%s", (s + wcslen(s) - (OSI_LOG_STRINGSIZE/sizeof(wchar_t) - 4))); else StringCbCopyW(saveplace, OSI_LOG_STRINGSIZE, s); logp->stringindex++; if (logp->stringindex >= logp->maxstringindex) logp->stringindex = 0; thrd_LeaveCrit(&logp->cs); return saveplace; }
void osi_LogPrint(osi_log_t *logp, FILE_HANDLE handle) { char wholemsg[1024], msg[1000]; int i, ix, ioCount; osi_logEntry_t *lep; if (!logp->enabled) return; thrd_EnterCrit(&logp->cs); for (ix = logp->first, i = 0; i < logp->nused; i++, ix++, (ix >= logp->alloc ? ix -= logp->alloc : 0)) { lep = logp->datap + ix; /* pointer arithmetic */ StringCbPrintfA(msg, sizeof(msg), lep->formatp, lep->parms[0], lep->parms[1], lep->parms[2], lep->parms[3], lep->parms[4]); StringCbPrintfA(wholemsg, sizeof(wholemsg), "time %d.%06d, tid %d %s\r\n", lep->micros / 1000000, lep->micros % 1000000, lep->tid, msg); if (!WriteFile(handle, wholemsg, strlen(wholemsg), &ioCount, NULL)) break; } thrd_LeaveCrit(&logp->cs); }
osi_queueData_t *osi_QDAlloc(void) { osi_queueData_t *tp; int i; thrd_EnterCrit(&osi_qdcrit); if (tp = osi_QDFreeListp) { osi_QDFreeListp = (osi_queueData_t *) tp->q.nextp; } else { /* need to allocate a block more */ tp = (osi_queueData_t *) malloc(OSI_NQDALLOC * sizeof(osi_queueData_t)); /* leave last guy off of the free list; this is the one we'll * return. */ for(i=0; i<OSI_NQDALLOC-1; i++, tp++) { tp->q.nextp = (osi_queue_t *) osi_QDFreeListp; tp->datap = NULL; osi_QDFreeListp = tp; } /* when we get here, tp is pointing to the last dude allocated. * This guy wasn't put on the free list, so we can return him now. */ tp->datap = NULL; } thrd_LeaveCrit(&osi_qdcrit); osi_assertx(tp->datap == NULL, "queue freelist screwup"); return tp; }
/* reset the contents of a log */ void osi_LogReset(osi_log_t *logp) { if (logp) { thrd_EnterCrit(&logp->cs); logp->nused = 0; thrd_LeaveCrit(&logp->cs); } }
void osi_QDFree(osi_queueData_t *qp) { thrd_EnterCrit(&osi_qdcrit); qp->q.nextp = (osi_queue_t *) osi_QDFreeListp; qp->datap = NULL; osi_QDFreeListp = qp; thrd_LeaveCrit(&osi_qdcrit); }
/* add an element to a log */ void osi_LogAdd(osi_log_t *logp, char *formatp, size_t p0, size_t p1, size_t p2, size_t p3, size_t p4) { osi_logEntry_t *lep; long ix; LARGE_INTEGER bigTime; /* handle init races */ if (!logp) return; /* do this w/o locking for speed; it is obviously harmless if we're off * by a bit. */ if (!logp->enabled) return; thrd_EnterCrit(&logp->cs); if (logp->nused < logp->alloc) logp->nused++; else { logp->first++; if (logp->first >= logp->alloc) logp->first -= logp->alloc; } ix = logp->first + logp->nused - 1; if (ix >= logp->alloc) ix -= logp->alloc; lep = logp->datap + ix; /* ptr arith */ lep->tid = thrd_Current(); /* get the time, using the high res timer if available */ if (osi_logFreq) { QueryPerformanceCounter(&bigTime); lep->micros = (bigTime.LowPart / osi_logFreq) * osi_logTixToMicros; } else lep->micros = GetCurrentTime() * 1000; lep->formatp = formatp; lep->parms[0] = p0; lep->parms[1] = p1; lep->parms[2] = p2; lep->parms[3] = p3; lep->parms[4] = p4; #ifdef NOTSERVICE printf( "%9ld:", lep->micros ); printf( formatp, p0, p1, p2, p3, p4); printf( "\n" ); #endif if(ISCLIENTDEBUGLOG(osi_TraceOption)) { char wholemsg[1024], msg[1000]; StringCbPrintfA(msg, sizeof(msg), formatp, p0, p1, p2, p3, p4); StringCbPrintfA(wholemsg, sizeof(wholemsg), "tid[%d] %s\n", lep->tid, msg); OutputDebugStringA(wholemsg); } thrd_LeaveCrit(&logp->cs); }
long osi_LogFDCreate(osi_fdType_t *typep, osi_fd_t **outpp) { osi_logFD_t *lfdp; osi_log_t *logp; lfdp = malloc(sizeof(*lfdp)); logp = lfdp->logp = typep->rockp; /* the log we were created for */ thrd_EnterCrit(&logp->cs); lfdp->nused = logp->nused; lfdp->first = logp->first; lfdp->current = 0; thrd_LeaveCrit(&logp->cs); *outpp = &lfdp->fd; return 0; }
long osi_LogFDGetInfo(osi_fd_t *ifd, osi_remGetInfoParms_t *outp) { osi_logFD_t *lfdp; osi_log_t *logp; osi_logEntry_t *lep; char tbuffer[256]; long ix; lfdp = (osi_logFD_t *) ifd; logp = lfdp->logp; /* see if we're done */ if (lfdp->current >= lfdp->nused) return OSI_DBRPC_EOF; /* grab lock */ thrd_EnterCrit(&logp->cs); /* compute which one we want */ ix = lfdp->first + lfdp->current; if (ix >= logp->alloc) ix -= logp->alloc; lfdp->current++; lep = logp->datap + ix; /* ptr arith to current index */ StringCbPrintfA(tbuffer, sizeof(tbuffer), lep->formatp, lep->parms[0], lep->parms[1], lep->parms[2], lep->parms[3], lep->parms[4]); /* now copy out info */ StringCbCopyA(outp->sdata[0], sizeof(outp->sdata[0]), tbuffer); StringCbPrintfA(tbuffer, sizeof(tbuffer), "%5.6f", ((double)lep->micros)/1000000.0); StringCbCopyA(outp->sdata[1], sizeof(outp->sdata[0]), tbuffer); outp->idata[0] = lep->tid; outp->scount = 2; outp->icount = 1; thrd_LeaveCrit(&logp->cs); return 0; }