Saturday, July 13, 2013

Event Flag Vs Semaphore: Creation

① Difference between binary semaphore and event flag
In the synchronization context, the event flag resembles the binary semaphore. So, I would like to explore the exact difference between the binary semaphore and event flag.

Instead of 'initial resource count value' in semaphore, event flag has 'initial pattern value'. Otherwise, it is exactly same as creating semaphore.

② ITRON implementation to create event flag

ER cre_flg(ID fkgid, T_CFLG *pk_cflg)
{
        Check context. If called from ISR,
                return E_CTX;
        Sanity check on arguments
        Enter critical section (Interrupt Disable)
        Initialize internal structure with the arguments.
        Internal structure has one queue to order waiting tasks
        If (tasks are queued in FIFO order)
                Initialize queue as follows:
                ┏━━━━━┯━━━━━━┓
                ┃Queue       │Queue           ┃
                ┃[0]          │Tail               ┃
                ┗━━━━━┷━━━━━━┛
        else (tasks are queued as priority based)
                Initialize as follows (Max Pri is taken from configuration):
                ┏━━━━━━━━┯━━┯━━━━┯━━━━━━┓
                ┃Priority                   │1     │Max         │Queue          ┃
                ┃    0              │      │Pri           │Tail              ┃
                ┗━━━━━━━━┷━━┷━━━━┷━━━━━━┛
        Exit critical section (Interrupt Restore)
        return E_OK;
}

The semaphore related implementation has been explained in the previous posts under RTOS label. Please refer to that.
 

No comments: