임베디드/[ RTOS ]

[ RTOS ] 06. ThreadX의 Event Flags

kim.svadoz 2021. 4. 4. 12:56
728x90
반응형

Event Flags

Event flags provide a powerful tool for thread synchronization. Each event flag is represented by a single bit. Event flags are arranged in groups of 32.

Threads can operate on all 32 event flags in a group at the same time. Events are set by tx_event_flags_set and are retrieved by tx_event_flags_get.

Setting event flags is done with a logical AND/OR operation between the current event flags and the new event flags. The type of logical operation (either an AND or OR) is specified in the tx_event_flags_set call.

There are similar logical options for retrieval of event flags. A get request can specify that all specified event flags are required (a logical AND). Alternatively, a get request can specify that any of the specified event flags will satisfy the request (a logical OR). The type of logical operation associated with event flag retrieval is specified in the tx_event_flags_get call.

Event flags that satisfy a get request are consumed, i.e. set to zero, if TX_OR_CLEAR or TX_AND_CLEAR are specified by the request.

Each event flag group is a public resource. ThreadX places no constraints on how event flag groups are used.

이벤트 플래그는 스레드 동기화를위한 강력한 도구를 제공합니다. 각 이벤트 플래그는 단일 비트로 표시됩니다. 이벤트 플래그는 32 개 그룹으로 정렬됩니다.

스레드는 한 그룹의 모든 32 개 이벤트 플래그에서 동시에 작동 할 수 있습니다. 이벤트는 tx_event_flags_set에 의해 설정되고 tx_event_flags_get에 의해 검색됩니다.

이벤트 플래그 설정은 현재 이벤트 플래그와 새 이벤트 플래그 사이의 논리적 AND / OR 연산으로 수행됩니다. 논리 연산 유형 (AND 또는 OR)은 tx_event_flags_set 호출에 지정됩니다.

이벤트 플래그 검색을위한 유사한 논리적 옵션이 있습니다. get 요청은 지정된 모든 이벤트 플래그가 필요함을 지정할 수 있습니다 (논리적 AND). 또는 get 요청은 지정된 이벤트 플래그 중 하나가 요청을 충족하도록 지정할 수 있습니다 (논리적 OR). 이벤트 플래그 검색과 관련된 논리적 연산의 유형은 tx_event_flags_get 호출에 지정됩니다.

get 요청을 충족하는 이벤트 플래그가 사용됩니다. 즉, TX_OR_CLEAR 또는 TX_AND_CLEAR가 요청에 의해 지정된 경우 0으로 설정됩니다.

각 이벤트 플래그 그룹은 공용 자원입니다. ThreadX는 이벤트 플래그 그룹이 사용되는 방법에 제한을 두지 않습니다.

  • Creating Event Flag Groups

Event flag groups are created either during initialization or during run-time by application threads. At time of their creation, all event flags in the group are set to zero. There are no limits on the number of event flag groups in an application.

이벤트 플래그 그룹은 초기화 중에 또는 런타임 중에 애플리케이션 스레드에 의해 작성됩니다. 생성시 그룹의 모든 이벤트 플래그는 0으로 설정됩니다. 애플리케이션의 이벤트 플래그 그룹 수에는 제한이 없습니다.

  • Thread Suspension

Application threads can suspend while attempting to get any logical combination of event flags from a group. Once an event flag is set, the get requests of all suspended threads are reviewed. All the threads that now have the required event flags are resumed.

It is important to emphasize that all suspended threads on an event flag group are reviewed when its event flags are set. This, of course, introduces additional overhead. Therefore, it is generally good practice to limit the number of threads using the same event flag group to a reasonable number

그룹에서 이벤트 플래그의 논리적 조합을 가져 오는 동안 애플리케이션 스레드가 일시 중단 될 수 있습니다. 이벤트 플래그가 설정되면 일시 중단 된 모든 스레드의 가져 오기 요청이 검토됩니다. 이제 필수 이벤트 플래그가있는 모든 스레드가 재개됩니다.

이벤트 플래그가 설정 될 때 이벤트 플래그 그룹에서 일시 중단 된 모든 스레드가 검토된다는 점을 강조하는 것이 중요합니다. 물론 이것은 추가적인 오버 헤드를 야기합니다. 따라서 일반적으로 동일한 이벤트 플래그 그룹을 사용하는 스레드 수를 적절한 수로 제한하는 것이 좋습니다.

  • Event Flag Group Control Block

The characteristics of each event flag group are found in its control block. It contains information such as the current event flag settings and the number of threads suspended for events. This structure is defined in the tx_api.h file.

Event group control blocks can be located anywhere in memory, but it is most common to make the control block a global structure by defining it outside the scope of any function.

각 이벤트 플래그 그룹의 특성은 제어 블록에서 찾을 수 있습니다. 여기에는 현재 이벤트 플래그 설정 및 이벤트에 대해 일시 중단 된 스레드 수와 같은 정보가 포함됩니다. 이 구조는 tx_api.h 파일에 정의되어 있습니다.

이벤트 그룹 제어 블록은 메모리의 어느 위치 에나 위치 할 수 있지만 모든 기능의 범위 밖에서 정의하여 제어 블록을 글로벌 구조로 만드는 것이 가장 일반적입니다.

728x90
반응형