implement tss_ routines using vx6.9 tasking model along and call_once() function (#12)
Reviewed-on: http://13.234.246.121:3000/Neominds/ossl35vx69/pulls/12 Co-authored-by: siddhant <siddhant.singh@neominds.in> Co-committed-by: siddhant <siddhant.singh@neominds.in>
This commit is contained in:
@@ -179,7 +179,7 @@ OBJS_COMMON= classLib.o clockLib.o coprocLib.o coprocFuncBind.o copyright.o \
|
|||||||
objFuncBind.o objLib.o objSymLib.o pmLib.o \
|
objFuncBind.o objLib.o objSymLib.o pmLib.o \
|
||||||
rebootLib.o rebootHookLib.o kernelBaseLib.o sigFuncBind.o \
|
rebootLib.o rebootHookLib.o kernelBaseLib.o sigFuncBind.o \
|
||||||
taskHookShow.o timerLib.o timerShow.o trcLib.o vxAtomicLib.o \
|
taskHookShow.o timerLib.o timerShow.o trcLib.o vxAtomicLib.o \
|
||||||
vxMemProbeLib.o vxCpuLib.o vxIpiLib.o
|
vxMemProbeLib.o vxCpuLib.o vxIpiLib.o vxtss.o
|
||||||
|
|
||||||
# Handle modules & subdirs that are incompatible
|
# Handle modules & subdirs that are incompatible
|
||||||
# with MEM_ALLOT because they use malloc/free.
|
# with MEM_ALLOT because they use malloc/free.
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
/* vxtssLib.c - vxworks threads-specific storage */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Wind River Systems, Inc.
|
||||||
|
*
|
||||||
|
* The right to copy, distribute, modify or otherwise make use
|
||||||
|
* of this software may be licensed only pursuant to the terms
|
||||||
|
* of an applicable Wind River license agreement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
modification history
|
||||||
|
--------------------
|
||||||
|
13mar26,ssp created
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
DESCRIPTION
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <vxWorks.h>
|
||||||
|
#include <taskLib.h>
|
||||||
|
#include <semLib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <sysLib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <vxAtomicLib.h>
|
||||||
|
|
||||||
|
/* Macro for static initialization */
|
||||||
|
#define CRYPTO_ONCE_INIT { FALSE, NULL }
|
||||||
|
|
||||||
|
#define tss_t int
|
||||||
|
#define TSS_TASK_PRIORITY 50
|
||||||
|
|
||||||
|
typedef void (*tss_dtor_t)(void*);
|
||||||
|
|
||||||
|
/* Equivalent to CRYPTO_ONCE */
|
||||||
|
typedef struct {
|
||||||
|
BOOL done;
|
||||||
|
SEM_ID sem;
|
||||||
|
} CRYPTO_ONCE;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void *var; /* pointer to the task-specific variable */
|
||||||
|
tss_dtor_t dtor; /* optional destructor */
|
||||||
|
} tss_entry_t;
|
||||||
|
|
||||||
|
/* Internal pthread_once-like routine */
|
||||||
|
static STATUS crypto_once(CRYPTO_ONCE *once_control, void (*init_routine)(void))
|
||||||
|
{
|
||||||
|
/* Lazy init of semaphore */
|
||||||
|
if (once_control->sem == NULL) {
|
||||||
|
once_control->sem = semBCreate(SEM_Q_PRIORITY, SEM_FULL);
|
||||||
|
if (once_control->sem == NULL) {
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
semTake(once_control->sem, WAIT_FOREVER);
|
||||||
|
|
||||||
|
if (!once_control->done) {
|
||||||
|
init_routine();
|
||||||
|
once_control->done = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
semGive(once_control->sem);
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void call_once(CRYPTO_ONCE *once_control, void (*init_routine)(void))
|
||||||
|
{
|
||||||
|
crypto_once(once_control, init_routine);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
tss_create(tss_t *key, tss_dtor_t destructor) {
|
||||||
|
if (!key) return ERROR;
|
||||||
|
|
||||||
|
/* Allocate a slot for the variable */
|
||||||
|
tss_entry_t *entry = (tss_entry_t*) malloc(sizeof(tss_entry_t));
|
||||||
|
if (!entry) return ERROR;
|
||||||
|
|
||||||
|
entry->var = malloc(sizeof(void*)); /* storage for per-task value */
|
||||||
|
if (!entry->var) {
|
||||||
|
free(entry);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry->dtor = destructor;
|
||||||
|
|
||||||
|
/* Register this variable with the current task */
|
||||||
|
if (__taskVarAdd(taskIdSelf(), (int*)entry->var) == ERROR) {
|
||||||
|
free(entry->var);
|
||||||
|
free(entry);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return a "key" (could be just the pointer cast to int) */
|
||||||
|
*key = (tss_t) entry;
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tss_delete(tss_t key) {
|
||||||
|
if (!key) return;
|
||||||
|
|
||||||
|
tss_entry_t *entry = (tss_entry_t*) key;
|
||||||
|
|
||||||
|
/* Remove the task variable association */
|
||||||
|
__taskVarDelete(taskIdSelf(), (int*)entry->var);
|
||||||
|
|
||||||
|
/* Free allocated storage */
|
||||||
|
free(entry->var);
|
||||||
|
free(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
tss_get(tss_t key)
|
||||||
|
{
|
||||||
|
long var=0;
|
||||||
|
|
||||||
|
if (__taskVarGet (key, &var) == ERROR)
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return (void*)var;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
tss_set(tss_t key, void *val)
|
||||||
|
{
|
||||||
|
long var=0;
|
||||||
|
|
||||||
|
if (__taskVarGet (key, &var) == ERROR)
|
||||||
|
return OK;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (__taskVarSet (key, &var, (long)val) == ERROR)
|
||||||
|
return ERROR;
|
||||||
|
else
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user