From 63a28a9514d089a8061e986ab240e4574ff50aa4 Mon Sep 17 00:00:00 2001 From: siddhant Date: Thu, 19 Mar 2026 13:24:41 +0000 Subject: [PATCH] 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 Co-committed-by: siddhant --- vxworks-6.9/target/src/os/Makefile | 2 +- vxworks-6.9/target/src/os/vxtss.c | 143 +++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 vxworks-6.9/target/src/os/vxtss.c diff --git a/vxworks-6.9/target/src/os/Makefile b/vxworks-6.9/target/src/os/Makefile index af463e14..8ab9824d 100644 --- a/vxworks-6.9/target/src/os/Makefile +++ b/vxworks-6.9/target/src/os/Makefile @@ -179,7 +179,7 @@ OBJS_COMMON= classLib.o clockLib.o coprocLib.o coprocFuncBind.o copyright.o \ objFuncBind.o objLib.o objSymLib.o pmLib.o \ rebootLib.o rebootHookLib.o kernelBaseLib.o sigFuncBind.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 # with MEM_ALLOT because they use malloc/free. diff --git a/vxworks-6.9/target/src/os/vxtss.c b/vxworks-6.9/target/src/os/vxtss.c new file mode 100644 index 00000000..79e3ad61 --- /dev/null +++ b/vxworks-6.9/target/src/os/vxtss.c @@ -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 +#include +#include +#include +#include +#include +#include + +/* 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; + } +}