Skip to content

Commit 5493bd6

Browse files
committed
ATRONIX: Add functions to update an event
This could optimize the event handling performance by removing duplicate events (cherry picked from commit 6142624)
1 parent 9132147 commit 5493bd6

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/core/a-lib.c

+26
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,32 @@ extern int Do_Callback(REBSER *obj, u32 name, RXIARG *args, RXIARG *result);
498498
return 0;
499499
}
500500

501+
/***********************************************************************
502+
**
503+
*/ RL_API int RL_Update_Event(REBEVT *evt)
504+
/*
505+
** Updates an application event (e.g. GUI) to the event port.
506+
**
507+
** Returns:
508+
** Returns 1 if updated, or 0 if event appended, and -1 if full.
509+
** Arguments:
510+
** evt - A properly initialized event structure. The
511+
** model and type of the event are used to address
512+
** the unhandled event in the queue, when it is found,
513+
** it will be replaced with this one
514+
**
515+
***********************************************************************/
516+
517+
{
518+
REBVAL *event = Find_Event(evt->model, evt->type);
519+
520+
if (event) {
521+
event->data.event = *evt;
522+
return 1;
523+
}
524+
525+
return RL_Event(evt) - 1;
526+
}
501527

502528
RL_API void *RL_Make_Block(u32 size)
503529
/*

src/core/p-event.c

+28
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,35 @@ REBREQ *req; //!!! move this global
9696

9797
return value;
9898
}
99+
/***********************************************************************
100+
**
101+
*/ REBVAL *Find_Event (REBINT model, REBINT type)
102+
/*
103+
** Find the event in the queue by the model and type
104+
** Return a pointer to the event value.
105+
**
106+
**
107+
***********************************************************************/
108+
{
109+
REBVAL *port;
110+
REBVAL *value;
111+
REBVAL *state;
112+
113+
port = Get_System(SYS_PORTS, PORTS_SYSTEM);
114+
if (!IS_PORT(port)) return NULL; // verify it is a port object
99115

116+
// Get queue block:
117+
state = VAL_BLK_SKIP(port, STD_PORT_STATE);
118+
if (!IS_BLOCK(state)) return NULL;
119+
for(value = VAL_BLK(state); value != VAL_BLK_TAIL(state); ++ value){
120+
if (VAL_EVENT_MODEL(value) == model
121+
&& VAL_EVENT_TYPE(value) == type){
122+
return value;
123+
}
124+
}
125+
126+
return NULL;
127+
}
100128

101129
/***********************************************************************
102130
**

0 commit comments

Comments
 (0)