Ejemplo n.º 1
0
OSBLOG_API VXIlogResult OSBlogFlush(VXIlogInterface* pThis,
                                    const char   *logFileName,
                                    VXIbool       logToStdout)
{
    // Lock and write out the log entry
    if (VXItrdMutexLock(gblLogMutex) != VXItrd_RESULT_SUCCESS)
        return VXIlog_RESULT_SYSTEM_ERROR;

    // Close the log file
    if (gblInitialized && gblLogFile) {
        fflush(gblLogFile);
        fclose(gblLogFile);
    }

    // Open the log file
    if ((logFileName) && (logFileName[0])) {
        gblLogFile = fopen(logFileName, "a");
        if (! gblLogFile)
            return VXIlog_RESULT_IO_ERROR;
    }

    gblLogToStdout = (logToStdout ? true : false);

    if (VXItrdMutexUnlock(gblLogMutex) != VXItrd_RESULT_SUCCESS)
        return VXIlog_RESULT_SYSTEM_ERROR;

    return VXIlog_RESULT_SUCCESS;
}
Ejemplo n.º 2
0
/**
 * Destroy a thread handle
 *
 * Note: this does NOT stop or destroy the thread, it just releases
 * the handle for accessing it. If this is not done, a memory leak
 * occurs, so if the creator of the thread never needs to communicate
 * with the thread again it should call this immediately after the
 * create if the create was successful.
 *
 * @param  thread  Handle to the thread to destroy
 *
 * @result VXItrdResult 0 on success 
 */
VXITRD_API VXItrdResult VXItrdThreadDestroyHandle(VXItrdThread **thread)
{
  if ((thread == NULL) || (*thread == NULL))
    return VXItrd_RESULT_INVALID_ARGUMENT;

  // Decrement ref count
  VXIulong refs = 0;
  if ((*thread)->refCountMutex) {
    VXItrdMutexLock ((*thread)->refCountMutex);
    (*thread)->refCount--;
    refs = (*thread)->refCount;
    VXItrdMutexUnlock ((*thread)->refCountMutex);
  }

  if (refs == 0) {
    // No longer needed
    if ((*thread)->refCountMutex)
      VXItrdMutexDestroy (&(*thread)->refCountMutex);
    delete *thread;
  }

  *thread = NULL;

  return VXItrd_RESULT_SUCCESS;
}
Ejemplo n.º 3
0
// Wait on the event
VXItrdResult SBtrdEvent::Wait( ) 
{
  VXItrdResult rc = VXItrd_RESULT_SUCCESS;
  Diag (0, L"SBtrdEvent::Wait", L"enter: this 0x%p", this);

  if (( ! _alerted ) &&
      ( (rc = VXItrdMutexLock (_sleepMutex)) == VXItrd_RESULT_SUCCESS )) {
    while (( ! _alerted ) && 
	   ( (rc = VXItrdTimerSleep (_timer, INT_MAX, NULL)) ==
	     VXItrd_RESULT_SUCCESS )) {
      // keep waiting
      Diag (0, L"SBtrdEvent::Wait", L"woke up: %d", _alerted);
    }
    
    if ( VXItrdMutexUnlock (_sleepMutex) != VXItrd_RESULT_SUCCESS )
      rc = VXItrd_RESULT_SYSTEM_ERROR;
  }

  Diag (0, L"SBtrdEvent::Wait", L"exit: %d", rc);
  return rc;
}
Ejemplo n.º 4
0
VXIlogResult OSBlog::WriteEntry(const LogEntry &entry, bool logToStdout)
{
    if (((! gblLogFile) && (! gblLogToStdout)) || (entry.size() < 1))
        return VXIlog_RESULT_SUCCESS;

    // Convert to narrow characters
    unsigned int i;
    unsigned int n = entry.size();
    const wchar_t *ptr = entry.Entry();
    char outbuf[MAX_LOG_BUFFER];
    for(i=0; i<n; i++)
        outbuf[i] = w2c(ptr[i]);
    outbuf[i] = '\0';

    // Lock and write out the log entry
    if (VXItrdMutexLock(gblLogMutex) != VXItrd_RESULT_SUCCESS)
        return VXIlog_RESULT_SYSTEM_ERROR;

    VXIlogResult rc = VXIlog_RESULT_SUCCESS;
    if (gblLogFile) {
        if (fwrite(outbuf, sizeof(char), n, gblLogFile) < 1) {
            // should disable logging.
            rc = VXIlog_RESULT_IO_ERROR;
        } else {
            // to ensure we don't lose log lines on a crash/abort
            fflush(gblLogFile);
        }
    }

    if (gblLogToStdout && logToStdout &&
            (fwrite(outbuf, sizeof(char), n, stdout) < 1 || fflush(stdout) != 0))
        rc = VXIlog_RESULT_IO_ERROR;

    if (VXItrdMutexUnlock(gblLogMutex) != VXItrd_RESULT_SUCCESS)
        rc = VXIlog_RESULT_SYSTEM_ERROR;

    return rc;
}
Ejemplo n.º 5
0
 void Unlock() const
 { if (error) return;
   error = (VXItrdMutexUnlock(mutex) != VXItrd_RESULT_SUCCESS); }