//------------------------------------------------------------------------------ tOplkError eventucal_init(void) { tOplkError ret = kErrorOk; OPLK_MEMSET(&instance_l, 0, sizeof(tEventuCalInstance)); if ((instance_l.semUserData = CreateSemaphore(NULL, 0, 100, "Local\\semUserEvent")) == NULL) goto Exit; if ((instance_l.semKernelData = CreateSemaphore(NULL, 0, 100, "Local\\semKernelEvent")) == NULL) goto Exit; if (eventucal_initQueueCircbuf(kEventQueueK2U) != kErrorOk) goto Exit; if (eventucal_initQueueCircbuf(kEventQueueU2K) != kErrorOk) goto Exit; eventucal_setSignalingCircbuf(kEventQueueU2K, signalKernelEvent); if (eventucal_initQueueCircbuf(kEventQueueUInt) != kErrorOk) goto Exit; eventucal_setSignalingCircbuf(kEventQueueUInt, signalUserEvent); instance_l.fStopThread = FALSE; if ((instance_l.threadHandle = CreateThread(NULL, 0, eventThread, (LPVOID)&instance_l, 0, NULL)) == NULL) { TRACE("%s() CreateThread fails! Error:%ld\n", __func__, GetLastError()); goto Exit; } // jba set thread priority!!! instance_l.fInitialized = TRUE; return kErrorOk; Exit: if (instance_l.semUserData != NULL) CloseHandle(instance_l.semUserData); if (instance_l.semKernelData != NULL) CloseHandle(instance_l.semKernelData); eventucal_exitQueueCircbuf(kEventQueueK2U); eventucal_exitQueueCircbuf(kEventQueueU2K); eventucal_exitQueueCircbuf(kEventQueueUInt); return kErrorNoResource; }
//------------------------------------------------------------------------------ tOplkError eventucal_init(void) { tOplkError ret = kErrorOk; struct sched_param schedParam; OPLK_MEMSET(&instance_l, 0, sizeof(tEventuCalInstance)); instance_l.fd = ctrlucal_getFd(); instance_l.fStopKernelThread = FALSE; instance_l.fStopProcessThread = FALSE; sem_unlink("/semUserEvent"); // Deinitialize any existing instance of the semaphore if ((instance_l.semUserData = sem_open("/semUserEvent", O_CREAT | O_RDWR, S_IRWXG, 0)) == SEM_FAILED) goto Exit; if (eventucal_initQueueCircbuf(kEventQueueUInt) != kErrorOk) goto Exit; if (eventucal_setSignalingCircbuf(kEventQueueUInt, signalUIntEvent) != kErrorOk) goto Exit; // Create thread for fetching new user data from kernel if (pthread_create(&instance_l.kernelEventThreadId, NULL, k2uEventFetchThread, NULL) != 0) goto Exit; schedParam.sched_priority = KERNEL_EVENT_FETCH_THREAD_PRIORITY; if (pthread_setschedparam(instance_l.kernelEventThreadId, SCHED_FIFO, &schedParam) != 0) { DEBUG_LVL_ERROR_TRACE("%s(): couldn't set K2U thread scheduling parameters! %d\n", __func__, schedParam.sched_priority); } #if (defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 12)) pthread_setname_np(instance_l.kernelEventThreadId, "oplk-eventufetch"); #endif // Create thread for processing pending user data if (pthread_create(&instance_l.processEventThreadId, NULL, eventProcessThread, NULL) != 0) goto Exit; schedParam.sched_priority = EVENT_PROCESS_THREAD_PRIORITY; if (pthread_setschedparam(instance_l.processEventThreadId, SCHED_FIFO, &schedParam) != 0) { DEBUG_LVL_ERROR_TRACE("%s(): couldn't set event process thread scheduling parameters! %d\n", __func__, schedParam.sched_priority); } #if (defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 12)) pthread_setname_np(instance_l.processEventThreadId, "oplk-eventuprocess"); #endif instance_l.fInitialized = TRUE; return kErrorOk; Exit: eventucal_exit(); return ret; }