// Creation method VXItrdResult SBtrdEvent::Create( ) { VXItrdResult rc; Diag (0, L"SBtrdEvent::Create", L"enter: this 0x%p", this); if ( _timer != NULL ) { rc = VXItrd_RESULT_FATAL_ERROR; } else { rc = VXItrdTimerCreate (&_timer); if ( rc == VXItrd_RESULT_SUCCESS ) rc = VXItrdMutexCreate (&_sleepMutex); } return rc; }
/** * Global platform initialization of OSBlog * * @param logFileName Name of the file where diagnostic, error, and * event information will be written. Pass NULL * to disable logging to a file. * @param logToStdout TRUE to log diagnostic and error messages to * standard out, FALSE to disable. Event reports * are never logged to standard out. * * @result VXIlogResult 0 on success */ OSBLOG_API VXIlogResult OSBlogInit(const char *logFileName, VXIbool logToStdout) { if (gblInitialized == true) return VXIlog_RESULT_FATAL_ERROR; // Create the log mutex if (VXItrdMutexCreate(&gblLogMutex) != VXItrd_RESULT_SUCCESS) return VXIlog_RESULT_SYSTEM_ERROR; // Open the log file if ((logFileName) && (logFileName[0])) { gblLogFile = fopen(logFileName, "a"); if (! gblLogFile) return VXIlog_RESULT_IO_ERROR; } gblInitialized = true; gblLogToStdout = (logToStdout ? true : false); return VXIlog_RESULT_SUCCESS; }
/** * Create a thread. Note: thread values are not supported on OS/2. * execution starts on the thread immediately. To pause execution * use a Mutex between the thread and the thread creator. * * @param thread the thread object to be created * @param thread_function the function for the thread to start execution on * @param thread_arg the arguments to the thread function * @return VXItrdResult of operation. Return SUCCESS if thread has been * created and started. * */ VXITRD_API VXItrdResult VXItrdThreadCreate(VXItrdThread **thread, VXItrdThreadStartFunc thread_function, VXItrdThreadArg thread_arg) { if ((thread == NULL) || (thread_function == NULL)) return VXItrd_RESULT_INVALID_ARGUMENT; *thread = NULL; // Create the wrapper object VXItrdThread *result = new VXItrdThread; if (result == NULL) return VXItrd_RESULT_OUT_OF_MEMORY; memset(result, 0, sizeof (VXItrdThread)); result->state = STATE_STARTING; result->refCount = 1; // 1 for parent result->thread_function = thread_function; result->thread_arg = thread_arg; if (VXItrdMutexCreate(&result->refCountMutex) != VXItrd_RESULT_SUCCESS) { VXItrdThreadDestroyHandle(&result); return VXItrd_RESULT_SYSTEM_ERROR; } // construct thread attribute pthread_attr_t thread_attr; int prc = pthread_attr_init(&thread_attr); if (prc != 0) { VXItrdThreadDestroyHandle(&result); return VXItrd_RESULT_NON_FATAL_ERROR; } // configure thread attribute #ifdef USE_DETACHED_THREADS prc = pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); if (prc != 0) { pthread_attr_destroy(&thread_attr); VXItrdThreadDestroyHandle(&result); return VXItrd_RESULT_NON_FATAL_ERROR; } #else // use joinable threads // this is default - no work required #endif // Instead of using the default 2M as stack size, reduce it to 1M size_t stacksize = 0; prc = pthread_attr_getstacksize(&thread_attr, &stacksize); if (prc == 0) { prc = pthread_attr_setstacksize(&thread_attr, SIPXCHANGE_STACK_SIZE_128K); } // Start the thread using our wrapper function result->refCount++; // for child prc = pthread_create(&result->thread, &thread_attr, VXItrdThreadStart, (VXItrdThreadArg) result); pthread_attr_destroy(&thread_attr); if (prc != 0) { result->refCount--; VXItrdThreadDestroyHandle(&result); return VXItrd_RESULT_NON_FATAL_ERROR; } *thread = result; return VXItrd_RESULT_SUCCESS; }
OSBlog::OSBlog(VXIint chNum) : channelNum(chNum) { // reset TAG ID range memset(TagIDs,0,LOG_MAX_TAG); VXItrdMutexCreate(&callbackLock); }
InternalMutex() : mutex(NULL) { error = (VXItrdMutexCreate(&mutex) != VXItrd_RESULT_SUCCESS); }