ThreadContext

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.

Summary
ThreadContextDefines the global (thread local) context of a running system thread.
CopyrightThis program is free software.
Files
C-kern/api/context/threadcontext.hHeader file ThreadContext.
C-kern/context/threadcontext.cImplementation file ThreadContext impl.
Types
struct threadcontext_tExport threadcontext_t.
Functions
test
unittest_context_threadcontextTest interface of threadcontext_t.
threadcontext_tStores services useable exclusively from one thread.
pcontextPoints to shared processcontext_t.
pagecacheThread local virtual memory page manager.
mmThread local memory manager.
syncrunThread local syncronous task support.
objectcacheThread local erorr object cache.
logThread local erorr log.
thread_idIdentification number which is incremented every time a thread is created.
initcountNumber of correct initialized objects.
lifetime
threadcontext_FREEStatic initializer for threadcontext_t.
threadcontext_INIT_STATICStatic initializer for threadcontext_t.
init_threadcontextCreates all top level services which are bound to a single thread.
free_threadcontextFrees all resources bound to this object.
query
isstatic_threadcontextReturns true if tcontext == threadcontext_INIT_STATIC.
change
resetthreadid_threadcontextResets the the thread id.
setmm_threadcontextOverwrites old mm_t of threadcontext_t with new_mm.

Copyright

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.

Author

© 2012 Jörg Seebohn

Files

C-kern/api/context/threadcontext.h

Header file ThreadContext.

C-kern/context/threadcontext.c

Implementation file ThreadContext impl.

Types

struct threadcontext_t

typedef struct threadcontext_t threadcontext_t

Export threadcontext_t.

Functions

test

unittest_context_threadcontext

int unittest_context_threadcontext(void)

Test interface of threadcontext_t.

threadcontext_t

struct threadcontext_t

Stores services useable exclusively from one thread.

Summary
pcontextPoints to shared processcontext_t.
pagecacheThread local virtual memory page manager.
mmThread local memory manager.
syncrunThread local syncronous task support.
objectcacheThread local erorr object cache.
logThread local erorr log.
thread_idIdentification number which is incremented every time a thread is created.
initcountNumber of correct initialized objects.
lifetime
threadcontext_FREEStatic initializer for threadcontext_t.
threadcontext_INIT_STATICStatic initializer for threadcontext_t.
init_threadcontextCreates all top level services which are bound to a single thread.
free_threadcontextFrees all resources bound to this object.
query
isstatic_threadcontextReturns true if tcontext == threadcontext_INIT_STATIC.
change
resetthreadid_threadcontextResets the the thread id.
setmm_threadcontextOverwrites old mm_t of threadcontext_t with new_mm.

pcontext

struct processcontext_t * pcontext

Points to shared processcontext_t.

pagecache

iobj_DECLARE(,
pagecache) pagecache

Thread local virtual memory page manager.

mm

iobj_DECLARE(,
mm) mm

Thread local memory manager.

syncrun

struct syncrun_t * syncrun

Thread local syncronous task support.

objectcache

iobj_DECLARE(,
objectcache) objectcache

Thread local erorr object cache.

log

iobj_DECLARE(,
log) log

Thread local erorr log.

thread_id

size_t thread_id

Identification number which is incremented every time a thread is created.  The main thread has id 1.  If SIZE_MAX is reached the value is wrapped around to number 2 which may be no more unique.

initcount

size_t initcount

Number of correct initialized objects.

lifetime

threadcontext_FREE

#define threadcontext_FREE { 0, iobj_FREE, iobj_FREE, 0, iobj_FREE, iobj_FREE, 0, 0 }

Static initializer for threadcontext_t.

threadcontext_INIT_STATIC

#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.

init_threadcontext

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.

free_threadcontext

int free_threadcontext(threadcontext_t *tcontext)

Frees all resources bound to this object.  This function is called from maincontext_t.free_maincontext.

query

isstatic_threadcontext

bool isstatic_threadcontext(const threadcontext_t *tcontext)

Returns true if tcontext == threadcontext_INIT_STATIC.

change

resetthreadid_threadcontext

void resetthreadid_threadcontext(void)

Resets the the thread id.  The next created thread will be assigned the id 2.  Call this function only in test situations.

setmm_threadcontext

void setmm_threadcontext(threadcontext_t *tcontext,
const struct mm_t *new_mm)

Overwrites old mm_t of threadcontext_t with new_mm.

Defines the global (thread local) context of a running system thread.
Implements the global (thread local) context of a running system thread.
typedef struct threadcontext_t threadcontext_t
Export threadcontext_t.
struct threadcontext_t
Stores services useable exclusively from one thread.
int unittest_context_threadcontext(void)
Test interface of threadcontext_t.
struct processcontext_t * pcontext
Points to shared processcontext_t.
struct processcontext_t
Defines computing environment / context which is shared between all threads of computation.
iobj_DECLARE(,
pagecache) pagecache
Thread local virtual memory page manager.
iobj_DECLARE(,
mm) mm
Thread local memory manager.
struct syncrun_t * syncrun
Thread local syncronous task support.
iobj_DECLARE(,
objectcache) objectcache
Thread local erorr object cache.
iobj_DECLARE(,
log) log
Thread local erorr log.
size_t thread_id
Identification number which is incremented every time a thread is created.
size_t initcount
Number of correct initialized objects.
#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.
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.
int free_threadcontext(threadcontext_t *tcontext)
Frees all resources bound to this object.
bool isstatic_threadcontext(const threadcontext_t *tcontext)
Returns true if tcontext == threadcontext_INIT_STATIC.
void resetthreadid_threadcontext(void)
Resets the the thread id.
void setmm_threadcontext(threadcontext_t *tcontext,
const struct mm_t *new_mm)
Overwrites old mm_t of threadcontext_t with new_mm.
int init_maincontext(const maincontext_e context_type,
int argc,
const char **argv)
Initializes global program context.
Used to switch between different implementations.
int free_maincontext(void)
Frees global context.
Close