而是透過 Event﹝Timer interrupt﹞來達成任務的分配
底下是一個簡單 create Event 的例子
這個 Event 綁定在 1 個 5 秒鐘會觸發 1 次的 Timer 上
不多說,直接來看範例
#include <Library/UefiBootServicesTableLib.h>
#include <stdio.h>
#include <time.h>
//-----------------------------------------------------------------------------
static int g_count = 1;
//-----------------------------------------------------------------------------
void printTime(void)
{
struct tm *t1;
time_t ret;
time(&ret);
ret += 8 * 60 * 60;
t1 = gmtime(&ret);
printf(
"[%04d-%02d-%02d %02d:%02d:%02d] %02d - in NotifyFunction \n",
t1->tm_year + 1900,
t1->tm_mon + 1,
t1->tm_mday,
t1->tm_hour,
t1->tm_min,
t1->tm_sec,
g_count
);
}
//-----------------------------------------------------------------------------
VOID EFIAPI
NotifyFunction(
IN EFI_EVENT Event,
IN VOID *Context
)
{
printTime();
g_count++;
}
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
EFI_EVENT event;
gBS->CreateEvent(
EVT_TIMER | EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
NotifyFunction,
NULL,
&event
);
// every 5 seconds to trigger
gBS->SetTimer(event, TimerPeriodic, 50000000);
do {
// wait NotifyFunction
} while(g_count < 10);
gBS->SetTimer(event, TimerCancel, 0);
gBS->CloseEvent(event);
return 0;
}