📄 handlers.c
字号:
/************************************************************ * * * Copyright (c) 2001-2006 McObject LLC. All Right Reserved.* * * ************************************************************/#include "app.h"#include "monitorDB.h"int test_ExitCode = 0;#ifdef CFG_ASYNCHRONOUS_EVENTSlong ev_new_count = 0;long ev_update_count = 0;long ev_del_count = 0;/* Thread function that handles the <new> event. The visit count * is incremented. When the <new> object is created, eXtremeDB * runtime wakes up the Event_NewHndlr thread - the call to * mco_async_event_wait() retunrs with MCO_S_OK (zero). When the * main thread explicitely releses the event, the thread is also * awakened, but with the return code MCO_S_EVENT_RELEASED (14). * This return value forces the thread function to return, thus * terminating the thread. */THREAD_PROC_DEFINE(Event_NewHndlr, p) { ThrParam *p_ = (ThrParam *)p; mco_db_h db = *p_->db; MCO_RET rc; p_->finished = 0; for(;;) { rc = mco_async_event_wait(db, MCO_EVENT_newEvent); if (rc) { printf("Exiting Event_NewHndlr thread\n"); p_->finished = 1; return; } ev_new_count++; printf("NewEvent handler is called\n",rc); }}/* Thread function that handles the <update> event. The visit count * is incremented. */THREAD_PROC_DEFINE(Event_Update1Hndlr, p) { ThrParam *p_ = (ThrParam *)p; mco_db_h db = *p_->db; MCO_RET rc; p_->finished = 1; for(;;) { rc = mco_async_event_wait(db, MCO_EVENT_update1Event); if (rc) { printf("Exiting Event_UpdateHndlr thread\n"); p_->finished = 1; return; } ev_update_count++; printf("Update1Event handler is called\n",rc); }}/* Thread function that handles the <update> event. The visit count * is incremented. */THREAD_PROC_DEFINE(Event_Update2Hndlr, p) { ThrParam *p_ = (ThrParam *)p; mco_db_h db = *p_->db; MCO_RET rc; p_->finished = 1; for(;;) { rc = mco_async_event_wait(db, MCO_EVENT_update2Event); if (rc) { printf("Exiting Event_Update2Hndlr thread\n"); p_->finished = 1; return; } ev_update_count++; printf("Update2Event handler is called\n",rc); }}/* Thread function that handles the <update> event. The visit count * is incremented. */THREAD_PROC_DEFINE(Event_Update3Hndlr, p) { ThrParam *p_ = (ThrParam *)p; mco_db_h db = *p_->db; MCO_RET rc; p_->finished = 1; for(;;) { rc = mco_async_event_wait(db, MCO_EVENT_update3Event); if (rc) { printf("Exiting Event_Update3Hndlr thread\n"); p_->finished = 1; return; } ev_update_count++; printf("Update3Event handler is called\n",rc); }}/* Thread function that handles the <update> event. The visit count * is incremented. */THREAD_PROC_DEFINE(Event_Update4Hndlr, p) { ThrParam *p_ = (ThrParam *)p; mco_db_h db = *p_->db; MCO_RET rc; p_->finished = 1; for(;;) { rc = mco_async_event_wait(db, MCO_EVENT_update4Event); if (rc) { printf("Exiting Event_Update4Hndlr thread\n"); p_->finished = 1; return; } ev_update_count++; printf("Update4Event handler is called\n",rc); }}/* Thread function that handles the <delete> event. The visit count * is incremented. */THREAD_PROC_DEFINE(Event_DeleteHndlr, p) { ThrParam *p_ = (ThrParam *)p; mco_db_h db = *p_->db; MCO_RET rc; p_->finished = 0; for (;;) { rc = mco_async_event_wait(db, MCO_EVENT_deleteEvent); if (rc) { printf("Exiting Event_DeleteHndlr thread\n"); p_->finished = 1; return; } ev_del_count++; printf("DeleteEvent handler is called\n",rc); }}/* Starts all the event-handling threads */void threads(ThrParam *all_tp_ptr) { THREAD_PROC_START(Event_NewHndlr, &all_tp_ptr[0], &all_tp_ptr[0].tid); Sleep(100); THREAD_PROC_START(Event_Update1Hndlr, &all_tp_ptr[1], &all_tp_ptr[1].tid); THREAD_PROC_START(Event_Update2Hndlr, &all_tp_ptr[2], &all_tp_ptr[2].tid); THREAD_PROC_START(Event_Update3Hndlr, &all_tp_ptr[3], &all_tp_ptr[3].tid); THREAD_PROC_START(Event_Update4Hndlr, &all_tp_ptr[4], &all_tp_ptr[4].tid); Sleep(100); THREAD_PROC_START(Event_DeleteHndlr, &all_tp_ptr[5], &all_tp_ptr[5].tid); Sleep(100);}#endif //CFG_ASYNCHRONOUS_EVENTS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -