Implements the global (thread local) context of a running system thread. See ThreadContext.
ThreadContext impl | Implements 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. |
threadcontext_t | |
static variables | |
s_threadcontext_errtimer | Simulates an error in <init_threadcontext>. |
s_threadcontext_nextid | The next id which is assigned to threadcontext_t.thread_id. |
helper | |
INITIOBJ | Initializes iobj. |
FREEIOBJ | Frees iobj. |
INITOBJECT | Initializes object. |
FREEOBJECT | Frees object. |
freehelperX_threadcontext | |
inithelperX_threadcontext | |
configruation | |
config_threadcontext | Adapts tcontext to chosen maincontext_e type. |
lifetime | |
query | |
change | |
test |
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.
static variables | |
s_threadcontext_errtimer | Simulates an error in <init_threadcontext>. |
s_threadcontext_nextid | The next id which is assigned to threadcontext_t.thread_id. |
helper | |
INITIOBJ | Initializes iobj. |
FREEIOBJ | Frees iobj. |
INITOBJECT | Initializes object. |
FREEOBJECT | Frees object. |
freehelperX_threadcontext | |
inithelperX_threadcontext | |
configruation | |
config_threadcontext | Adapts tcontext to chosen maincontext_e type. |
lifetime | |
query | |
change | |
test |
static size_t s_threadcontext_nextid
The next id which is assigned to threadcontext_t.thread_id.
#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.
#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.
#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.
#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.
static int config_threadcontext( threadcontext_t * tcontext, maincontext_e context_type )
Adapts tcontext to chosen maincontext_e type.
Simulates an error in init_threadcontext.
static test_errortimer_t s_threadcontext_errtimer
The next id which is assigned to threadcontext_t.thread_id.
static size_t s_threadcontext_nextid
Identification number which is incremented every time a thread is created.
size_t thread_id
Initializes iobj.
#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 ;
Frees 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 ;
Initializes object.
#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 ;
Frees 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 ;
Adapts tcontext to chosen maincontext_e type.
static int config_threadcontext( threadcontext_t * tcontext, maincontext_e context_type )