A singleton called g_maincontext defines the global program context.
Main Program Context | A singleton called g_maincontext defines the global program context. |
Context Types | |
Accessing Context | The process context (processcontext_t) can be accessed with maincontext_t.pcontext_maincontext. |
Main Thread | The main thread which executes the function main() and which is created implicitly by the operating system must call the function maincontext_t.init_maincontext to initialize its processcontext_t and associated threadcontext_t. |
Other Threads | Any additional created thread must call <thread_t.init_threadcontext> at its beginning and <thread_t.free_threadcontext> at its end. |
Internal Workings | The function maincontext_t.init_maincontext calls processcontext_t.init_processcontext and threadcontext_t.init_threadcontext. |
Every service which can be accessed from the processcontext_t shall be programmed in thread safe way. Every service which is referenced only from threadcontext_t is already thread safe C-kern/api/maincontext.hcause only one thread calls this service. This means that every service in threadcontext_t must be duplicated for every running thread.
The process context (processcontext_t) can be accessed with maincontext_t.pcontext_maincontext. The returned process context is the same for every thread. The thread context (threadcontext_t) can be accessed with maincontext_t.tcontext_maincontext. Every thread has its own thread context.
The main thread which executes the function main() and which is created implicitly by the operating system must call the function maincontext_t.init_maincontext to initialize its processcontext_t and associated threadcontext_t.
The difference between the main and any other threads is that only the main thread calls maincontext_t.init_maincontext which in turn initializates all subsystems of the C-kernel. This initialization has to be done only once.
Before the main thread exits (after all other threads have exited) it should call maincontext_t.free_maincontext to make sure all resources are freed.
Any additional created thread must call <thread_t.init_threadcontext> at its beginning and <thread_t.free_threadcontext> at its end. The thread module implementation does this automatically. Use thread_t.new_thread and thread_t.delete_thread in this case.
The function maincontext_t.init_maincontext calls processcontext_t.init_processcontext and threadcontext_t.init_threadcontext.
The function processcontext_t.init_processcontext calls all functions with patterns
int initonce_NAME(void) int initonce_NAME(service_t**)
defined in any submodule in the same order as defined in “C-kern/resource/config/initprocess”.
The function threadcontext_t.init_threadcontext calls all functions with pattern
int initthread_NAME(service_t**)
defined in any submodule in the same order as defined in “C-kern/resource/config/initthread”.
This init database can be checked against the whole source tree with “C-kern/test/static/check_textdb.sh” - so that no entry is forgotten.
Defines computing environment / context which is shared between all threads of computation.
struct processcontext_t
Returns processcontext_t of the current process.
processcontext_t * pcontext_maincontext( void )
Initializes global program context.
int init_maincontext( const maincontext_e context_type, int argc, const char ** argv )
Initializes the current process context.
int init_processcontext( /*out*/processcontext_t * pcontext )
Creates all top level services which are bound to a single thread.
int init_threadcontext( /*out*/threadcontext_t * tcontext, struct processcontext_t * pcontext, uint8_t context_type )
Returns threadcontext_t of the current thread.
threadcontext_t * tcontext_maincontext( void )
Frees global context.
int free_maincontext( void )
Creates and starts a new system thread.
int new_thread( /*out*/thread_t ** threadobj, thread_f thread_main, void * main_arg )
Calls join_thread (if not already called) and deletes resources.
int delete_thread( thread_t ** threadobj )