void DestroySolution(Solution* Sol){ int n = Sol->size; for(int i=0; i<n; i++){ DestroyQueue(Sol->queens[i]); DestroyQueue(Sol->knights[i]); } free(Sol->queens); free(Sol->knights); free(Sol); }
void bfs(Edge **C, int nNodes, int sink, int *sequenceList) { int *colour; Item u, v, *p; Item i = 0; int k = 0; p = (Item *)malloc(sizeof(Item)); colour = (int *)calloc(nNodes, sizeof(int)); colour[sink] = GRAY; Queue *queue = InitQueue(); EnQueue(queue, sink); do { while (!IsEmpty(queue)) { DeQueue(queue, p); sequenceList[k++] = v = *p; for (u = 0; u < nNodes; u++) { if (colour[u] == WHITE && C[u][v].eContent > 0) { EnQueue(queue, u); colour[u] = GRAY; } } colour[v] = BLACK; } if (colour[i] == WHITE) { EnQueue(queue, i); colour[i] = GRAY; } } while(i++ < nNodes); free(p); free(colour); DestroyQueue(queue); }
/* * === FUNCTION ====================================================================== * Name: ClearQueue * Description: * ===================================================================================== */ Status ClearQueue ( LinkQueue *Q) { DestroyQueue(Q); InitQueue(Q); return OK; } /* ----- end of function ClearQueue ----- */
int main() { LinkQueue Q; if(InitQueue(&Q)) { QElemType e; printf("initialize successful"); if(IsEmpty(Q)) { printf("queue is IsEmpty\n"); } for (int i=0;i<10;i++) { EnQueue(&Q,i); } GetHead(Q,&e); printf("The head element is %d\n",e ); printf("The length of the queue is %d\n",GetLength(Q)); DeQueue(&Q,&e); printf("delete element is %d\n",e); TraverseQueue(Q,*visit); if (DestroyQueue(&Q)) { printf("DestroyQueue successful\n"); } } return 0; }
void LevelOrderTraverse(BinaryTree * binaryTree,void(*visit)()){ if(binaryTree){ NodeQueue * queue=NULL; queue=InitQueue(); visit(binaryTree->data); if(binaryTree->lChild){ EnQueue(queue,binaryTree->lChild); } if(binaryTree->rChild){ EnQueue(queue,binaryTree->rChild); } while(IsQueueEmpty(queue)==1){ Node * e=NULL; e=DeQueue(queue); visit(e->data); if(e->lChild){ EnQueue(queue,e->lChild); } if(e->rChild){ EnQueue(queue,e->rChild); } } DestroyQueue(queue); } }
int main() { //测试样例 QElemType a[5]={2,3,4,5,6}; QElemType result; LinkQueue queue; InitQueue(queue,1); printf_s("初始化队列...完成\n"); PrintQueue(queue); //进出顺序:进三个,出两个,进两个,清空队列 printf_s("队列进入三个元素..."); EnQueue(queue,a[0]); EnQueue(queue,a[1]); EnQueue(queue,a[2]); printf_s("完成\n"); PrintQueue(queue); printf_s("队列退出两个元素..."); DeQueue(queue,result); DeQueue(queue,result); printf_s("完成\n"); PrintQueue(queue); printf_s("队列进入两个元素..."); EnQueue(queue,a[3]); EnQueue(queue,a[4]); printf_s("完成\n"); PrintQueue(queue); printf_s("销毁队列..."); DestroyQueue(queue); printf_s("完成\n"); }
int main() { int i; QElemType d; LinkQueue q; i=InitQueue(&q); if(i) printf("成功地构造了一个空队列!\n"); printf("是否空队列?%d(1:空 0:否) ",QueueEmpty(q)); printf("队列的长度为%d\n",QueueLength(q)); EnQueue(&q,-5); EnQueue(&q,5); EnQueue(&q,10); printf("插入3个元素(-5,5,10)后,队列的长度为%d\n",QueueLength(q)); printf("是否空队列?%d(1:空 0:否) ",QueueEmpty(q)); printf("队列的元素依次为:"); QueueTraverse(q); i=GetHead(q,&d); if(i==OK) printf("队头元素是:%d\n",d); DeQueue(&q,&d); printf("删除了队头元素%d\n",d); i=GetHead(q,&d); if(i==OK) printf("新的队头元素是:%d\n",d); ClearQueue(&q); printf("清空队列后,q.front=%u q.rear=%u q.front->next=%u\n",q.front,q.rear,q.front->next); DestroyQueue(&q); printf("销毁队列后,q.front=%u q.rear=%u\n",q.front, q.rear); return 0; }
//----------------------------------------------- // Test a 4-entry queue //----------------------------------------------- int main() { int elem = 0; queue *Q; CreateQueue(Q, 4); Dequeue(Q); Enqueue(Q, ++elem); Enqueue(Q, ++elem); Enqueue(Q, ++elem); Enqueue(Q, ++elem); Dequeue(Q); Enqueue(Q, ++elem); Enqueue(Q, ++elem); Dequeue(Q); Enqueue(Q, ++elem); Dequeue(Q); Enqueue(Q, ++elem); Dequeue(Q); Dequeue(Q); Dequeue(Q); Dequeue(Q); DestroyQueue(Q); return 0; }
//测试单链队列的主程序 int main() { SqQueue s; int x; //输入若干正整数以0结束,依次入栈,然后依次出栈并打印 InitQueue(&s); printf("Is empty: %d\n",IsEmpty(s)); printf("the length is: %d\n",QueueLength(s)); printf("进入队列顺序: 1 2 3 \n"); EnQueue(&s,1); EnQueue(&s,2); EnQueue(&s,3); printf("the top is : %d\n",x); printf("Is empty: %d\n",IsEmpty(s)); printf("the length is: %d\n",QueueLength(s)); printf("\n退出队列结果:"); while(!IsEmpty(s)) { DEQueue(&s,&x); printf("%4d",x); } printf("\nIs empty: %d\n",IsEmpty(s)); //------------------------------------- // TODO (#1#): 其它测试程序 //------------------------------------- DestroyQueue(&s); //销毁栈 return 0; }
int main() { LinkQueue Q; QElemType e = 5; InitQueue(&Q); EnQueue(&Q,e); TranverseQueue(Q,print); printf("\n------------\n"); e = 6; EnQueue(&Q,e); TranverseQueue(Q,print); printf("\n------------\n"); e = 7; EnQueue(&Q,e); TranverseQueue(Q,print); printf("\n------------\n"); DeQueue(&Q,&e); TranverseQueue(Q,print); DestroyQueue(&Q); return 0; }
Status ClearQueue(LinkQueue &q) { DestroyQueue(q); q.front->next = NULL; q.rear = q.front; return OK; }
void sendMailQueue( int signal ) { /* ----------------------------------------- */ void* dbase_handler = NULL; long longRet = 0; char* response = NULL; /* ----------------------------------------- */ if ((_GLOBAL_shptr->config).stopSending == 0) { sem_wait(&(_GLOBAL_shptr->clientMutex)); longRet = bmd_db_connect2(_GLOBAL_awizoConfig.dbIP, _GLOBAL_awizoConfig.dbPort, _GLOBAL_awizoConfig.dbName, \ _GLOBAL_awizoConfig.dbUser, _GLOBAL_awizoConfig.dbPassword, &dbase_handler); if ( longRet < 0 ){ PRINT_ERROR("Błąd połączenia z bazą danych. Error = %d\n", BMD_ERR_OP_FAILED); } /* **************************************************** */ /* uruchomienie procesu wysyłki e-Awiza w jednej sesji */ /* **************************************************** */ PRINT_INFO("AWIZOJMSSERVERINF SENT %ld AWIZOS FROM MAILQUEUE.\n", _GLOBAL_myXmlQueue.ulCount ); longRet = prepareAndSendAwizoSet( dbase_handler, &response ); if (longRet != BMD_OK) { PRINT_ERROR("Błąd wysyłki zakolejkowanych wiadomości email. Error = %d\n", BMD_ERR_OP_FAILED); } bmd_db_disconnect(&dbase_handler); /* ************************************* */ /* Wyczyszczenie kolejki wiadomości */ /* ************************************* */ PRINT_INFO("AWIZOJMSSERVERINF CURRENT MAILQUEUE SIZE : %ld.\n", _GLOBAL_myXmlQueue.ulCount ); PRINT_INFO("AWIZOJMSSERVERINF CLEAR MAILQUEUE\n"); if (DestroyQueue(&_GLOBAL_myXmlQueue, DestroyMsgNode) != BMD_OK) { PRINT_ERROR("Błędy w trakcie czyszczenia kolejki komunikatów. Error = %d\n", BMD_ERR_OP_FAILED); } PRINT_INFO("AWIZOJMSSERVERINF CURRENT MAILQUEUE SIZE : %ld.\n", _GLOBAL_myXmlQueue.ulCount ); sem_post(&(_GLOBAL_shptr->clientMutex)); } else{ PRINT_INFO("AWIZOJMSSERVERINF USER STOPED AWIZO SENDING PROCESS.\n" ); } }
void DeleteThreadQueue(ThreadQueue *q) { if (q->sem) { SemaphoreSignal(q->sem); SemaphoreDestroy(q->sem); q->sem = NULL; } DestroyQueue(q->queue); free(q); }
int main(int argc, char const* argv[]) { Queue queue = BuildQueue(5); Enqueue(queue, 1); Enqueue(queue, 2); Enqueue(queue, 4); Enqueue(queue, 5); Enqueue(queue, 6); Dequeue(queue); Enqueue(queue, 7); ShowQueue(queue); DestroyQueue(queue); }
void Stop(int signo) { printf("oops! stop by ctrl+c or kill!!!----------------------------------------\n"); if(flock(fileno(fd_pid_conf),LOCK_UN) != 0) { DEBUG_printf("unlock fd_pid_conf failed!\n"); } else { DEBUG_printf("unlock fd_pid_conf succeed!\n"); } fclose(fd_pid_conf); DeleteList(L_cmd); p_n_over = false; //sleep(5); pthread_join(thread_id,NULL); //pthread_join(thread_rev,NULL); pthread_join(thread_deal_cmd_id,NULL); pthread_join(thread_deal_response_id,NULL); DestroyQueue(&Q_cmd); DestroyQueue(&Q_respond); SSL_shutdown(ssl); SSL_free(ssl); close(sockfd); SSL_CTX_free(ctx); CONF_modules_free(); ERR_remove_state(0); ENGINE_cleanup(); CONF_modules_unload(1); ERR_free_strings(); EVP_cleanup(); CRYPTO_cleanup_all_ex_data(); sk_SSL_COMP_free(SSL_COMP_get_compression_methods()); exit(0); }
/* test application */ int main() { Tqueue queue; double Ta, Tc; queue = CreateQueue(NOT_OK); printf("First the simple array implementation\n"); printf("dequeue() took %lf us to run\n", Ta = measureQueue(queue, N)*1e6); DestroyQueue(queue); queue = CreateQueue(OK); printf("\nThen the circular array implementation\n"); printf("dequeue() took %lf us to run\n", Tc = measureQueue(queue, N)*1e6); DestroyQueue(queue); if (Tc != 0.0) printf("\nCircular implementation was %d times faster than array implementation\n", (int)floor(Ta/Tc + .5)); else printf("\nNo circular implmentation measurement available\n"); fflush(stdin); getchar(); }
void clearCache(int num, siginfo_t* info, void *other ) { PRINT_INFO("AWIZOJMSSERVERINF CURRENT CACHE SIZE : %ld.\n", _GLOBAL_myCache.ulCount ); PRINT_INFO("AWIZOJMSSERVERINF CLEAR CACHE\n"); if (DestroyQueue(&_GLOBAL_myCache, DestroyCacheNode) != BMD_OK) { PRINT_ERROR("Błędy w trakcie czyszczenia pamięci cache. Error = %d\n", BMD_ERR_OP_FAILED); } PRINT_INFO("AWIZOJMSSERVERINF CURRENT CACHE SIZE : %ld.\n", _GLOBAL_myCache.ulCount ); sem_post(&(_GLOBAL_shptr->clientMutex)); }
void clearMailQueue(int num, siginfo_t* info, void *other ) { PRINT_INFO("AWIZOJMSSERVERINF CURRENT MAILQUEUE SIZE : %ld.\n", _GLOBAL_myXmlQueue.ulCount ); PRINT_INFO("AWIZOJMSSERVERINF CLEAR MAILQUEUE\n"); if (DestroyQueue(&_GLOBAL_myXmlQueue, DestroyMsgNode) != BMD_OK) { PRINT_ERROR("Błędy w trakcie czyszczenia kolejki komunikatów. Error = %d\n", BMD_ERR_OP_FAILED); } PRINT_INFO("AWIZOJMSSERVERINF CURRENT MAILQUEUE SIZE : %ld.\n", _GLOBAL_myXmlQueue.ulCount ); sem_post(&(_GLOBAL_shptr->clientMutex)); }
BOOL DestroyNode(ObjDescType nds) { NodeType* pnode; pnode=GetObjPtr(nds, &Node_Carrier); if(!pnode) return FALSE; DetachNode(nds); if(pnode->pReqList) DestroyObjectList(pnode->pReqList); if(pnode->pItfList) DestroyObjectList(pnode->pItfList); if(pnode->pOpList) DestroyObjectList(pnode->pOpList); if(pnode->pRtList) DestroyObjectList(pnode->pRtList); if(pnode->pReqQueue) DestroyQueue(pnode->pReqQueue); free(pnode); return TRUE; }
int main() { ULONG i, j; Queue Queue; PCACHE_BLOCK *blocks, pblock; blocks = (PCACHE_BLOCK*)malloc(QUEUE_SIZE*sizeof(PCACHE_BLOCK)); assert(blocks); for (i = 0; i < QUEUE_SIZE; i++) { assert(blocks[i] = (PCACHE_BLOCK)malloc(sizeof(CACHE_BLOCK))); blocks[i]->Value = i; } assert(InitQueue(&Queue, QUEUE_SIZE/2)); QueueInsert(&Queue, blocks[0]); QueueInsert(&Queue, blocks[1]); QueueRemove(&Queue); QueueRemove(&Queue); i = 0, j = 0; while (QueueInsert(&Queue, blocks[i++]) == TRUE); while ((pblock = QueueRemove(&Queue)) != NULL) assert(pblock->Value == blocks[j++]->Value); srand((unsigned int)time(NULL)); i = 0, j = 0; while (i < QUEUE_SIZE) { if (rand() & 1) QueueInsert(&Queue, blocks[i++]); else if ((pblock = QueueRemove(&Queue)) != NULL) assert(pblock->Value == blocks[j++]->Value); } while ((pblock = QueueRemove(&Queue)) != NULL) assert(pblock->Value == blocks[j++]->Value); DestroyQueue(&Queue); for (i = 0; i < QUEUE_SIZE; i++) free(blocks[i]); free(blocks); return 0; }
int main() { Queue q; int nData = 0; int nLength = 0; BOOL bEmpty = FALSE; InitQueue(&q); EnQueue(&q, 12); EnQueue(&q, 3); EnQueue(&q, 8); EnQueue(&q, 34); EnQueue(&q, 6); EnQueue(&q, 9); EnQueue(&q, 56); EnQueue(&q, 78); EnQueue(&q, 4); EnQueue(&q, 90); printf("入队后的队列:"); TraverseQueue(&q, OutputQueue); nLength = GetQueueLength(&q); printf("队列长度:%d\n", nLength); bEmpty = IsQueueEmpty(&q); printf("队列为%s\n", bEmpty ? "空" : "非空"); DeQueue(&q, &nData); printf("出队数据:%d\n", nData); printf("出队后的队列:"); TraverseQueue(&q, OutputQueue); DeQueue(&q, &nData); printf("出队数据:%d\n", nData); printf("出队后的队列:"); TraverseQueue(&q, OutputQueue); DestroyQueue(&q); return 0; }
void main() { Status j; int i,n; QElemType d; SqQueue Q; InitQueue(Q); printf("初始化队列后,队列空否?%u(1:空 0:否)\n",QueueEmpty(Q)); printf("队列长度为:%d\n",QueueLength(Q)); printf("请输入队列元素个数n: "); scanf("%d",&n); printf("请输入%d个整型队列元素:\n",n); for(i=0;i<n;i++) { scanf("%d",&d); EnQueue(Q,d); } printf("队列长度为:%d\n",QueueLength(Q)); printf("现在队列空否?%u(1:空 0:否)\n",QueueEmpty(Q)); printf("现在队列中的元素为: \n"); QueueTraverse(Q,visit); DeQueue(Q,d); printf("删除队头元素%d\n",d); printf("队列中的元素为: \n"); QueueTraverse(Q,visit); j=GetHead(Q,d); if(j) printf("队头元素为: %d\n",d); else printf("无队头元素(空队列)\n"); ClearQueue(Q); printf("清空队列后, 队列空否?%u(1:空 0:否)\n",QueueEmpty(Q)); j=GetHead(Q,d); if(j) printf("队头元素为: %d\n",d); else printf("无队头元素(空队列)\n"); DestroyQueue(Q); }
int main(){ int value =0; QueType* queue; QueType* q1 = QueType* q2 = NULL; printf("enter value; %d\n", value); scanf("%d\n",&value); queue = CreateQueue(); while(value <= 7){ Enqueue(queue,value); value++; printf("\n Elements in the queue are:\n"); printqueue(queue,value); } /* Print all the items */ while(!IsQueueEmpty(queue)){ Dequeue(queue,&value); printf("%d\n",value); } DestroyQueue(queue); return 0; }
void main() { Status j; int i=0,m; QElemType d; SqQueue Q; InitQueue(Q); printf("初始化队列后,队列空否?%u(1:空 0:否)\n",QueueEmpty(Q)); printf("请输入整型队列元素(不超过%d个),-1为提前结束符:",MAX_QSIZE-1); do { scanf("%d",&d); if(d==-1) break; i++; EnQueue(Q,d); } while(i<MAX_QSIZE-1); printf("队列长度为%d,",QueueLength(Q)); printf("现在队列空否?%u(1:空 0:否)\n",QueueEmpty(Q)); printf("连续%d次由队头删除元素,队尾插入元素:\n",MAX_QSIZE); for(m=1; m<=MAX_QSIZE; m++) { DeQueue(Q,d); printf("删除的元素是%d,请输入待插入的元素:",d); scanf("%d",&d); EnQueue(Q,d); } m=QueueLength(Q); printf("现在队列中的元素为"); QueueTraverse(Q,print); printf("共向队尾插入了%d个元素。",i+MAX_QSIZE); if(m-2>0) printf("现在由队头删除%d个元素,",m-2); while(QueueLength(Q)>2) { DeQueue(Q,d); printf("删除的元素值为%d,",d); } j=GetHead(Q,d); if(j) printf("现在队头元素为%d\n",d); ClearQueue(Q); printf("清空队列后,队列空否?%u(1:空 0:否)\n",QueueEmpty(Q)); DestroyQueue(Q); }
/* * === FUNCTION ====================================================================== * Name: main * Description: * ===================================================================================== */ int main ( int argc, char *argv[] ) { LinkQueue Q; if(InitQueue(&Q)) { QElemtype e; int i; printf("Init Success\n"); if(IsEmpty(Q)) { printf("Queue is Empty\n"); } for(i = 0; i < 10; i++) { EnQueue(&Q, i); } GetHead(Q, &e); printf("The first element is %d\n", e); printf("Length is %d\n", GetLength(Q)); DeQueue(&Q,&e); printf("Delete element is %d \n", e); TraverseQueue(Q, *visit); if(DestroyQueue(&Q)) { printf("\n DestroyQueue Success\n"); } } return EXIT_SUCCESS; } /* ---------- end of function main ---------- */
CmDevice_RT::~CmDevice_RT(void) { for (UINT i = 0; i < m_KernelCount; i++) { CmKernel_RT *pKernel = (CmKernel_RT *) m_KernelArray.GetElement(i); if (pKernel) { CmProgram_RT *pProgram = NULL; pKernel->GetCmProgram(pProgram); UINT indexInProgramArray; for (indexInProgramArray = 0; indexInProgramArray < m_ProgramCount; indexInProgramArray++) { if (pProgram == m_ProgramArray.GetElement (indexInProgramArray)) { break; } } CmKernel_RT::Destroy(pKernel, pProgram); if ((pProgram == NULL) && (indexInProgramArray < m_ProgramCount)) { m_ProgramArray.SetElement(indexInProgramArray, NULL); } } } m_KernelArray.Delete(); for (UINT i = 0; i < m_ProgramCount; i++) { CmProgram_RT *pProgram = (CmProgram_RT *) m_ProgramArray.GetElement(i); while (pProgram) { CmProgram_RT::Destroy(pProgram); } } m_ProgramArray.Delete(); UINT ThreadSpaceArrayUsedSize = m_ThreadSpaceArray.GetMaxSize(); for (UINT i = 0; i < ThreadSpaceArrayUsedSize; i++) { CmThreadSpace *pTS_RT = (CmThreadSpace *) m_ThreadSpaceArray.GetElement(i); if (pTS_RT) { CmThreadSpace::Destroy(pTS_RT); } } m_ThreadSpaceArray.Delete(); for (UINT i = 0; i < m_ThreadGroupSpaceCount; i++) { CmThreadGroupSpace *pTGS = (CmThreadGroupSpace *) m_ThreadGroupSpaceArray.GetElement(i); if (pTGS) { CmThreadGroupSpace_RT::Destroy(pTGS); } } m_ThreadGroupSpaceArray.Delete(); UINT TaskArrayUsedSize = m_TaskArray.GetMaxSize(); for (UINT i = 0; i < TaskArrayUsedSize; i++) { CmTask_RT *pTask = (CmTask_RT *) m_TaskArray.GetElement(i); if (pTask) { CmTask_RT::Destroy(pTask); } } m_TaskArray.Delete(); CmSurfaceManager::Destroy(m_pSurfaceMgr); DestroyQueue(m_pQueue); if (m_hJITDll) { FreeLibrary(m_hJITDll); } DestroyAuxDevice(); };
Status ClearQueue(LinkQueue *Q) { DestroyQueue(Q); InitQueue(Q); return OK; }
/** Stop the USB keyboard device handled by this driver. @param This The USB keyboard driver binding protocol. @param Controller The controller to release. @param NumberOfChildren The number of handles in ChildHandleBuffer. @param ChildHandleBuffer The array of child handle. @retval EFI_SUCCESS The device was stopped. @retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol is not installed on Controller. @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error. @retval Others Fail to uninstall protocols attached on the device. **/ EFI_STATUS EFIAPI USBKeyboardDriverBindingStop ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer ) { EFI_STATUS Status; EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleInput; USB_KB_DEV *UsbKeyboardDevice; Status = gBS->OpenProtocol ( Controller, &gEfiSimpleTextInProtocolGuid, (VOID **) &SimpleInput, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } Status = gBS->OpenProtocol ( Controller, &gEfiSimpleTextInputExProtocolGuid, NULL, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_TEST_PROTOCOL ); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (SimpleInput); // // The key data input from this device will be disabled. // REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, (EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_DISABLE), UsbKeyboardDevice->DevicePath ); // // Delete the Asynchronous Interrupt Transfer from this device // UsbKeyboardDevice->UsbIo->UsbAsyncInterruptTransfer ( UsbKeyboardDevice->UsbIo, UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress, FALSE, UsbKeyboardDevice->IntEndpointDescriptor.Interval, 0, NULL, NULL ); gBS->CloseProtocol ( Controller, &gEfiUsbIoProtocolGuid, This->DriverBindingHandle, Controller ); Status = gBS->UninstallMultipleProtocolInterfaces ( Controller, &gEfiSimpleTextInProtocolGuid, &UsbKeyboardDevice->SimpleInput, &gEfiSimpleTextInputExProtocolGuid, &UsbKeyboardDevice->SimpleInputEx, NULL ); // // Free all resources. // gBS->CloseEvent (UsbKeyboardDevice->TimerEvent); gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer); gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent); gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey); gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx); KbdFreeNotifyList (&UsbKeyboardDevice->NotifyList); ReleaseKeyboardLayoutResources (UsbKeyboardDevice); gBS->CloseEvent (UsbKeyboardDevice->KeyboardLayoutEvent); if (UsbKeyboardDevice->ControllerNameTable != NULL) { FreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable); } DestroyQueue (&UsbKeyboardDevice->UsbKeyQueue); DestroyQueue (&UsbKeyboardDevice->EfiKeyQueue); FreePool (UsbKeyboardDevice); return Status; }
/** *MAIN函数 */ int main() { //初始化操作,建立一个队列 queue* testqueue = NULL; testqueue = InitQueue(); //判断队列是否为空 QueueEmpty(testqueue)?printf("True\n"):printf("False\n"); printf("\n"); //数据进入队列 int i; for(i=0;i<15;i++) { EnQueue(testqueue,i); } QueueEmpty(testqueue)?printf("True\n"):printf("False\n"); printf("\n"); //数据退出队列 int temp; for(i=0;i<10;i++) { DeQueue(testqueue,&temp); printf("%d ",temp); } QueueEmpty(testqueue)?printf("\nTrue\n"):printf("\nFalse\n"); printf("\n"); //数据进入队列 for(i=0;i<15;i++) { EnQueue(testqueue,i); } QueueEmpty(testqueue)?printf("True\n"):printf("False\n"); printf("\n"); //数据退出队列 for(i=0;i<17;i++) { DeQueue(testqueue,&temp); printf("%d ",temp); } QueueEmpty(testqueue)?printf("\nTrue\n"):printf("\nFalse\n"); printf("\n"); //获取队首数据 GetHead(testqueue,&temp); printf("%d\n\n",temp); //获取队列长度 int len; len = QueueLength(testqueue); printf("%d\n\n",len); //清除一个队列 ClearQueue(testqueue); len = QueueLength(testqueue); printf("%d\n\n",len); //销毁一个队列 testqueue = DestroyQueue(testqueue); len = QueueLength(testqueue); printf("%d\n\n",len); return 0; }
NTSTATUS DF_DispatchIoctl(PDEVICE_OBJECT DeviceObject, PIRP Irp) { NTSTATUS Status; PVOID InputBuffer; ULONG InputLength; PVOID OutputBuffer; ULONG OutputLength; PIO_STACK_LOCATION IrpSp; PDF_DEVICE_EXTENSION DevExt; BOOLEAN Type; PAGED_CODE(); IrpSp = IoGetCurrentIrpStackLocation(Irp); DevExt = (PDF_DEVICE_EXTENSION)DeviceObject->DeviceExtension; if (DeviceObject == g_pDeviceObject) { InputBuffer = Irp->AssociatedIrp.SystemBuffer; InputLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength; OutputBuffer = Irp->AssociatedIrp.SystemBuffer; OutputLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength; switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) { // Test IOCTL case IOCTL_DF_TEST: DBG_PRINT(DBG_TRACE_OPS, ("%s: Test Ioctl\n", __FUNCTION__)); if (InputLength >= 2*sizeof(ULONG32) && OutputLength >= sizeof(ULONG32)) { *(ULONG32*)OutputBuffer = ((ULONG32*)InputBuffer)[0] + ((ULONG32*)InputBuffer)[1]; Irp->IoStatus.Information = sizeof(ULONG32); } else Irp->IoStatus.Information = 0; Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT); return Irp->IoStatus.Status; // Start or Stop One Filter case IOCTL_DF_START: case IOCTL_DF_STOP: Type = (IOCTL_DF_START == IrpSp->Parameters.DeviceIoControl.IoControlCode); DBG_PRINT(DBG_TRACE_OPS, ("%s: %s One Filter\n", __FUNCTION__, Type?"Start":"Stop")); DeviceObject = g_pDriverObject->DeviceObject; Status = STATUS_UNSUCCESSFUL; while (DeviceObject != NULL) { DevExt = (PDF_DEVICE_EXTENSION)DeviceObject->DeviceExtension; if (DeviceObject != g_pDeviceObject && DevExt->bIsStart == TRUE && DevExt->DiskNumber == ((ULONG32*)InputBuffer)[0] && DevExt->PartitionNumber == ((ULONG32*)InputBuffer)[1]) { DBG_PRINT(DBG_TRACE_OPS, ("%s Filter on disk(%u) partition(%u)\n", Type?"Start":"Stop", ((ULONG32*)InputBuffer)[0], ((ULONG32*)InputBuffer)[1])); #ifndef USE_DRAM DBG_PRINT(DBG_TRACE_OPS, ("Use disk(%u) partition(%u) as Cache\n", ((ULONG32*)InputBuffer)[2], ((ULONG32*)InputBuffer)[3])); #endif Status = STATUS_SUCCESS; if (Type == FALSE) { DevExt->bIsProtected = FALSE; // Wait for unfinished Ops in RW Thread while (FALSE == IsListEmpty(&DevExt->RwList)) { KeSetEvent(&DevExt->RwThreadStartEvent, IO_NO_INCREMENT, FALSE); KeWaitForSingleObject(&DevExt->RwThreadFinishEvent, Executive, KernelMode, FALSE, NULL); } #ifdef WRITE_BACK_ENABLE // Flush Back All Data DevExt->CachePool.WbFlushAll = TRUE; while (DevExt->CachePool.WbQueue.Used) { KeSetEvent(&DevExt->CachePool.WbThreadStartEvent, IO_NO_INCREMENT, FALSE); KeWaitForSingleObject(&DevExt->CachePool.WbThreadFinishEvent, Executive, KernelMode, FALSE, NULL); } DevExt->CachePool.WbFlushAll = FALSE; #endif DevExt->ReadCount = 0; DevExt->WriteCount = 0; DevExt->CachePool.Size = 0; DevExt->CachePool.Used = 0; DevExt->CachePool.ReadHit = 0; DevExt->CachePool.WriteHit = 0; DestroyCachePool(&DevExt->CachePool); } else if (DevExt->bIsProtected == FALSE) { if (InitCachePool(&DevExt->CachePool #ifndef USE_DRAM ,((ULONG32*)InputBuffer)[2] ,((ULONG32*)InputBuffer)[3] #endif ) == TRUE #ifdef WRITE_BACK_ENABLE && InitQueue(&DevExt->CachePool.WbQueue, (WB_QUEUE_SIZE << 20)/(BLOCK_SIZE)) == TRUE #endif ) DevExt->bIsProtected = TRUE; else { #ifdef WRITE_BACK_ENABLE DestroyQueue(&DevExt->CachePool.WbQueue); #endif DestroyCachePool(&DevExt->CachePool); DevExt->bIsProtected = FALSE; KdPrint(("%s: %d-%d: Init Cache Pool Error\n", __FUNCTION__, DevExt->DiskNumber, DevExt->PartitionNumber)); Status = STATUS_UNSUCCESSFUL; } } break; } DeviceObject = DeviceObject->NextDevice; } COMPLETE_IRP(Irp, Status); return Irp->IoStatus.Status; // Get or Clear Statistic case IOCTL_DF_GET_STAT: case IOCTL_DF_CLEAR_STAT: Type = (IOCTL_DF_GET_STAT == IrpSp->Parameters.DeviceIoControl.IoControlCode); DBG_PRINT(DBG_TRACE_OPS, ("%s: %s Statistic\n", __FUNCTION__, Type?"Get":"Clear")); DeviceObject = g_pDriverObject->DeviceObject; Status = STATUS_UNSUCCESSFUL; while (DeviceObject != NULL) { DevExt = (PDF_DEVICE_EXTENSION)DeviceObject->DeviceExtension; if (DeviceObject != g_pDeviceObject && DevExt->bIsStart == TRUE && DevExt->DiskNumber == ((ULONG32*)InputBuffer)[0] && DevExt->PartitionNumber == ((ULONG32*)InputBuffer)[1]) { DBG_PRINT(DBG_TRACE_OPS, ("On disk(%u) partition(%u)\n", DevExt->DiskNumber, DevExt->PartitionNumber)); if (Type && OutputLength >= 6 * sizeof(ULONG32)) { ((ULONG32*)OutputBuffer)[0] = DevExt->CachePool.ReadHit; ((ULONG32*)OutputBuffer)[1] = DevExt->CachePool.WriteHit; ((ULONG32*)OutputBuffer)[2] = DevExt->ReadCount; ((ULONG32*)OutputBuffer)[3] = DevExt->WriteCount; ((ULONG32*)OutputBuffer)[4] = DevExt->CachePool.Size; ((ULONG32*)OutputBuffer)[5] = DevExt->CachePool.Used; Irp->IoStatus.Information = 6 * sizeof(ULONG32); } else { DevExt->CachePool.ReadHit = 0; DevExt->CachePool.WriteHit = 0; DevExt->ReadCount = 0; DevExt->WriteCount = 0; Irp->IoStatus.Information = 0; } Status = STATUS_SUCCESS; break; } DeviceObject = DeviceObject->NextDevice; } Irp->IoStatus.Status = Status; IoCompleteRequest(Irp, IO_NO_INCREMENT); return Irp->IoStatus.Status; // Setup Output case IOCTL_DF_QUIET: DBG_PRINT(DBG_TRACE_OPS, ("%s: Quite All Output\n", __FUNCTION__)); g_TraceFlags = 0; COMPLETE_IRP(Irp, STATUS_SUCCESS); return Irp->IoStatus.Status; case IOCTL_DF_VERBOSE: g_TraceFlags = -1; DBG_PRINT(DBG_TRACE_OPS, ("%s: Verbose All Output\n", __FUNCTION__)); COMPLETE_IRP(Irp, STATUS_SUCCESS); return Irp->IoStatus.Status; // Setup Data Verify case IOCTL_DF_VERIFY: g_bDataVerify = (g_bDataVerify==TRUE)?FALSE:TRUE; DBG_PRINT(DBG_TRACE_OPS, ("%s: %s Data Verify\n", __FUNCTION__, g_bDataVerify?"Start":"Stop")); COMPLETE_IRP(Irp, STATUS_SUCCESS); return Irp->IoStatus.Status; // Unknown Ioctl default: DBG_PRINT(DBG_TRACE_OPS, ("%s: Unknown User Ioctl\n", __FUNCTION__)); COMPLETE_IRP(Irp, STATUS_UNSUCCESSFUL); return Irp->IoStatus.Status; } } else { switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) { case IOCTL_VOLUME_ONLINE: DBG_PRINT(DBG_TRACE_OPS, ("%s: IOCTL_VOLUME_ONLINE\n", __FUNCTION__)); if (IoForwardIrpSynchronously(DevExt->LowerDeviceObject, Irp)) { StartDevice(DeviceObject); } IoCompleteRequest(Irp, IO_NO_INCREMENT); return Irp->IoStatus.Status; case IOCTL_VOLUME_OFFLINE: DBG_PRINT(DBG_TRACE_OPS, ("%s: IOCTL_VOLUME_OFFLINE\n", __FUNCTION__)); // ... Flush back Cache break; case IOCTL_DISK_COPY_DATA: DBG_PRINT(DBG_TRACE_OPS, ("%s: IOCTL_DISK_COPY_DATA\n", __FUNCTION__)); COMPLETE_IRP(Irp, STATUS_UNSUCCESSFUL); return Irp->IoStatus.Status; default: //DBG_PRINT(DBG_TRACE_OPS, ("%s: 0x%X\n", __FUNCTION__, IrpSp->Parameters.DeviceIoControl.IoControlCode)); break; } } IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(DevExt->LowerDeviceObject, Irp); }