Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| nicholassouchu:kernelgraphicsinterface [2022/06/10 02:35] – Import KgiMutex content KubilayKocak | nicholassouchu:kernelgraphicsinterface [2022/06/10 02:46] (current) – Finally, expand acronyms for page names KubilayKocak | ||
|---|---|---|---|
| Line 647: | Line 647: | ||
| The %%KgimAPI%% is part of KGI but strictly speaking, it is a lower level API interfaced to KGI thanks to the [[/ | The %%KgimAPI%% is part of KGI but strictly speaking, it is a lower level API interfaced to KGI thanks to the [[/ | ||
| + | |||
| + | ==== KGI Mutex API ==== | ||
| + | |||
| + | kgi_mutex_t | ||
| + | |||
| + | The kgi_mutex_t is an opaque structure. One shall use it with the following methods and never | ||
| + | access it directly. It is OS specific and its content, its size may vary from one platform to | ||
| + | another. | ||
| + | |||
| + | kgi_mutex_alloc() | ||
| + | |||
| + | Allocate a mutex. mtx must be null. The return parameter is 0 (KGI_EOK) in case of success. | ||
| + | |||
| + | If the mutex has to be owned in the context of event synchronisation | ||
| + | mechanisms, the number of different events has to be specified, otherwise | ||
| + | KGI_MUTEX_NOEVENT shall be passed. Anyway nb_event can't exceed the maximum number KGI_MUTEX_MAXEVENT. | ||
| + | |||
| + | < | ||
| + | kgi_u_t kgi_mutex_alloc( | ||
| + | |||
| + | /* Comment: pointer to the mutex to initialize */ | ||
| + | | ||
| + | |||
| + | /* Comment: max number of events */ | ||
| + | | ||
| + | </ | ||
| + | |||
| + | kgi_mutex_free() | ||
| + | |||
| + | Free a mutex. The mutex must have be done before free. | ||
| + | mtx is null when returning from this function. Memory allocated | ||
| + | for event management is also freed. | ||
| + | |||
| + | < | ||
| + | void kgi_mutex_free( | ||
| + | |||
| + | /* Comment: pointer to the mutex to free */ | ||
| + | | ||
| + | ); | ||
| + | </ | ||
| + | |||
| + | kgi_mutex_init() | ||
| + | |||
| + | Initialize a pre-allocated mutex. The name passed is used for debug etc. | ||
| + | |||
| + | < | ||
| + | void kgi_mutex_init( | ||
| + | |||
| + | /* Comment: pointer to the mutex to initialize */ | ||
| + | | ||
| + | |||
| + | /* Comment: name of the mutex */ | ||
| + | const char *name | ||
| + | ); | ||
| + | </ | ||
| + | |||
| + | kgi_mutex_done() | ||
| + | |||
| + | Release a mutex. Memory allocated for the mutex itself is not freed. | ||
| + | |||
| + | < | ||
| + | void kgi_mutex_done( | ||
| + | |||
| + | /* Comment: pointer to the mutex to release */ | ||
| + | | ||
| + | ); | ||
| + | </ | ||
| + | |||
| + | kgi_mutex_lock() | ||
| + | |||
| + | Lock the mutex. If the mutex is not free, the thread is blocked. | ||
| + | |||
| + | < | ||
| + | void kgi_mutex_lock( | ||
| + | |||
| + | /* Comment: pointer to the mutex to lock */ | ||
| + | | ||
| + | ); | ||
| + | </ | ||
| + | |||
| + | kgi_mutex_unlock() | ||
| + | |||
| + | Unlock the mutex previously locked. | ||
| + | |||
| + | < | ||
| + | void kgi_mutex_unlock( | ||
| + | |||
| + | /* Comment: pointer to the mutex to unlock */ | ||
| + | | ||
| + | ); | ||
| + | </ | ||
| + | |||
| + | kgi_mutex_wait() | ||
| + | |||
| + | Wait on event e.g unlock the mutex and add the thread to the list of waiting | ||
| + | threads on this event. When the thread is made runnable again, it owns the mutex. | ||
| + | |||
| + | Important: the mutex must be already locked by the current running thread when calling | ||
| + | kgi_mutex_wait(). | ||
| + | |||
| + | Callers are responsible for managing the relationship between event ids and their | ||
| + | signification. the event parameter can't exceed nb_events passed when the mutex was | ||
| + | initialized. | ||
| + | |||
| + | < | ||
| + | void kgi_mutex_wait( | ||
| + | |||
| + | /* Comment: pointer to the mutex hold */ | ||
| + | | ||
| + | |||
| + | /* Comment: the event to wait on */ | ||
| + | | ||
| + | ); | ||
| + | </ | ||
| + | |||
| + | kgi_mutex_signal() | ||
| + | |||
| + | Wakeup threads waiting on an event to occur with mutex ownership. | ||
| + | If unblock_all is TRUE then unblock all waiters otherwise only one. | ||
| + | |||
| + | < | ||
| + | void kgi_mutex_signal( | ||
| + | |||
| + | /* Comment: pointer to the mutex processes are blocked on */ | ||
| + | | ||
| + | |||
| + | /* Comment: event to signal */ | ||
| + | | ||
| + | |||
| + | /* Comment: 1 = unblock all processes waiting on the mutex, 0 = unblock only the next one */ | ||
| + | int unblock_all | ||
| + | ); | ||
| + | </ | ||
| ---- | ---- | ||