📄 handlers.c
字号:
/************************************************************ * * * Copyright (c) 2001-2007 McObject LLC. All Right Reserved.* * * ************************************************************/#include "async.h"long 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"); }}/* Thread function that handles the <update> event. The visit count * is incremented. */THREAD_PROC_DEFINE(Event_UpdateHndlr, 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_updateEvent); if (rc) { printf("Exiting Event_UpdateHndlr thread\n"); p_->finished = 1; return; } ev_update_count++; printf("UpdateEvent handler is called\n"); }}/* 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"); }}/* Starts all the event-handling threads */void threads(ThrParam *all_tp_ptr) { THREAD_ID_T event_new_id; THREAD_ID_T event_update_id; THREAD_ID_T event_del_id; THREAD_PROC_START(Event_NewHndlr, &all_tp_ptr[0], &event_new_id); Sleep(100); THREAD_PROC_START(Event_UpdateHndlr, &all_tp_ptr[1], &event_update_id); Sleep(100); THREAD_PROC_START(Event_DeleteHndlr, &all_tp_ptr[2], &event_del_id); Sleep(100);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -