/* * Function: SerialOpen(unsigned int uiBaudrate) * Description: * - Open the serial port with the port name is given by typing * - Giving input and output queue for data read and write * Input: * - uiBaudrate: Baudrate of the port. * Return: * - pointer to serial management data struct. */ PSERIAL SerialOpen(char* PortName, unsigned int uiBaudrate) { struct termios stSerialIo; PSERIAL pSerialPort = (PSERIAL)malloc(sizeof(SERIAL)); pSerialPort->tty_fd = -1; /* Configure the port */ memset(&stSerialIo, 0, sizeof(stSerialIo)); stSerialIo.c_iflag = 0; // raw input stSerialIo.c_oflag = 0; // raw output stSerialIo.c_cflag = 0; stSerialIo.c_lflag = 0; stSerialIo.c_cc[VMIN] = 1; stSerialIo.c_cc[VTIME] = 0; /* configure control flag * CS8: 8bit, 1 bit stop, no parity */ stSerialIo.c_cflag = uiBaudrate | CS8 | CREAD | CLOCAL; /* open port */ pSerialPort->tty_fd = open(PortName, O_RDWR | O_NOCTTY); if (pSerialPort->tty_fd < 0) { return NULL; } /* set configuration to be activated */ cfsetospeed(&stSerialIo, uiBaudrate); cfsetispeed(&stSerialIo, uiBaudrate); tcsetattr(pSerialPort->tty_fd, TCSANOW, &stSerialIo); g_nPackageIndex = 0; /* initialize queue for communication */ pSerialPort->pInputQueue = QueueCreate(SERIAL_QUEUE_SIZE, MAX_SERIAL_PACKAGE_SIZE); pSerialPort->pOutputQueue = QueueCreate(SERIAL_QUEUE_SIZE, MAX_SERIAL_PACKAGE_SIZE); pSerialPort->uiBaudrate = uiBaudrate; return pSerialPort; }
PCCore* PCCoreCreate() { PCCore* pPCCore = NULL; pPCCore = (PCCore*)AMMalloc(sizeof(PCCore)); memset(pPCCore, 0, sizeof(PCCore)); if(pPCCore) { QueueCreate(&pPCCore->pReaderQueue); QueueCreate(&pPCCore->pSenderQueue); QueueCreate(&pPCCore->pCallbackQueue); } return pPCCore; }
static void *calendar_manager_thread_entry(void *param) { UNUSED(param); mqd_hdl mq; memset(input_buffer, '\0', MAX_MSG_QUEUE_SIZE+1); memset(answer_buffer, '\0', MAX_MSG_QUEUE_SIZE+1); if(FAILURE == QueueCreate(&mq, QUEUE_NAME, MAX_MSG_QUEUE_SIZE, MAX_MSG_QUEUE_NUM)) { calendar_quit(); } while(!calendar_exit) { if(FAILURE == QueueReceive(&mq, input_buffer, MODE_BLOCK)) { calendar_quit(); } CALENDER_DEBUG("Success to receive message : [ %s ] from user input process thread.", input_buffer); process_input_string(input_buffer, answer_buffer); if(FAILURE == QueueSend(&mq, answer_buffer, MODE_BLOCK)) { calendar_quit(); } CALENDER_DEBUG("Success to Answer message to user input process thread."); memset(answer_buffer, '\0', strlen(answer_buffer)); } QueueDelete(&mq, QUEUE_NAME); }
void queue_app_test(void) { unsigned int iloop = 0; int data = 0; SqQueue sq; QueueCreate(&sq); for(iloop=0; iloop < 16; iloop++) { #ifdef USE_LINE_QUEUE QueueEnterL(&sq, iloop*8); #else //USE_CIRCLE_QUEUE QueueEnterC(&sq, iloop*8); #endif printf("queue get valid data len is %d \n", QueueGetTag(&sq)); //队列长度 } #ifdef USE_LINE_QUEUE while(QueueDeleteL(&sq, &data) != -1) #else //USE_CIRCLE_QUEUE while(QueueDeleteC(&sq, &data) != -1) #endif { printf("queue get data value is %d \n", data); printf("queue get remain data len is %d \n", QueueGetTag(&sq)); } QueueDestroy(&sq); return; }
/********************************************************************************************************* ** 函数名称: UART0Init ** 功能描述: 初始化UART0 ** 输 入: bps:波特率 ** ** 输 出:TRUE :成功 ** FALSE:失败 ** 全局变量: Uart0Sem ** 调用模块: QueueCreate,OSSemCreate ** ** 作 者: 陈明计 ** 日 期: 2003年7月4日 **------------------------------------------------------------------------------------------------------- ** 修改人: 陈明计 ** 日 期: 2003年7月8日 **------------------------------------------------------------------------------------------------------- ** 修改人: 陈明计 ** 日 期: 2003年7月21日 **------------------------------------------------------------------------------------------------------ ********************************************************************************************************/ uint8 UART1Init(uint32 bps) { uint16 Fdiv; PINSEL0 = (PINSEL0 & 0xfff0ffff) | (0x05 << 16); /* 选择管脚为UART1 */ U1LCR = 0x80; /* 允许访问分频因子寄存器 */ Fdiv = (Fpclk / 16) / bps; /* 设置波特率 */ U1DLM = Fdiv / 256; U1DLL = Fdiv % 256; U1LCR = 0x03; /* 禁止访问分频因子寄存器 */ /* 且设置为8,1,n */ U1IER = 0x05; /* 允许接收和发送中断 */ U1FCR = 0x87; /* 初始化FIFO */ if (QueueCreate((void *)UART1SendBuf, sizeof(UART1SendBuf), NULL, (uint8 (*)())Uart1WriteFull) == NOT_OK) { return FALSE; } Uart1Sem = OSSemCreate(0); if (Uart1Sem != NULL) { return TRUE; } else { return FALSE; } }
VOID QueueHashAddToSubqueue(Queue *pHashQueue, PSID pSID, VOID * pData) { ASSERT(pHashQueue != NULL); if (pHashQueue->lpCriticalSection != NULL) EnterCriticalSection(pHashQueue->lpCriticalSection); #ifdef DEBUG2 DbgMsgRecord(TEXT("-> QueueHashAddToSubqueue\n")); #endif // Put the request onto the appropriate queue. // Lookup the subqueue for the user's sid. Queue * pQueue = (Queue *) QueueHashLookup(pHashQueue, pSID, FALSE); // If the subqueue does not exist, create it. if (pQueue == NULL) { if ((pQueue = QueueCreate(TRUE)) == NULL) { AddToMessageLog(TEXT("QueueHashAddToSubqueue: QueueCreate failed")); if (pHashQueue->lpCriticalSection != NULL) LeaveCriticalSection(pHashQueue->lpCriticalSection); return; } QueueHashAdd(pHashQueue, pSID, pQueue, FALSE); } // Add the request to the subqueue QueueAdd(pQueue, pData, FALSE); #ifdef DEBUG2 DbgMsgRecord(TEXT("<- QueueHashAddToSubqueue\n")); #endif if (pHashQueue->lpCriticalSection != NULL) LeaveCriticalSection(pHashQueue->lpCriticalSection); }
SafeQueue* SafeQueueInit(size_t _size) { SafeQueue* safeQ = NULL; /* creating safe queue */ safeQ = malloc (sizeof(SafeQueue)); if (NULL == safeQ) { return NULL; } safeQ->m_queue = QueueCreate(_size); if (NULL == safeQ->m_queue) { return NULL; } /* initializing its semahores and mutex */ pthread_mutex_init(&safeQ->m_mutex, NULL); /* initially an empty queue, so full ability exists to insert all messages up to size */ if (ERR_OK != SemCreate(&safeQ->m_prodSem, _size)) { return NULL; } /* initially an empty queue, so consumer can't yet consume */ if (ERR_OK != SemCreate(&safeQ->m_consSem, 0)) { return NULL; } return safeQ; }
unsigned int ABPEvenCount (PtABPNode proot) { PtABPNode node = proot; PtQueue queue; unsigned int count = 0; if (proot == NULL) { Error = ABP_EMPTY; return -1; } if ((queue = QueueCreate(sizeof(PtABPNode))) == NULL) { Error = NO_MEM; return -1; } QueueEnqueue(queue, &node); while (!QueueIsEmpty(queue)) { QueueDequeue(queue, &node); if (!(node->Elem & 1)) count++; if (node->PtLeft != NULL) QueueEnqueue(queue, &(node->PtLeft)); if (node->PtRight != NULL) QueueEnqueue(queue, &(node->PtRight)); } QueueDestroy(&queue); Error = OK; return count; }
void I2cInit() { state = STATE_IDLE; result_queue = QueueCreate(1, sizeof(bool)); _MI2C1IP = configKERNEL_INTERRUPT_PRIORITY; _MI2C2IP = configKERNEL_INTERRUPT_PRIORITY + 1; I2C2BRG = 165; I2C2CONbits.I2CEN = 1; // Enable. }
int main(int argc, char *argv[]) { void *p = NULL; long msg = 0; void *pMsg = NULL; p = QueueCreate(10); if (NULL == p) { printf("Create queue failed.\n"); return -1; } msg = 90; while (msg--) { if (QueuePush(p, (void *)msg) < 0) { printf("----------Queue is full now-----------\n"); break; } printf("Push ok. [msg: %ld, size: %d]\n", msg, QueueGetSize(p)); } msg = 15; while (msg--) { if (QueuePopPush(p, (void *)msg, &pMsg) < 0) { printf("----------QueuePopPush failed-----------\n"); break; } printf("PopPush ok. [msgPop: %ld, msgPush: %ld, size: %d]\n", (long)pMsg, msg, QueueGetSize(p)); } msg = 60; while (msg--) { if (QueuePop(p, &pMsg) < 0) { printf("----------Queue is empty now-----------\n"); break; } printf("Pop ok. [msg: %ld, size: %d]\n", (long)pMsg, QueueGetSize(p)); } QueueDestroy(p); system("pause"); return 0; }
void serverStart( IRCServer_t *server ) { server->newServer = FALSE; server->txQueue = QueueCreate( 1024 ); thread_create( &server->txThreadId, transmit_thread, (void *)server, server->txThreadName, NULL ); server->callbacks.sighupFunc = botSighup; server->callbacks.sighupArg = (void *)server; thread_create( &server->threadId, bot_server_thread, (void *)server, server->threadName, &server->callbacks ); }
int CTAsyncWorkQueue::Start(int v_threadsNum, int v_runQSize, int v_endQSize) { m_pRunQ = QueueCreate(v_runQSize); if (NULL == m_pRunQ) { return -1; } m_pEndQ = QueueCreate(v_endQSize); if (NULL == m_pEndQ) { return -1; } m_pThreadsGroup = ThreadsGroupCreate(v_threadsNum, ThreadWork, this); if (NULL == m_pThreadsGroup) { return -1; } return 0; }
void enet_slirp_start(void) { struct in_addr guest_addr; if (!slirp_inited) { Log_Printf(LOG_WARN, "Starting SLIRP"); #ifndef _WIN32 signal(SIGPIPE, SIG_IGN); #endif slirp_init(); slirpq = QueueCreate(); slirp_inited=1; //host_sleep_ms(500); slirp_mutex=SDL_CreateMutex(); tick_func_handle=SDL_CreateThread(tick_func,"SLiRPTickThread", (void *)NULL); inet_aton("10.0.2.15", &guest_addr); slirp_redir(0, 42323, guest_addr, 23); } }
int main() { inbound_queue = QueueCreate(sizeof(char), 20) ; ClearScreen(0x07) ; SetCursorVisible(TRUE) ; InitSerial() ; InitOutBound() ; InitInBound() ; for (;;) { OutBound() ; InBound() ; } return 0 ; }
void logging_initialize( bool ncurses ) { LoggingQ = QueueCreate(1024); LogList = LinkedListCreate(); if( !ncurses ) { LogStdoutAdd(); } else { LogNcursesAdd(); } LogSyslogAdd( LOG_LOCAL7 ); if( Debug ) { LogFileAdd( DEBUG_FILE ); } thread_create( &loggingThreadId, LoggingThread, NULL, "thread_logging", NULL ); }
// Поиск в ширину (FIFO) int TreeSearch(){ int i,j; node *n = NodeCreate(start_i,start_j,NULL,0,NOTHING); array arr; queue *h = QueueCreate(); QueueAdd(h,n); while(!QueueIsEmpty(h)){ n = QueueGet(h); if(NodeIsFinish(n)){ while(n->parent != NULL){ NodePrint(n); field[n->state[0]][n->state[1]] = USED; n = n->parent; } field[n->state[0]][n->state[1]] = USED; printf("\nКарта пути:\n"); printf("\"X\" - Препятствие\n"); printf("\".\" - Свободная ячейка\n"); printf("\"*\" - Путь робота\n\n"); for(i = 0; i<SIZE; i++){ for(j = 0; j<SIZE; j++){ if(field[i][j] == FREE)printf("."); if(field[i][j] == OBSTACLE)printf("X"); if(field[i][j] == USED)printf("*"); } printf("\n"); } free(h); return 0; } //если решение еще не нашлось, то заново записываем переферию arr = Expand(n); for(i = 0; i < arr.size; i++){ QueueAdd(h, arr.arr[i]); } } printf("Can't find solution\n"); free(h); return 0; }
BOOL QueuesCreate(Queue *Queues[], UINT n, BOOL NoCritSec) { BOOL ret = FALSE; #ifdef DEBUG2 DbgMsgRecord(TEXT("-> QueuesCreate\n")); #endif for (UINT i=0; i<n; i++) { if ((Queues[i] = QueueCreate(NoCritSec)) == NULL) { QueuesDelete(Queues, i-1); ret = FALSE; break; } } ret = TRUE; #ifdef DEBUG2 DbgMsgRecord(TEXT("<- QueuesCreate\n")); #endif return ret; }
void ABPByLevel (PtABPNode proot) /* travessia por niveis - traversal by levels */ { PtABPNode Node = proot; PtQueue Queue; if (proot == NULL) { Error = ABP_EMPTY; return; } /* arvore vazia - empty tree */ if ((Queue = QueueCreate (sizeof (PtABPNode))) == NULL) { Error = NO_MEM ; return; } QueueEnqueue (Queue, &Node); /* armazenar a raiz - storing the root */ while (!QueueIsEmpty (Queue)) { QueueDequeue (Queue, &Node); /* retirar o no - retrieve the node */ printf ("%d ", Node->Elem); /* imprimir o elemento - printing the element */ /* armazenar a raiz da subarvore esquerda - storing the left subtree root */ if (Node->PtLeft != NULL) QueueEnqueue (Queue, &Node->PtLeft); /* armazenar a raiz da subarvore direita - storing the right subtree root */ if (Node->PtRight != NULL) QueueEnqueue (Queue, &Node->PtRight); } QueueDestroy (&Queue); /* destruir a fila - releasing the queue */ Error = OK; }
void StartThreads( void ) { pthread_mutex_t spinLockMutex; pid_t childPid; struct sigaction sa; sigset_t sigmsk; size_t len; ThreadCallback_t callbacks; GlobalAbort = FALSE; #ifndef __CYGWIN__ len = confstr( _CS_GNU_LIBPTHREAD_VERSION, NULL, 0 ); if( len ) { pthreadsVersion = CREATEN(char, len); confstr( _CS_GNU_LIBPTHREAD_VERSION, pthreadsVersion, len ); } #else (void)len; pthreadsVersion = memstrlink( "Cygwin" ); #endif if( !pthreadsVersion || strstr( pthreadsVersion, "linuxthreads" ) ) { fprintf( stderr, "havokmud requires NPTL to operate correctly.\n\n" "The signal handling in linuxthreads is just too " "broken to use.\n\n" ); exit( 1 ); } /* Do we need to detach? */ if( Daemon ) { childPid = fork(); if( childPid < 0 ) { perror( "Couldn't detach in daemon mode" ); _exit( 1 ); } if( childPid != 0 ) { /* This is still the parent, report the child's pid and exit */ printf( "[Detached as PID %d]\n", childPid ); /* And exit the parent */ _exit( 0 ); } /* After this is in the detached child */ /* Close stdin, stdout, stderr to release the tty */ close(0); close(1); close(2); } LoggingQ = QueueCreate( 1024 ); ConnectInputQ = QueueCreate( 256 ); ConnectDnsQ = QueueCreate( 64 ); InputLoginQ = QueueCreate( 256 ); InputEditorQ = QueueCreate( 256 ); InputPlayerQ = QueueCreate( 256 ); InputImmortQ = QueueCreate( 256 ); MailQ = QueueCreate( 128 ); QueryQ = QueueCreate( 1024 ); ProtobufQ = QueueCreate( 1024 ); mainThreadId = pthread_self(); /* * Setup the sigmasks for this thread (which is the parent to all others). * This will propogate to all children. */ sigfillset( &sigmsk ); sigdelset( &sigmsk, SIGUSR1 ); sigdelset( &sigmsk, SIGUSR2 ); sigdelset( &sigmsk, SIGHUP ); sigdelset( &sigmsk, SIGWINCH ); sigdelset( &sigmsk, SIGINT ); sigdelset( &sigmsk, SIGSEGV ); sigdelset( &sigmsk, SIGILL ); sigdelset( &sigmsk, SIGFPE ); pthread_sigmask( SIG_SETMASK, &sigmsk, NULL ); memset( &callbacks, 0, sizeof(ThreadCallback_t) ); callbacks.sighupFunc = mainSighup; thread_register( &mainThreadId, "MainThread", NULL ); /* Setup signal handler for SIGUSR1 (toggles Debug) */ sa.sa_sigaction = (sigAction_t)logging_toggle_debug; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART; sigaction( SIGUSR1, &sa, NULL ); /* Setup the exit handler */ atexit( MainDelayExit ); /* Setup signal handler for SIGINT (shut down cleanly) */ sa.sa_sigaction = (sigAction_t)signal_interrupt; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART; sigaction( SIGINT, &sa, NULL ); /* Setup signal handlers that are to be propogated to all threads */ sa.sa_sigaction = (sigAction_t)signal_everyone; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction( SIGUSR2, &sa, NULL ); sigaction( SIGHUP, &sa, NULL ); sigaction( SIGWINCH, &sa, NULL ); /* Setup signal handlers for SEGV, ILL, FPE */ sa.sa_sigaction = (sigAction_t)signal_death; sigemptyset( &sa.sa_mask ); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction( SIGSEGV, &sa, NULL ); sigaction( SIGILL, &sa, NULL ); sigaction( SIGFPE, &sa, NULL ); versionAdd( "pthreads", pthreadsVersion ); versionAdd( "TERM", getenv("TERM") ); thread_create( &loggingThreadId, LoggingThread, NULL, "LoggingThread", NULL ); #if 0 curses_start(); cursesMenuItemAdd( 2, MENU_SYSTEM, "About", mainAbout, NULL ); cursesMenuItemAdd( 2, MENU_SYSTEM, "Licensing", mainLicensing, NULL ); cursesMenuItemAdd( 2, MENU_SYSTEM, "Versions", mainVersions, NULL ); cursesMenuItemAdd( 2, MENU_SYSTEM, "Reload All", mainReloadAll, NULL ); #endif LogBanner(); db_init(); db_mysql_init(); memset( &callbacks, 0, sizeof(ThreadCallback_t) ); callbacks.sigusr2Func = memoryStats; thread_create( &memoryThreadId, MemoryCoalesceThread, NULL, "MemoryCoalesceThread", &callbacks ); thread_create( &dnsThreadId, DnsThread, NULL, "DnsThread", NULL ); thread_create( &inputThreadId, InputThread, NULL, "InputThread", NULL ); thread_create( &loginThreadId, LoginThread, NULL, "LoginThread", NULL ); thread_create( &editorThreadId, EditorThread, NULL, "EditorThread", NULL ); mortalPlayingArgs.inputQ = InputPlayerQ; thread_create( &mortalPlayingThreadId, PlayingThread, &mortalPlayingArgs, "MortalPlayingThread", NULL ); immortPlayingArgs.inputQ = InputImmortQ; thread_create( &immortPlayingThreadId, PlayingThread, &immortPlayingArgs, "ImmortPlayingThread", NULL ); thread_create( &mysqlThreadId, MysqlThread, NULL, "MySQLThread", NULL ); thread_create( &protobufThreadId, ProtobufThread, NULL, "ProtobufThread", NULL ); pthread_mutex_lock( startupMutex ); pthread_mutex_unlock( startupMutex ); db_check_schema_main(); thread_create( &smtpThreadId, SmtpThread, NULL, "SMTPThread", NULL ); connectThreadArgs.port = mud_port; connectThreadArgs.timeout_sec = 0; connectThreadArgs.timeout_usec = 100000; thread_create( &connectionThreadId, ConnectionThread, &connectThreadArgs, "ConnectionThread", NULL ); pthread_mutex_lock( startupMutex ); pthread_mutex_unlock( startupMutex ); /* Sit on this and rotate - this causes an intentional deadlock, this * thread should stop dead in its tracks */ thread_mutex_init( &spinLockMutex ); pthread_mutex_lock( &spinLockMutex ); pthread_mutex_lock( &spinLockMutex ); }
NTSTATUS DeviceConfigure( _In_ PDEVICE_CONTEXT DeviceContext ) /*++ Routine Description: This method is called after the device callback object has been initialized and returned to the driver. It would setup the device's queues and their corresponding callback objects. Arguments: FxDevice - the framework device object for which we're handling events. Return Value: status --*/ { NTSTATUS status; WDFDEVICE device = DeviceContext->Device; WDFKEY key; LPGUID guid; errno_t errorNo; DECLARE_CONST_UNICODE_STRING(portName, REG_VALUENAME_PORTNAME); DECLARE_UNICODE_STRING_SIZE (comPort, 10); DECLARE_UNICODE_STRING_SIZE (symbolicLinkName, SYMBOLIC_LINK_NAME_LENGTH); #ifdef _FAKE_MODEM // // Compiled as fake modem // guid = (LPGUID) &GUID_DEVINTERFACE_MODEM; #else // // Compiled as virtual serial port // guid = (LPGUID) &GUID_DEVINTERFACE_COMPORT; #endif // // Create device interface // status = WdfDeviceCreateDeviceInterface( device, guid, NULL); if (!NT_SUCCESS(status)) { Trace(TRACE_LEVEL_ERROR, "Error: Cannot create device interface"); goto Exit; } // // Read the COM port number from the registry, which has been automatically // created by "MsPorts!PortsClassInstaller" if INF file says "Class=Ports" // status = WdfDeviceOpenRegistryKey( device, PLUGPLAY_REGKEY_DEVICE, KEY_QUERY_VALUE, WDF_NO_OBJECT_ATTRIBUTES, &key); if (!NT_SUCCESS(status)) { Trace(TRACE_LEVEL_ERROR, "Error: Failed to retrieve device hardware key root"); goto Exit; } status = WdfRegistryQueryUnicodeString( key, &portName, NULL, &comPort); if (!NT_SUCCESS(status)) { Trace(TRACE_LEVEL_ERROR, "Error: Failed to read PortName"); goto Exit; } // // Manually create the symbolic link name. Length is the length in // bytes not including the NULL terminator. // // 6054 and 26035 are code analysis warnings that comPort.Buffer might // not be NULL terminated, while we know that they are. // #pragma warning(suppress: 6054 26035) symbolicLinkName.Length = (USHORT)((wcslen(comPort.Buffer) * sizeof(wchar_t)) + sizeof(SYMBOLIC_LINK_NAME_PREFIX) - sizeof(UNICODE_NULL)); if (symbolicLinkName.Length >= symbolicLinkName.MaximumLength) { Trace(TRACE_LEVEL_ERROR, "Error: Buffer overflow when creating COM port name. Size" " is %d, buffer length is %d", symbolicLinkName.Length, symbolicLinkName.MaximumLength); status = STATUS_BUFFER_OVERFLOW; goto Exit; } errorNo = wcscpy_s(symbolicLinkName.Buffer, SYMBOLIC_LINK_NAME_LENGTH, SYMBOLIC_LINK_NAME_PREFIX); if (errorNo != 0) { Trace(TRACE_LEVEL_ERROR, "Failed to copy %ws to buffer with error %d", SYMBOLIC_LINK_NAME_PREFIX, errorNo); status = STATUS_INVALID_PARAMETER; goto Exit; } errorNo = wcscat_s(symbolicLinkName.Buffer, SYMBOLIC_LINK_NAME_LENGTH, comPort.Buffer); if (errorNo != 0) { Trace(TRACE_LEVEL_ERROR, "Failed to copy %ws to buffer with error %d", comPort.Buffer, errorNo); status = STATUS_INVALID_PARAMETER; goto Exit; } // // Create symbolic link // status = WdfDeviceCreateSymbolicLink( device, &symbolicLinkName); if (!NT_SUCCESS(status)) { Trace(TRACE_LEVEL_ERROR, "Error: Cannot create symbolic link %ws", symbolicLinkName.Buffer); goto Exit; } status = DeviceGetPdoName(DeviceContext); if (!NT_SUCCESS(status)) { goto Exit; } status = DeviceWriteLegacyHardwareKey( DeviceContext->PdoName, comPort.Buffer, DeviceContext->Device); if (NT_SUCCESS(status)) { DeviceContext->CreatedLegacyHardwareKey = TRUE; } status = QueueCreate(DeviceContext); if (!NT_SUCCESS(status)) { goto Exit; } Exit: return status; }
NTSTATUS EvtDeviceAdd( _In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit ) /*++ Routine Description: EvtDeviceAdd is called by the framework in response to AddDevice call from the PnP manager. We create and initialize a device object to represent a new instance of the device. Arguments: Driver - Handle to a framework driver object created in DriverEntry DeviceInit - Pointer to a framework-allocated WDFDEVICE_INIT structure. Return Value: NTSTATUS --*/ { NTSTATUS status; WDF_OBJECT_ATTRIBUTES deviceAttributes; WDFDEVICE device; PDEVICE_CONTEXT deviceContext; PHID_DEVICE_ATTRIBUTES hidAttributes; UNREFERENCED_PARAMETER (Driver); KdPrint(("Enter EvtDeviceAdd\n")); // // Mark ourselves as a filter, which also relinquishes power policy ownership // WdfFdoInitSetFilter(DeviceInit); WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE( &deviceAttributes, DEVICE_CONTEXT); status = WdfDeviceCreate(&DeviceInit, &deviceAttributes, &device); if (!NT_SUCCESS(status)) { KdPrint(("Error: WdfDeviceCreate failed 0x%x\n", status)); return status; } deviceContext = GetDeviceContext(device); deviceContext->Device = device; deviceContext->DeviceData = 0; hidAttributes = &deviceContext->HidDeviceAttributes; RtlZeroMemory(hidAttributes, sizeof(HID_DEVICE_ATTRIBUTES)); hidAttributes->Size = sizeof(HID_DEVICE_ATTRIBUTES); hidAttributes->VendorID = HIDMINI_VID; hidAttributes->ProductID = HIDMINI_PID; hidAttributes->VersionNumber = HIDMINI_VERSION; status = QueueCreate(device, &deviceContext->DefaultQueue); if( !NT_SUCCESS(status) ) { return status; } status = ManualQueueCreate(device, &deviceContext->ManualQueue); if( !NT_SUCCESS(status) ) { return status; } // // Use default "HID Descriptor" (hardcoded). We will set the // wReportLength memeber of HID descriptor when we read the // the report descriptor either from registry or the hard-coded // one. // deviceContext->HidDescriptor = G_DefaultHidDescriptor; // // Check to see if we need to read the Report Descriptor from // registry. If the "ReadFromRegistry" flag in the registry is set // then we will read the descriptor from registry using routine // ReadDescriptorFromRegistry(). Otherwise, we will use the // hard-coded default report descriptor. // status = CheckRegistryForDescriptor(device); if (NT_SUCCESS(status)){ // // We need to read read descriptor from registry // status = ReadDescriptorFromRegistry(device); if (!NT_SUCCESS(status)){ KdPrint(("Failed to read descriptor from registry\n")); } } // // We will use hard-coded report descriptor if registry one is not used. // if (!NT_SUCCESS(status)){ deviceContext->ReportDescriptor = G_DefaultReportDescriptor; KdPrint(("Using Hard-coded Report descriptor\n")); status = STATUS_SUCCESS; } return status; }
/*************************************************************** * Bank System Initid ****************************************************************/ int Bank_Sys_Init(void) { QueueCreate(&sq); QueueCreate(&sq1); return 0; }
/** * @brief Initialize a ParallelWriter */ static void ParallelWriterInit(ParallelWriter *self) { unsigned queryKey; char queueName[MAXPGPATH]; PGresult *res; Assert(self->base.truncate == false); if (self->base.relid != InvalidOid) { TupleDesc resultDesc; /* open relation without any relation locks */ self->base.rel = heap_open(self->base.relid, NoLock); self->base.desc = RelationGetDescr(self->base.rel); self->base.tchecker = CreateTupleChecker(self->base.desc); self->base.tchecker->checker = (CheckerTupleProc) CoercionCheckerTuple; /* * If the return value of the filter function or input function is a * target table, lookup_rowtype_tupdesc grab AccessShareLock on the * table in the first call. We call lookup_rowtype_tupdesc here to * avoid deadlock when lookup_rowtype_tupdesc is called by the internal * routine of the filter function or input function, because a parallel * writer process holds an AccessExclusiveLock. */ resultDesc = lookup_rowtype_tupdesc(self->base.desc->tdtypeid, -1); ReleaseTupleDesc(resultDesc); } else { self->writer->init(self->writer); self->base.desc = self->writer->desc; self->base.tchecker = self->writer->tchecker; } self->base.context = AllocSetContextCreate( CurrentMemoryContext, "ParallelWriter", ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE); /* create queue */ self->queue = QueueCreate(&queryKey, DEFAULT_BUFFER_SIZE); snprintf(queueName, lengthof(queueName), ":%u", queryKey); /* connect to localhost */ self->conn = connect_to_localhost(); /* start transaction */ res = PQexec(self->conn, "BEGIN"); if (PQresultStatus(res) != PGRES_COMMAND_OK) { ereport(ERROR, (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION), errmsg("could not start transaction"), errdetail("%s", finish_and_get_message(self)))); } PQclear(res); if (!self->writer->dup_badfile) self->writer->dup_badfile = self->base.dup_badfile; if (1 != self->writer->sendQuery(self->writer, self->conn, queueName, self->base.logfile, self->base.verbose)) { ereport(ERROR, (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION), errmsg("could not send query"), errdetail("%s", finish_and_get_message(self)))); } }