ThreadContext impl

Implements the global (thread local) context of a running system thread.  See ThreadContext.

Summary
ThreadContext implImplements 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.
threadcontext_t
static variables
s_threadcontext_errtimerSimulates an error in <init_threadcontext>.
s_threadcontext_nextidThe next id which is assigned to threadcontext_t.thread_id.
helper
INITIOBJInitializes iobj.
FREEIOBJFrees iobj.
INITOBJECTInitializes object.
FREEOBJECTFrees object.
freehelperX_threadcontext
inithelperX_threadcontext
configruation
config_threadcontextAdapts tcontext to chosen maincontext_e type.
lifetime
query
change
test

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.

threadcontext_t

Summary
static variables
s_threadcontext_errtimerSimulates an error in <init_threadcontext>.
s_threadcontext_nextidThe next id which is assigned to threadcontext_t.thread_id.
helper
INITIOBJInitializes iobj.
FREEIOBJFrees iobj.
INITOBJECTInitializes object.
FREEOBJECTFrees object.
freehelperX_threadcontext
inithelperX_threadcontext
configruation
config_threadcontextAdapts tcontext to chosen maincontext_e type.
lifetime
query
change
test

static variables

s_threadcontext_errtimer

static test_errortimer_t s_threadcontext_errtimer

Simulates an error in <init_threadcontext>.

s_threadcontext_nextid

static size_t s_threadcontext_nextid

The next id which is assigned to threadcontext_t.thread_id.

helper

INITIOBJ

