Defines the global (thread local) context of a running system thread. If more than one thread is running in a process each thread has its own context. It contains references to services which belong only to one thread and therefore are not thread safe. They can not be shared between threads.
ThreadContext | Defines the global (thread local) context of a running system thread. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file ThreadContext. |
C-kern/ | Implementation file ThreadContext impl. |
Types | |
struct threadcontext_t | Export threadcontext_t. |
Functions | |
test | |
unittest_context_threadcontext | Test interface of threadcontext_t. |
threadcontext_t | Stores services useable exclusively from one thread. |
pcontext | Points to shared processcontext_t. |
pagecache | Thread local virtual memory page manager. |
mm | Thread local memory manager. |
syncrun | Thread local syncronous task support. |
objectcache | Thread local erorr object cache. |
log | Thread local erorr log. |
thread_id | Identification number which is incremented every time a thread is created. |
initcount | Number of correct initialized objects. |
lifetime | |
threadcontext_FREE | Static initializer for threadcontext_t. |
threadcontext_INIT_STATIC | Static initializer for threadcontext_t. |
init_threadcontext | Creates all top level services which are bound to a single thread. |
free_threadcontext | Frees all resources bound to this object. |
query | |
isstatic_threadcontext | Returns true if tcontext == threadcontext_INIT_STATIC. |
change | |
resetthreadid_threadcontext | Resets the the thread id. |
setmm_threadcontext | Overwrites old mm_t of threadcontext_t with new_mm. |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2012 Jörg Seebohn
Header file ThreadContext.
Implementation file ThreadContext impl.
typedef struct threadcontext_t threadcontext_t
Export threadcontext_t.
test | |
unittest_context_threadcontext | Test interface of threadcontext_t. |
int unittest_context_threadcontext( void )
Test interface of threadcontext_t.
struct threadcontext_t
Stores services useable exclusively from one thread.
pcontext | Points to shared processcontext_t. |
pagecache | Thread local virtual memory page manager. |
mm | Thread local memory manager. |
syncrun | Thread local syncronous task support. |
objectcache | Thread local erorr object cache. |
log | Thread local erorr log. |
thread_id | Identification number which is incremented every time a thread is created. |
initcount | Number of correct initialized objects. |
lifetime | |
threadcontext_FREE | Static initializer for threadcontext_t. |
threadcontext_INIT_STATIC | Static initializer for threadcontext_t. |
init_threadcontext | Creates all top level services which are bound to a single thread. |
free_threadcontext | Frees all resources bound to this object. |
query | |
isstatic_threadcontext | Returns true if tcontext == threadcontext_INIT_STATIC. |
change | |
resetthreadid_threadcontext | Resets the the thread id. |
setmm_threadcontext | Overwrites old mm_t of threadcontext_t with new_mm. |
struct processcontext_t * pcontext
Points to shared processcontext_t.
#define threadcontext_FREE { 0, iobj_FREE, iobj_FREE, 0, iobj_FREE, iobj_FREE, 0, 0 }
Static initializer for threadcontext_t.
#define threadcontext_INIT_STATIC { &g_maincontext.pcontext, iobj_FREE, iobj_FREE, 0, iobj_FREE, { 0, &g_logmain_interface }, 0, 0 }
Static initializer for threadcontext_t. These initializer ensures that in function main the global log service is available even without calling maincontext_t.init_maincontext first.
int init_threadcontext( /*out*/threadcontext_t * tcontext, struct processcontext_t * pcontext, uint8_t context_type )
Creates all top level services which are bound to a single thread. Services do not need to be multi thread safe cause a new one is created for every new thread. If a service shares information between threads then it must be programmed in a thread safe manner. This function is called from maincontext_t.init_maincontext. The parameter context_type is of type maincontext_e.
int free_threadcontext( threadcontext_t * tcontext )
Frees all resources bound to this object. This function is called from maincontext_t.free_maincontext.
bool isstatic_threadcontext( const threadcontext_t * tcontext )
Returns true if tcontext == threadcontext_INIT_STATIC.
Export threadcontext_t.
typedef struct threadcontext_t threadcontext_t
Stores services useable exclusively from one thread.
struct threadcontext_t
Test interface of threadcontext_t.
int unittest_context_threadcontext( void )
Points to shared processcontext_t.
struct processcontext_t * pcontext
Defines computing environment / context which is shared between all threads of computation.
struct processcontext_t
Thread local virtual memory page manager.
iobj_DECLARE( , pagecache ) pagecache
Thread local memory manager.
iobj_DECLARE( , mm ) mm
Thread local syncronous task support.
struct syncrun_t * syncrun
Thread local erorr object cache.
iobj_DECLARE( , objectcache ) objectcache
Thread local erorr log.
iobj_DECLARE( , log ) log
Identification number which is incremented every time a thread is created.
size_t thread_id
Number of correct initialized objects.
size_t initcount
Static initializer for threadcontext_t.
#define threadcontext_FREE { 0, iobj_FREE, iobj_FREE, 0, iobj_FREE, iobj_FREE, 0, 0 }
Static initializer for threadcontext_t.
#define threadcontext_INIT_STATIC { &g_maincontext.pcontext, iobj_FREE, iobj_FREE, 0, iobj_FREE, { 0, &g_logmain_interface }, 0, 0 }
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 )
Frees all resources bound to this object.
int free_threadcontext( threadcontext_t * tcontext )
Returns true if tcontext == threadcontext_INIT_STATIC.
bool isstatic_threadcontext( const threadcontext_t * tcontext )
Resets the the thread id.
void resetthreadid_threadcontext( void )
Overwrites old mm_t of threadcontext_t with new_mm.
void setmm_threadcontext( threadcontext_t * tcontext, const struct mm_t * new_mm )
Initializes global program context.
int init_maincontext( const maincontext_e context_type, int argc, const char ** argv )
Frees global context.
int free_maincontext( void )