#define INITIOBJ(
   module,
   objtype_t,
   iobj
) int err ; memblock_t memobject = memblock_FREE ; if (! interface_##module()) { keep static object return 0 ; } ONERROR_testerrortimer( &s_threadcontext_errtimer, &err, ONABORT); err = ALLOCSTATIC_PAGECACHE( sizeof(objtype_t), &memobject) ; if (err) goto ONABORT ; objtype_t * newobj ; newobj = (objtype_t*) memobject.addr ; ONERROR_testerrortimer( &s_threadcontext_errtimer, &err, ONABORT); err = init_##module(newobj) ; if (err) goto ONABORT ; init_iobj(&(iobj), (void*)newobj, interface_##module()) ; return 0 ; ONABORT: FREESTATIC_PAGECACHE(&memobject) ; return err ;

Initializes iobj.  Calls ALLOCSTATIC_PAGECACHE to allocate memory.  This memory is initialized with call to init_##module() and the address is assigned to iobj.object.  The return value of interface_##module() is assigned to iobj.iimpl.

FREEIOBJ

#define FREEIOBJ(
   module,
   objtype_t,
   iobj,
   staticiobj
) int err ; int err2 ; objtype_t * delobj = (objtype_t*) (iobj).object ; if ((iobj).object != (staticiobj).object) { assert( interface_##module() == (iobj).iimpl) ; (iobj) = (staticiobj) ; err = free_##module(delobj) ; memblock_t memobject = memblock_INIT( sizeof(objtype_t), (uint8_t*)delobj) ; err2 = FREESTATIC_PAGECACHE(&memobject) ; if (err2) err = err2 ; return err ; } return 0 ;

Frees iobj.  Calls FREESTATIC_PAGECACHE to free memory as last operation.  Calls free_##module() to free the object iobj.object.  The return value of interface_##module() is checked against iobj.iimpl. iobj is cleared.  Calling it twice has no effect.

INITOBJECT

#define INITOBJECT(
   module,
   objtype_t,
   object
) int err ; memblock_t memobject = memblock_FREE; ONERROR_testerrortimer( &s_threadcontext_errtimer, &err, ONABORT); err = ALLOCSTATIC_PAGECACHE( sizeof(objtype_t), &memobject); if (err) goto ONABORT ; objtype_t * newobj ; newobj = (objtype_t*) memobject.addr; ONERROR_testerrortimer( &s_threadcontext_errtimer, &err, ONABORT); err = init_##module(newobj) ; if (err) goto ONABORT ; (object) = newobj ; return 0 ; ONABORT: FREESTATIC_PAGECACHE(&memobject) ; return err ;

Initializes object.  Calls ALLOCSTATIC_PAGECACHE to allocate memory.  This memory is initialized with call to init_##module() and the address is assigned to object.

FREEOBJECT

#define FREEOBJECT(
   module,
   objtype_t,
   object,
   staticobj
) int err ; int err2 ; objtype_t * delobj = (object) ; if (delobj != (staticobj)) { (object) = (staticobj) ; err = free_##module(delobj) ; memblock_t memobject = memblock_INIT( sizeof(objtype_t), (uint8_t*)delobj) ; err2 = FREESTATIC_PAGECACHE(&memobject) ; if (err2) err = err2 ; return err ; } return 0 ;

Frees object.  Calls FREESTATIC_PAGECACHE to free memory as last operation.  Calls free_##module() to free object and object is cleared.  Calling it twice has no effect.

freehelperX_threadcontext

  • Generated freehelper functions to free modules with calls to freethread_module.
  • Generated freehelper functions to free interfaceable objects with calls free_module.
  • Generated freehelper functions to free objects with calls free_module.

inithelperX_threadcontext

  • Generated inithelper functions to init modules with calls to initthread_module.
  • Generated inithelper functions to init interfaceable objects with calls init_module.
  • Generated inithelper functions to init objects with calls init_module.

configruation

config_threadcontext

static int config_threadcontext(threadcontext_t *tcontext,
maincontext_e context_type)

Adapts tcontext to chosen maincontext_e type.

lifetime

query

change

test

Defines the global (thread local) context of a running system thread.
Implements the global (thread local) context of a running system thread.
static test_errortimer_t s_threadcontext_errtimer
Simulates an error in init_threadcontext.
static size_t s_threadcontext_nextid
The next id which is assigned to threadcontext_t.thread_id.
size_t thread_id
Identification number which is incremented every time a thread is created.
#define INITIOBJ(
   module,
   objtype_t,
   iobj
) int err ; memblock_t memobject = memblock_FREE ; if (! interface_##module()) { keep static object return 0 ; } ONERROR_testerrortimer( &s_threadcontext_errtimer, &err, ONABORT); err = ALLOCSTATIC_PAGECACHE( sizeof(objtype_t), &memobject) ; if (err) goto ONABORT ; objtype_t * newobj ; newobj = (objtype_t*) memobject.addr ; ONERROR_testerrortimer( &s_threadcontext_errtimer, &err, ONABORT); err = init_##module(newobj) ; if (err) goto ONABORT ; init_iobj(&(iobj), (void*)newobj, interface_##module()) ; return 0 ; ONABORT: FREESTATIC_PAGECACHE(&memobject) ; return err ;
Initializes iobj.
#define FREEIOBJ(
   module,
   objtype_t,
   iobj,
   staticiobj
) int err ; int err2 ; objtype_t * delobj = (objtype_t*) (iobj).object ; if ((iobj).object != (staticiobj).object) { assert( interface_##module() == (iobj).iimpl) ; (iobj) = (staticiobj) ; err = free_##module(delobj) ; memblock_t memobject = memblock_INIT( sizeof(objtype_t), (uint8_t*)delobj) ; err2 = FREESTATIC_PAGECACHE(&memobject) ; if (err2) err = err2 ; return err ; } return 0 ;
Frees iobj.
#define INITOBJECT(
   module,
   objtype_t,
   object
) int err ; memblock_t memobject = memblock_FREE; ONERROR_testerrortimer( &s_threadcontext_errtimer, &err, ONABORT); err = ALLOCSTATIC_PAGECACHE( sizeof(objtype_t), &memobject); if (err) goto ONABORT ; objtype_t * newobj ; newobj = (objtype_t*) memobject.addr; ONERROR_testerrortimer( &s_threadcontext_errtimer, &err, ONABORT); err = init_##module(newobj) ; if (err) goto ONABORT ; (object) = newobj ; return 0 ; ONABORT: FREESTATIC_PAGECACHE(&memobject) ; return err ;
Initializes object.
#define FREEOBJECT(
   module,
   objtype_t,
   object,
   staticobj
) int err ; int err2 ; objtype_t * delobj = (object) ; if (delobj != (staticobj)) { (object) = (staticobj) ; err = free_##module(delobj) ; memblock_t memobject = memblock_INIT( sizeof(objtype_t), (uint8_t*)delobj) ; err2 = FREESTATIC_PAGECACHE(&memobject) ; if (err2) err = err2 ; return err ; } return 0 ;
Frees object.
static int config_threadcontext(threadcontext_t *tcontext,
maincontext_e context_type)
Adapts tcontext to chosen maincontext_e type.
Used to switch between different implementations.
Close