mirror of
https://github.com/eclipse-threadx/threadx.git
synced 2025-11-16 04:24:48 +00:00
Release 6.1.7
This commit is contained in:
1039
utility/execution_profile_kit/tx_execution_profile.c
Normal file
1039
utility/execution_profile_kit/tx_execution_profile.c
Normal file
File diff suppressed because it is too large
Load Diff
88
utility/execution_profile_kit/tx_execution_profile.h
Normal file
88
utility/execution_profile_kit/tx_execution_profile.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** ThreadX Component */
|
||||
/** */
|
||||
/** Execution Profile Kit */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
#ifndef TX_EXECUTION_PROFILE_H
|
||||
#define TX_EXECUTION_PROFILE_H
|
||||
|
||||
|
||||
/* The thread execution profile kit is designed to track thread execution time
|
||||
based on the hardware timer defined by TX_EXECUTION_TIME_SOURCE and
|
||||
TX_EXECUTION_MAX_TIME_SOURCE below. When the thread's total time reaches
|
||||
the maximum value, it remains there until the time is reset to 0 via a call
|
||||
to tx_thread_execution_time_reset. There are several assumptions to the
|
||||
operation of this kit, as follows:
|
||||
|
||||
1. The TX_EXECUTION_TIME_SOURCE and TX_EXECUTION_MAX_TIME_SOURCE macros are
|
||||
defined to utilize a local hardware time source.
|
||||
|
||||
2. The following routines are called from assembly code:
|
||||
VOID _tx_execution_thread_enter(void);
|
||||
VOID _tx_execution_thread_exit(void);
|
||||
VOID _tx_execution_isr_enter(void);
|
||||
VOID _tx_execution_isr_exit(void);
|
||||
|
||||
3. The ThreadX library must be rebuilt with TX_EXECUTION_PROFILE_ENABLE so
|
||||
the assembly code macros are enabled to call the execution profile routines.
|
||||
|
||||
4. Add tx_execution_profile.c to the application build. */
|
||||
|
||||
/* Define the basic time typedefs for 64-bit accumulation and a 32-bit timer source, which is the
|
||||
most common configuration. */
|
||||
|
||||
typedef unsigned long long EXECUTION_TIME;
|
||||
typedef unsigned long EXECUTION_TIME_SOURCE_TYPE;
|
||||
/* For 64-bit time source, the typedef would be: */
|
||||
/* typedef unsigned long long EXECUTION_TIME_SOURCE_TYPE; */
|
||||
|
||||
/* Define basic constants for the execution profile kit. */
|
||||
|
||||
/* Example for Cortex-M targets: */
|
||||
#ifndef TX_EXECUTION_TIME_SOURCE
|
||||
#define TX_EXECUTION_TIME_SOURCE (EXECUTION_TIME_SOURCE_TYPE) *((ULONG *) 0xE0001004)
|
||||
#endif
|
||||
#ifndef TX_EXECUTION_MAX_TIME_SOURCE
|
||||
#define TX_EXECUTION_MAX_TIME_SOURCE 0xFFFFFFFF
|
||||
#endif
|
||||
|
||||
/* For 64-bit time source, the constant would be: */
|
||||
/*#define TX_EXECUTION_TIME_SOURCE (EXECUTION_TIME_SOURCE_TYPE) *((unsigned long long *) 0xE0001004) */
|
||||
/*#define TX_EXECUTION_MAX_TIME_SOURCE 0xFFFFFFFFFFFFFFFF */
|
||||
|
||||
|
||||
/* Define APIs of the execution profile kit. */
|
||||
|
||||
struct TX_THREAD_STRUCT;
|
||||
VOID _tx_execution_thread_enter(void);
|
||||
VOID _tx_execution_thread_exit(void);
|
||||
VOID _tx_execution_isr_enter(void);
|
||||
VOID _tx_execution_isr_exit(void);
|
||||
UINT _tx_execution_thread_time_reset(struct TX_THREAD_STRUCT *thread_ptr);
|
||||
UINT _tx_execution_thread_total_time_reset(void);
|
||||
UINT _tx_execution_isr_time_reset(void);
|
||||
UINT _tx_execution_idle_time_reset(void);
|
||||
UINT _tx_execution_thread_time_get(struct TX_THREAD_STRUCT *thread_ptr, EXECUTION_TIME *total_time);
|
||||
UINT _tx_execution_thread_total_time_get(EXECUTION_TIME *total_time);
|
||||
UINT _tx_execution_isr_time_get(EXECUTION_TIME *total_time);
|
||||
UINT _tx_execution_idle_time_get(EXECUTION_TIME *total_time);
|
||||
|
||||
#endif
|
||||
157
utility/rtos_compatibility_layers/OSEK/demo_osek.c
Normal file
157
utility/rtos_compatibility_layers/OSEK/demo_osek.c
Normal file
@@ -0,0 +1,157 @@
|
||||
|
||||
#include <os.h>
|
||||
|
||||
/************************************************/
|
||||
/* Azure RTOS Implementation Specific */
|
||||
/************************************************/
|
||||
|
||||
/* Osek application definition. */
|
||||
APPLICATION_INFO Application1;
|
||||
|
||||
/* Task definition. */
|
||||
TaskType Task1;
|
||||
|
||||
/* Alarm definition. */
|
||||
AlarmType Alarm1;
|
||||
|
||||
/* Resource definition. */
|
||||
ResourceType Resource1;
|
||||
|
||||
/* Event definition. */
|
||||
EventMaskType Event1;
|
||||
|
||||
/* Counter definition. */
|
||||
CounterType SystemTimer;
|
||||
|
||||
/* Demo ISR definition. */
|
||||
ISRType DemoISR;
|
||||
|
||||
/* Task body declaration. */
|
||||
DeclareTask(Task1);
|
||||
|
||||
/* Demo ISR body declaration. */
|
||||
DeclareISR(DemoISR);
|
||||
|
||||
/* User hooks declarations. */
|
||||
static void ShutdownHook(StatusType Error);
|
||||
|
||||
static void PreTaskHook(void);
|
||||
|
||||
static void PostTaskHook(void);
|
||||
|
||||
static void StartupHook(void);
|
||||
|
||||
static void ErrorHook(StatusType Error);
|
||||
|
||||
|
||||
/* ThreadX timer for demo ISR. */
|
||||
TX_TIMER demo_isr_timer;
|
||||
|
||||
/* Entry function for the ThreadX timer. */
|
||||
VOID demo_isr_timer_entry(ULONG arg);
|
||||
|
||||
|
||||
/* Main function. */
|
||||
int main()
|
||||
{
|
||||
|
||||
tx_kernel_enter();
|
||||
|
||||
}
|
||||
ULONG free_memory[64*1024 / sizeof(ULONG)];
|
||||
|
||||
VOID tx_application_define(VOID * first_unused_memory)
|
||||
{
|
||||
|
||||
CHAR * pointer;
|
||||
|
||||
/* Put the first available address into character pointer. */
|
||||
pointer = (CHAR * )free_memory;
|
||||
|
||||
/* Setup hook pointers (optional). */
|
||||
Application1.shutdown_hook_handler = ShutdownHook;
|
||||
Application1.pretask_hook_handler = PreTaskHook;
|
||||
Application1.posttask_hook_handler = PostTaskHook;
|
||||
Application1.startup_hook_handler = StartupHook;
|
||||
Application1.error_hook_handler = ErrorHook;
|
||||
|
||||
/* Initialize a pointer. */
|
||||
osek_initialize(pointer,&Application1);
|
||||
|
||||
/* Create the system counter */
|
||||
SystemTimer = CreateCounter("SystemTimer", 0x7FFFFFFF, 2, 2, 0);
|
||||
DefineSystemCounter(SystemTimer);
|
||||
|
||||
/* Create the first Task. */
|
||||
Task1 = CreateTask("Task1", TaskEntry(Task1), 3, 1, 1024, NON, TRUE, EXTENDED, 0);
|
||||
|
||||
/* Create an event. */
|
||||
Event1 = CreateEvent();
|
||||
|
||||
/* Register Event1 to Task1. */
|
||||
RegisterEventtoTask(Event1 , Task1);
|
||||
|
||||
/* Create a resource. */
|
||||
Resource1 = CreateResource("Resource1", STANDARD, 0);
|
||||
|
||||
/* Register Resource1 to Task1. */
|
||||
RegisterTasktoResource(Resource1, Task1);
|
||||
|
||||
/* Create a demo ISR triggered by a ThreadX timer. */
|
||||
DemoISR = CreateISR("Demo ISR", ISREntry(DemoISR), CATEGORY2, 1024);
|
||||
|
||||
/* Create a ThreadX timer to simulate an ISR. */
|
||||
tx_timer_create(&demo_isr_timer, "Demo ISR timer", demo_isr_timer_entry, DemoISR,
|
||||
1000, 1000, TX_AUTO_ACTIVATE);
|
||||
|
||||
/* Start OSEK */
|
||||
StartOS(OSDEFAULTAPPMODE);
|
||||
|
||||
}
|
||||
|
||||
/* Task body. */
|
||||
TASK(Task1)
|
||||
{
|
||||
/* Task body. */
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/* Demo category 2 ISR function body. */
|
||||
ISR(DemoISR)
|
||||
{
|
||||
/* ISR body. */
|
||||
}
|
||||
|
||||
static void ShutdownHook(StatusType Error)
|
||||
{
|
||||
/* Hook body. */
|
||||
}
|
||||
|
||||
static void PreTaskHook(void)
|
||||
{
|
||||
/* Hook body. */
|
||||
}
|
||||
|
||||
static void PostTaskHook(void)
|
||||
{
|
||||
/* Hook body. */
|
||||
}
|
||||
|
||||
static void StartupHook(void)
|
||||
{
|
||||
/* Hook body. */
|
||||
}
|
||||
|
||||
static void ErrorHook(StatusType Error)
|
||||
{
|
||||
/* Hook body. */
|
||||
}
|
||||
|
||||
/* ThreadX timer handler to simulate an ISR. */
|
||||
VOID demo_isr_timer_entry(ULONG arg)
|
||||
{
|
||||
/* Call OSEK to process the ISR. */
|
||||
process_ISR2(arg);
|
||||
}
|
||||
941
utility/rtos_compatibility_layers/OSEK/os.h
Normal file
941
utility/rtos_compatibility_layers/OSEK/os.h
Normal file
@@ -0,0 +1,941 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** ThreadX Component */
|
||||
/** */
|
||||
/** OSEK IMPLEMENTATION */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* EKV DEFINITIONS RELEASE */
|
||||
/* */
|
||||
/* os.h PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This file defines the constants, structures, etc. needed for the */
|
||||
/* OSEK implementation. */
|
||||
/* */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TX_OSEK_H
|
||||
#define TX_OSEK_H
|
||||
|
||||
#include <tx_api.h>
|
||||
|
||||
#include "osek_user.h"
|
||||
|
||||
#ifdef TRUE
|
||||
#undef TRUE
|
||||
#endif
|
||||
|
||||
#ifdef FALSE
|
||||
#undef FALSE
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* System Macros. */
|
||||
/**************************************************************************/
|
||||
|
||||
#define TASK(Taskname) void Func ## Taskname()
|
||||
#define TaskEntry(Taskname) Func ## Taskname
|
||||
#define ALARM(Alarmname) void Func ## Alarmname()
|
||||
#define ISR(ISRname) void ISR_ ## ISRname()
|
||||
#define ISREntry(ISRname) ISR_ ## ISRname
|
||||
|
||||
#define ALARMCALLBACK(Alarmcallbackfunction) void Func ## Alarmcallbackfunction()
|
||||
#define ALARMCALLBACKEntry(Alarmcallbackfunction) Func ## Alarmcallbackfunction
|
||||
#define DeclareALARMCALLBACK(Alarmcallbackfunction) ALARMCALLBACK(Alarmcallbackfunction)
|
||||
|
||||
#define DeclareISR(ISRname) ISR(ISRname)
|
||||
#define DeclareResource(Resource_name)
|
||||
#define DeclareEvent(Event_name)
|
||||
#define DeclareAlarm(Alarmname) ALARM(Alarmname)
|
||||
#define DeclareTask(Taskname) TASK(Taskname)
|
||||
|
||||
#define CALL_ISR(ISRname) ISR_ ## ISRname()
|
||||
|
||||
#define OSErrorGetServiceId() service_GetServiceId.id
|
||||
#define OSError_ActivateTask_TaskID() service_ActivateTask.TaskID
|
||||
#define OSError_ChainTask_TaskID() service_ChainTask.TaskID
|
||||
#define OSError_GetAlarm_AlarmID() service_GetAlarm.AlarmID
|
||||
#define OSError_CancelAlarm_AlarmID() service_CancelAlarm.AlarmID
|
||||
#define OSError_SetAbsAlarm_AlarmID() service_SetAbsAlarm.AlarmID
|
||||
#define OSError_SetRelAlarm_AlarmID() service_SetRelAlarm.AlarmID
|
||||
#define OSError_GetResource_ResID() service_GetResource.ResID
|
||||
#define OSError_ReleaseResource_ResID() service_ReleaseResource.ResID
|
||||
#define OSError_SetEvent_TaskID() service_SetEvent.TaskID
|
||||
#define OSError_GetEvent_TaskID() service_SetEvent.TaskID
|
||||
#define OSError_WaitEvent_EventID() service_SetEvent.EventID
|
||||
#define OSError_ClearEvent_EventID() service_ClearEvent.EventID
|
||||
|
||||
/**************************************************************************/
|
||||
/* OSEK data Types */
|
||||
/**************************************************************************/
|
||||
|
||||
typedef ULONG STATUS;
|
||||
typedef void *VP;
|
||||
typedef void (* FP)();
|
||||
typedef ULONG PRI;
|
||||
typedef ULONG CounterType;
|
||||
typedef ULONG TaskType;
|
||||
typedef TaskType ISRType; /* TaskType and ISRType must be same as both often used interchangeably. */
|
||||
typedef ULONG TaskStateType;
|
||||
typedef ULONG *TaskStateRefType;
|
||||
typedef ULONG *TaskRefType;
|
||||
typedef ULONG TickType;
|
||||
typedef ULONG *TickRefType;
|
||||
typedef ULONG AppModeType;
|
||||
typedef ULONG AlarmType;
|
||||
typedef ULONG StatusType;
|
||||
typedef ULONG OsServiceIdType;
|
||||
typedef ULONG ResourceType;
|
||||
typedef ULONG *ResourceRefType;
|
||||
typedef ULONG EventMaskType;
|
||||
typedef ULONG *EventMaskRefType;
|
||||
typedef ULONG EventType;
|
||||
typedef ULONG *EventRefType;
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* OSEK Error Codes */
|
||||
/**************************************************************************/
|
||||
|
||||
#define E_OK (0U)
|
||||
#define E_OS_ACCESS (1U)
|
||||
#define E_OS_CALLEVEL (2U)
|
||||
#define E_OS_ID (3U)
|
||||
#define E_OS_LIMIT (4U)
|
||||
#define E_OS_NOFUNC (5U)
|
||||
#define E_OS_RESOURCE (6U)
|
||||
#define E_OS_STATE (7U)
|
||||
#define E_OS_VALUE (8U)
|
||||
|
||||
|
||||
/* Additional error codes defined for this Implementation. */
|
||||
|
||||
#define E_OS_EVENT (9U)
|
||||
#define E_OS_EXIST (10U) /* identical task name are found. */
|
||||
#define E_OS_SYSTEM (11U) /* Error for the OSEK system. */
|
||||
#define E_OS_SYS_STACK (12U) /* Error For OSEK Memory. */
|
||||
|
||||
/* osek_internal_error() error codes. */
|
||||
|
||||
#define THREADX_OBJECT_CREATION_ERROR (1U)
|
||||
#define THREADX_THREAD_RESUME_IN_ACTIVATE_TASK (2U)
|
||||
#define THREADX_PREEMPTION_CHANGE_GETRESOURCE (3U)
|
||||
#define THREADX_PREEMPTION_CHANGE_RLSRESOURCE (4U)
|
||||
#define THREADX_THREAD_TERMINATE_TERMINATETASK (5U)
|
||||
#define THREADX_THREAD_DELETE_TERMINATETASK (6U)
|
||||
#define THREADX_THREAD_TERMINATE_CHAINTASK (7U)
|
||||
#define THREADX_THREAD_DELETE_CHAINTASK (8U)
|
||||
#define THREADX_THREAD_DELETE_DELETETASK (9U)
|
||||
#define THREADX_THREAD_TERMINATE_DELETETASK (10U)
|
||||
#define THREADX_PREEMPTION_CHANGE_WRAPPER (11U)
|
||||
#define THREADX_THREAD_RELINQUISH_SCHEDULE (12U)
|
||||
#define THREADX_MUTEX_CREATERESOURCE (13U)
|
||||
#define THREADX_EVENT_SETEVENT (14U)
|
||||
#define THREADX_EVENT_CLEAREVENT (15U)
|
||||
#define THREADX_EVENT_FLAG_GETEVENT (16U)
|
||||
#define THREADX_EVENT_FLAG_WAITEVENT (17U)
|
||||
#define QUEUE_DELETETASK (18U)
|
||||
#define NO_FREE_EVENT (20U)
|
||||
#define SYSMGR_FATAL_ERROR (21U)
|
||||
#define EVENT_DELETETASK (22U)
|
||||
#define ERROR_FREEING_MEMORY (23U)
|
||||
#define SYS_MGR_SEND_CHAINTASK (24U)
|
||||
#define SYS_MGR_SEND_TERMINATETASK (25U)
|
||||
#define INVALID_ALARMID_TIMERWRAPPER (26U)
|
||||
#define TASK_ENDING_WITHOUT_CHAIN_OR_TERMINATE (27U)
|
||||
#define SYSMGR_QUEUE_SEND (28U)
|
||||
#define INVALID_OBJECT_CREATION_CALL (29U)
|
||||
#define SYS_MGR_START_OS (30U)
|
||||
#define SYS_MGR_SEND_ACTIVATETASK (31U)
|
||||
#define ERROR_OBJECT_CREATION (32U)
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* OSEM SYSTEM SERVICES IDs */
|
||||
/**************************************************************************/
|
||||
|
||||
#define OSServiceId_ActivateTask (1U)
|
||||
#define OSServiceId_TerminateTask (2U)
|
||||
#define OSServiceId_ChainTask (3U)
|
||||
#define OSServiceId_Schedule (4U)
|
||||
#define OSServiceId_GetTaskID (5U)
|
||||
#define OSServiceId_GetTaskState (6U)
|
||||
#define OSServiceId_DisableAllInterrupts (7U)
|
||||
#define OSServiceId_EnableAllInterrupts (8U)
|
||||
#define OSServiceId_SuspendAllInterrupts (9U)
|
||||
#define OSServiceId_ResumeAllInterrupts (10U)
|
||||
#define OSServiceId_SuspendOSInterrupts (11U)
|
||||
#define OSServiceId_ResumeOSInterrupts (12U)
|
||||
#define OSServiceId_GetResource (13U)
|
||||
#define OSServiceId_ReleaseResource (14U)
|
||||
#define OSServiceId_SetEvent (15U)
|
||||
#define OSServiceId_ClearEvent (16U)
|
||||
#define OSServiceId_GetEvent (17U)
|
||||
#define OSServiceId_WaitEvent (18U)
|
||||
#define OSServiceId_GetAlarmBase (19U)
|
||||
#define OSServiceId_GetAlarm (20U)
|
||||
#define OSServiceId_SetRelAlarm (21U)
|
||||
#define OSServiceId_SetAbsAlarm (22U)
|
||||
#define OSServiceId_CancelAlarm (23U)
|
||||
#define OSServiceId_GetActiveApplicationMode (24U)
|
||||
#define OSServiceId_StartOS (25U)
|
||||
#define OSServiceId_ShutdownOS (26U)
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* Implementation Specific OSEK operating modes */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
#define NORMAL_EXECUTION_MODE (0U)
|
||||
#define STARTUPHOOK_MODE (1U)
|
||||
#define SHUTDOWNHOOK_MODE (2U)
|
||||
#define PRETASKHOOK_MODE (3U)
|
||||
#define POSTTASKHOOK_MODE (4U)
|
||||
#define ERRORHOOK_MODE (5U)
|
||||
#define ISR1_MODE (6U)
|
||||
#define ISR2_MODE (7U)
|
||||
#define TIMER_MODE (8U)
|
||||
#define INITSYSTEM_MODE (9U)
|
||||
#define ALARM_CALLBACK_MODE (10U)
|
||||
#define OSEK_INIT_NOT_DONE (99U)
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* OSEK Constants and Definitions */
|
||||
/**************************************************************************/
|
||||
|
||||
/* OS APPLICATION MODES */
|
||||
|
||||
#define OSDEFAULTAPPMODE (1U)
|
||||
|
||||
|
||||
/* OSEK Task Types */
|
||||
|
||||
#define EXTENDED (1U)
|
||||
#define BASIC (0U)
|
||||
#define TRUE (1U)
|
||||
#define FALSE (0U)
|
||||
|
||||
|
||||
/* OSEK Task States */
|
||||
|
||||
#define RUNNING (0U)
|
||||
#define WAITING (1U)
|
||||
#define READY (2U)
|
||||
#define SUSPENDED (3U)
|
||||
#define THREADX_STATE (4U)
|
||||
|
||||
/* Invalid task id */
|
||||
#define INVALID_TASK (0U)
|
||||
|
||||
|
||||
/* ALARM OPERATION MODES */
|
||||
|
||||
#define ABSOLUTE_ALARM (1U)
|
||||
#define RELATIVE_ALARM (0U)
|
||||
#define AUTO_START (1U)
|
||||
#define NO_START (0U)
|
||||
|
||||
|
||||
/* RESOURCE TYPE */
|
||||
|
||||
#define STANDARD (0U)
|
||||
#define INTERNAL (1U)
|
||||
#define LINKED (2U)
|
||||
|
||||
typedef enum {NON, FULL} SCHEDULE;
|
||||
typedef enum {ACTIVATETASK, SETEVENT, CALLBACK, NONE} ACTION;
|
||||
typedef ULONG ACCR_TYPE;
|
||||
typedef ULONG TASK_TYPE;
|
||||
typedef ULONG COPY;
|
||||
typedef ULONG AUTOSTART;
|
||||
|
||||
|
||||
/* ISR types */
|
||||
|
||||
#define CATEGORY1 (1U)
|
||||
#define CATEGORY2 (2U)
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* SYSTEM CONFIGURATION PARAMETERS */
|
||||
/**************************************************************************/
|
||||
|
||||
/* OSEK Priority Definitions */
|
||||
|
||||
#define THREADX_MAX_PRIORITY (31U)
|
||||
#define THREADX_HIGHEST_PRIORITY (0U)
|
||||
#define THREADX_LOWEST_PRIORITY (31U)
|
||||
|
||||
#define OSEK_MAX_PRIORITY (23U)
|
||||
#define OSEK_HIGHEST_PRIORITY (OSEK_MAX_PRIORITY)
|
||||
#define OSEK_LOWEST_PRIORITY (0U)
|
||||
|
||||
#define OSEK_NON_SCHEDULE_PRIORITY (OSEK_HIGHEST_PRIORITY + 1u) /* 24 */
|
||||
#define OSEK_ISR2_PRIORITY (OSEK_NON_SCHEDULE_PRIORITY + 1u) /* 25 */
|
||||
#define OSEK_ISR1_PRIORITY (OSEK_ISR2_PRIORITY + 1u) /* 26 */
|
||||
|
||||
|
||||
/* Define maximum queued activation per task */
|
||||
|
||||
#define OSEK_MAX_ACTIVATION (8U)
|
||||
|
||||
/* Define maximum time count for Counters / Alarms */
|
||||
|
||||
#define MAXALLOWEDVALUE (0x7FFFFFFFUL)
|
||||
|
||||
#define OSEK_STACK_PADDING (128U)
|
||||
#define OSEK_SYSTEM_STACK_SIZE (1024U)
|
||||
|
||||
|
||||
/* Requests/commands to SysMgr task. */
|
||||
|
||||
#define SYSMGR_START_OS (0U)
|
||||
#define SYSMGR_TERMINATE_TASK (1U)
|
||||
#define SYSMGR_CHAIN_TASK (2U)
|
||||
#define SYSMGR_ACTIVATE_TASK (3U)
|
||||
#define SYSMGR_SCHEDULE (4U)
|
||||
#define SYSMGR_WAITEVENT (5U)
|
||||
#define SYSMGR_RELEASE_RESOURCE (6U)
|
||||
#define SYSMGR_SETEVENT (7U)
|
||||
#define SYSMGR_SHUTDOWN_OS (8U)
|
||||
#define SYSMGR_ERRORHOOK (9U)
|
||||
#define SYSMGR_GET_RESOURCE (10U)
|
||||
|
||||
/**************************************************************************/
|
||||
/* Define size of Region 0 memory segment. */
|
||||
/* NOTE: This region should be large enough to supply the memory */
|
||||
/* for all task stacks, TCBs, thread control blocks in the system. */
|
||||
/**************************************************************************/
|
||||
|
||||
#define TX_REGION0_SIZE (OSEK_MEMORY_SIZE)
|
||||
#define TX_REGION0_SIZE_IN_BYTES (TX_REGION0_SIZE)
|
||||
|
||||
|
||||
/**********************************************************************************/
|
||||
/* OSEK System Object maximum numbers */
|
||||
/* NOTE: These are only suggested values, user may modify them as needed. */
|
||||
/* Memory is the only limiting factor. */
|
||||
/**********************************************************************************/
|
||||
|
||||
/* Define the maximum number of simultaneous OSEK tasks supported. */
|
||||
/* Interrupt Service Routines are also treated as a task. */
|
||||
/* Total 8 Interrupt sources are supported. */
|
||||
/* That gives 24 max OSEK tasks. */
|
||||
|
||||
#define OSEK_MAX_TASKS (32U)
|
||||
|
||||
/* Define the maximum number of simultaneous Internal OSEK Resources supported. */
|
||||
|
||||
#define OSEK_MAX_INTERNAL_RES (8U)
|
||||
|
||||
|
||||
/* Define the maximum number of simultaneous External OSEK Resources supported. */
|
||||
|
||||
#define OSEK_MAX_EXTERNAL_RES (16U)
|
||||
|
||||
|
||||
/* Define the maximum number of simultaneous OSEK Resources (Internal & External Combined) supported. */
|
||||
|
||||
#define OSEK_MAX_RES (OSEK_MAX_INTERNAL_RES + OSEK_MAX_EXTERNAL_RES)
|
||||
|
||||
|
||||
/* Define the maximum number of simultaneous OSEK alarms supported. */
|
||||
|
||||
#define OSEK_MAX_ALARMS (16U)
|
||||
|
||||
|
||||
/* Define the maximum number of simultaneous OSEK counters supported. */
|
||||
/* This includes a counter to be assigned as a SystemTimer. */
|
||||
/* A system can have 8 alarms so 8 counters (one counter for each alarm) would be enough. */
|
||||
|
||||
#define OSEK_MAX_COUNTERS (16U)
|
||||
|
||||
|
||||
/* Define the maximum number of simultaneous OSEK events supported. */
|
||||
/* An event is just a bit , so a ULONG (32 bit data type) is used. */
|
||||
|
||||
#define OSEK_MAX_EVENTS (32U)
|
||||
|
||||
|
||||
/* Define the maximum number of OSEK ISR sources supported. */
|
||||
|
||||
#define OSEK_MAX_ISR (8U)
|
||||
|
||||
|
||||
/* Define OSEK Internal Task Queue depth per priority. */
|
||||
/* There is one such queue for each priority level. */
|
||||
/* What is the maximum number of tasks that can go in a queue? */
|
||||
/* Assuming that all tasks are of same priority and each task is activated to maximum */
|
||||
/* allowable limits (OSEK_MAX_ACTIVATION) it should be OSEK_MAX_ACTIVATION * OSEK_MAX_TASKS */
|
||||
/* but sometimes (READY)tasks are moved from queue to queue based on its changed ceiling priority */
|
||||
/* and that number could be equal to to maximum number of tasks supported. */
|
||||
|
||||
#define TASK_QUEUE_DEPTH1 (OSEK_MAX_ACTIVATION * OSEK_MAX_TASKS)
|
||||
#define TASK_QUEUE_DEPTH (TASK_QUEUE_DEPTH1 + OSEK_MAX_TASKS)
|
||||
|
||||
#define SYSMGR_QUEUE_MSG_LENGTH (4U)
|
||||
#define SYSMGR_QUEUE_MSG_COUNT (OSEK_MAX_ALARMS)
|
||||
#define SYSMGR_QUEUE_DEPTH ((sizeof(ULONG)) * SYSMGR_QUEUE_MSG_COUNT)
|
||||
|
||||
#define SYSMGR_PRIORITY (0U)
|
||||
#define SYSMGR_THRESHOLD (0U)
|
||||
|
||||
|
||||
/**********************************************************************************/
|
||||
/* OSEK System Object identifier this is placed in the object's control structure */
|
||||
/**********************************************************************************/
|
||||
|
||||
#define OSEK_TASK_ID (0x1234ABCDUL)
|
||||
#define OSEK_ALARM_ID (0x4567ABCDUL)
|
||||
#define OSEK_COUNTER_ID (0xABCD1234UL)
|
||||
#define OSEK_EVENT_ID (0x1234FEDCUL)
|
||||
#define OSEK_RES_ID (0x5678CDEFUL)
|
||||
#define OSEK_APPLICATION_ID (0x789ABCDEUL)
|
||||
#define OSEK_ISR_ID (0x3456CDEFUL)
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* OSEK SYSTEM OBJECT CONTROL STRUCTURES */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/* OSEK SERVICES */
|
||||
|
||||
struct Service_ActivateTask
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_TerminateTask
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_ChainTask
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_Schedule
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_GetTaskID
|
||||
{
|
||||
TaskRefType TaskID;
|
||||
};
|
||||
|
||||
struct Service_GetTaskState
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_DisableAllInterrupts
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_EnableAllInterrupts
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_SuspendAllInterrupts
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_ResumeAllInterrupts
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_SuspendOSInterrupts
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_ResumeOSInterrupts
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_GetResource
|
||||
{
|
||||
ResourceType ResID;
|
||||
};
|
||||
|
||||
struct Service_ReleaseResource
|
||||
{
|
||||
ResourceType ResID;
|
||||
};
|
||||
|
||||
struct Service_SetEvent
|
||||
{
|
||||
StatusType EventID;
|
||||
TaskType TaskID;
|
||||
};
|
||||
|
||||
struct Service_ClearEvent
|
||||
{
|
||||
EventMaskType EventID;
|
||||
};
|
||||
|
||||
struct Service_GetEvent
|
||||
{
|
||||
StatusType EventID;
|
||||
TaskType TaskID;
|
||||
};
|
||||
|
||||
struct Service_WaitEvent
|
||||
{
|
||||
EventMaskType EventID;
|
||||
};
|
||||
|
||||
struct Service_GetAlarmBase
|
||||
{
|
||||
AlarmType AlarmID;
|
||||
};
|
||||
|
||||
struct Service_GetAlarm
|
||||
{
|
||||
AlarmType AlarmID;
|
||||
};
|
||||
|
||||
struct Service_SetRelAlarm
|
||||
{
|
||||
AlarmType AlarmID;
|
||||
TickType increment;
|
||||
TickType cycle;
|
||||
};
|
||||
|
||||
struct Service_SetAbsAlarm
|
||||
{
|
||||
AlarmType AlarmID;
|
||||
TickType start;
|
||||
TickType cycle;
|
||||
};
|
||||
|
||||
struct Service_CancelAlarm
|
||||
{
|
||||
AlarmType AlarmID;
|
||||
};
|
||||
|
||||
struct Service_GetActiveApplicationMode
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_StartOS
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_ShutdownOS
|
||||
{
|
||||
StatusType TaskID;
|
||||
};
|
||||
|
||||
struct Service_GetServiceId
|
||||
{
|
||||
OsServiceIdType id;
|
||||
};
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* OSEK Resource */
|
||||
/**************************************************************************/
|
||||
|
||||
typedef struct osek_resource_struct
|
||||
{
|
||||
/* Name. */
|
||||
const CHAR *name;
|
||||
|
||||
/* This Resource is in use. */
|
||||
ULONG res_in_use;
|
||||
|
||||
/* Ceiling priority of the resource. */
|
||||
UINT c_priority;
|
||||
|
||||
/* Task occupying this resource. */
|
||||
TaskType taskid;
|
||||
|
||||
/* Type. */
|
||||
StatusType type; /* Internal, External, Linked. */
|
||||
|
||||
/* Linked Resource. */
|
||||
|
||||
ResourceType linked_res; /* id of the resource , Linked with this res. */
|
||||
|
||||
ResourceType resolved_res; /* Id of the res linked to this , after all chained links. */
|
||||
|
||||
/* Resource Object id. */
|
||||
ULONG osek_res_id;
|
||||
|
||||
} OSEK_RESOURCE;
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* Task structure */
|
||||
/**************************************************************************/
|
||||
|
||||
typedef struct osek_tcb_struct
|
||||
{
|
||||
/* This task's ThreadX TCB. */
|
||||
TX_THREAD task;
|
||||
|
||||
/* Name. */
|
||||
const CHAR *name;
|
||||
|
||||
/* This field indicates if this task is in use. */
|
||||
ULONG tcb_in_use;
|
||||
|
||||
/* Task type BASIC or EXTENDED. */
|
||||
UINT task_type;
|
||||
|
||||
/* Task AUTOSTART mode. */
|
||||
UINT task_autostart;
|
||||
|
||||
/* Design time Scheduling policy of this Task. */
|
||||
SCHEDULE policy;
|
||||
|
||||
/* Task start address (entry point). */
|
||||
FP task_entry;
|
||||
|
||||
/* Design time task priority. */
|
||||
UINT org_prio;
|
||||
|
||||
|
||||
/* Current ThreadX thread preemption threshold. */
|
||||
UINT cur_threshold;
|
||||
|
||||
/* task stack size. */
|
||||
ULONG stack_size;
|
||||
|
||||
/* start address of the task stack. */
|
||||
CHAR *pStackBase;
|
||||
|
||||
|
||||
/* Task status Suspended/ Ready(Running). */
|
||||
ULONG suspended;
|
||||
|
||||
/* Wait status */
|
||||
ULONG waiting;
|
||||
|
||||
/* Task to be activated when this task calls ChainTask(). */
|
||||
TaskType task_to_chain;
|
||||
|
||||
/* Counter to indicate how many Resources are occupied. */
|
||||
ULONG res_ocp;
|
||||
|
||||
/* Maximum multiple activation allowed for this task. */
|
||||
UINT max_active;
|
||||
|
||||
/* Current (recorded) multiple activation requests. */
|
||||
UINT current_active;
|
||||
|
||||
/* List of Event assigned to this task. */
|
||||
EventMaskType events;
|
||||
|
||||
EventMaskType waiting_events;
|
||||
|
||||
EventMaskType set_events;
|
||||
|
||||
/* List of External resources assigned (Design time) to this task. */
|
||||
ResourceType external_resource_list[OSEK_MAX_EXTERNAL_RES];
|
||||
|
||||
/* List of External Resources currently occupied (Run time) by this task. */
|
||||
ResourceType external_resource_occuplied_list[OSEK_MAX_EXTERNAL_RES];
|
||||
|
||||
/* List of Internal resources assigned (Design Time) to this task. */
|
||||
ResourceType internal_resource_list[OSEK_MAX_INTERNAL_RES];
|
||||
|
||||
/* List of Internal Resources currently occupied (Run Time) by this task. */
|
||||
ResourceType internal_resource_occuplied_list[OSEK_MAX_INTERNAL_RES];
|
||||
|
||||
/* Internal Resource assigned or not. */
|
||||
UINT internal_res;
|
||||
|
||||
/* RES_SCHEDULER taken or not. */
|
||||
UINT resource_scheduler;
|
||||
|
||||
AppModeType task_Appl_Mode;
|
||||
|
||||
/* Task Object id. */
|
||||
ULONG osek_task_id;
|
||||
|
||||
} OSEK_TCB;
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* Counter */
|
||||
/**************************************************************************/
|
||||
|
||||
typedef struct OSEK_COUNTER_STRUCT
|
||||
{
|
||||
|
||||
/* Max. allowable value. */
|
||||
TickType maxallowedvalue;
|
||||
|
||||
/* Tick base multiplier. */
|
||||
TickType ticksperbase;
|
||||
|
||||
/* Minimum cyclic numbers of counter ticks allowed for a cyclic alarm. */
|
||||
TickType mincycle;
|
||||
|
||||
/* Name. */
|
||||
const CHAR* name;
|
||||
|
||||
/* This field indicates if this counter is in use. */
|
||||
UINT cntr_in_use;
|
||||
|
||||
/* Pre-count needed to increment main count by 1. */
|
||||
TickType sub_count;
|
||||
|
||||
/* Current counter value in ticks. */
|
||||
TickType counter_value;
|
||||
|
||||
/* Whether attached to system timer. */
|
||||
UINT system_timer;
|
||||
|
||||
/* List of all alarms attached to this counter. */
|
||||
AlarmType alarm_list[OSEK_MAX_ALARMS];
|
||||
|
||||
/* Counter object id. */
|
||||
ULONG osek_counter_id;
|
||||
|
||||
|
||||
}OSEK_COUNTER;
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* ALARM */
|
||||
/**************************************************************************/
|
||||
|
||||
typedef struct OSEK_ALARM_STRUCT
|
||||
{
|
||||
|
||||
/* Name. */
|
||||
const CHAR* name;
|
||||
|
||||
/* This field indicates if this entry is in use. */
|
||||
UINT alarm_in_use;
|
||||
|
||||
UINT occupied;
|
||||
|
||||
/* Max allowed value of count for this alarm depends on the counter to which this alarm is attached. */
|
||||
TickType max_allowed_value;
|
||||
|
||||
/* Cycles programmed depends on the counter to which this alarm is attached. */
|
||||
TickType min_cyc;
|
||||
|
||||
/* Tick base multiplier. */
|
||||
TickType ticks_per_base;
|
||||
|
||||
/* Cycles programmed for this alarm. */
|
||||
TickType cycle;
|
||||
|
||||
/* alarm expiration count. */
|
||||
|
||||
TickType expiration_count;
|
||||
|
||||
/* Alarm Callback function. */
|
||||
void (*alarm_callback)();
|
||||
|
||||
/* Alarm Activation. */
|
||||
UINT armed;
|
||||
|
||||
/* Alarm Action. */
|
||||
UINT action;
|
||||
|
||||
/* Attach task here. */
|
||||
OSEK_TCB* task;
|
||||
|
||||
/* Attach the counter. */
|
||||
OSEK_COUNTER *cntr;
|
||||
|
||||
/* Event to set in case of SET_EVENT action. The event bits should be 1
|
||||
to SET that EVENT of the task. */
|
||||
EventMaskType events;
|
||||
|
||||
/* Start up action. */
|
||||
UINT auto_start;
|
||||
|
||||
/* ALARM armed in relative mode or abs mode. */
|
||||
UINT rel_abs_mode;
|
||||
|
||||
/* Counter roll back flag for absolute alarm mode. */
|
||||
UINT counter_rollback;
|
||||
|
||||
/* Alarm object id. */
|
||||
ULONG osek_alarm_id;
|
||||
|
||||
} OSEK_ALARM;
|
||||
|
||||
|
||||
typedef struct USER_ALARM_STRUCT
|
||||
{
|
||||
|
||||
/* Max allowed value of count. */
|
||||
TickType maxallowedvalue;
|
||||
|
||||
/* Cycles. */
|
||||
TickType mincycle;
|
||||
|
||||
/* Tick base multiplier. */
|
||||
TickType ticksperbase;
|
||||
|
||||
}AlarmBaseType;
|
||||
|
||||
typedef AlarmBaseType *AlarmBaseRefType;
|
||||
|
||||
|
||||
typedef struct REGISTER_APPLICATION_STRUCT
|
||||
{
|
||||
|
||||
AppModeType application_mode;
|
||||
|
||||
/* ErrorHook. */
|
||||
void (*error_hook_handler)(StatusType);
|
||||
/* Startup hook. */
|
||||
void (*startup_hook_handler)();
|
||||
/* Shutdown Hook. */
|
||||
void (*shutdown_hook_handler)(StatusType);
|
||||
|
||||
void (*pretask_hook_handler)(void);
|
||||
|
||||
void (*posttask_hook_handler)(void);
|
||||
|
||||
/* Any errors generated while creating the application. */
|
||||
StatusType osek_object_creation_error;
|
||||
|
||||
|
||||
/* Application object ID. */
|
||||
ULONG osek_application_id;
|
||||
|
||||
|
||||
}APPLICATION_INFO;
|
||||
|
||||
typedef APPLICATION_INFO *APPLICATION_INFO_PTR;
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* OSEK API CALLS */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/* TASK MANAGEMENT */
|
||||
|
||||
StatusType ActivateTask(TaskType TaskId);
|
||||
StatusType GetTaskID(TaskType *TaskID);
|
||||
StatusType TerminateTask(void);
|
||||
StatusType ChainTask(TaskType TaskID);
|
||||
StatusType GetTaskState(TaskType TaskID, TaskStateRefType State);
|
||||
TaskType CreateTask(const CHAR *name, void(*entry_function)(), UINT priority, UINT max_activation,
|
||||
ULONG stack_size, SCHEDULE policy, AUTOSTART start, UINT, AppModeType mode);
|
||||
StatusType Schedule (void);
|
||||
|
||||
|
||||
/* RESOURCE MANAGEMENT */
|
||||
|
||||
ResourceType CreateResource(const CHAR *name, StatusType type, ResourceType linked_res);
|
||||
StatusType GetResource(ResourceType id);
|
||||
StatusType ReleaseResource(ResourceType id);
|
||||
StatusType RegisterTasktoResource(ResourceType Resource, TaskType TaskID);
|
||||
|
||||
/* EVENT MANAGEMENT */
|
||||
|
||||
StatusType SetEvent(TaskType task_id, EventMaskType mask);
|
||||
StatusType ClearEvent(EventMaskType mask);
|
||||
StatusType GetEvent(TaskType task_id, EventMaskRefType event);
|
||||
StatusType WaitEvent(EventMaskType mask);
|
||||
EventMaskType CreateEvent(void);
|
||||
StatusType RegisterEventtoTask(EventType eventid, TaskType TaskID);
|
||||
|
||||
/* INTERUUPT MANAGEMENT */
|
||||
|
||||
StatusType EnableInterrupt(void);
|
||||
StatusType DisableInterrupt(void);
|
||||
|
||||
StatusType GetInterruptDescriptor(UINT *mask);
|
||||
|
||||
void SuspendAllInterrupts(void);
|
||||
void ResumeAllInterrupts(void);
|
||||
|
||||
void SuspendOSInterrupts(void);
|
||||
void ResumeOSInterrupts(void);
|
||||
|
||||
void DisableAllInterrupts(void);
|
||||
void EnableAllInterrupts(void);
|
||||
|
||||
ISRType CreateISR(const CHAR *name, void(*entry_function)(), UINT category, ULONG stack_size);
|
||||
StatusType RegisterISRtoResource(ResourceType Resource, ISRType ISRID);
|
||||
|
||||
|
||||
/* COUNTER MANAGEMENT */
|
||||
|
||||
StatusType GetCounterValue(OSEK_COUNTER *counter_ptr, TickRefType ticks);
|
||||
CounterType CreateCounter(const CHAR *name, TickType max_allowed_value, TickType ticks_per_base,
|
||||
TickType min_cycle, TickType start_value);
|
||||
StatusType IncrCounter(CounterType cntr);
|
||||
StatusType DefineSystemCounter(CounterType cntr);
|
||||
|
||||
/* ALARM MANAGEMENT */
|
||||
|
||||
StatusType GetAlarmBase(AlarmType AlarmID, AlarmBaseRefType info);
|
||||
StatusType SetAbsAlarm(AlarmType AlarmID, TickType start, TickType cycle);
|
||||
StatusType SetRelAlarm(AlarmType AlarmID, TickType increment, TickType cycle);
|
||||
StatusType CancelAlarm(AlarmType AlarmID);
|
||||
StatusType GetAlarm(AlarmType AlarmID, TickRefType tick_ptr);
|
||||
AlarmType CreateAlarm(const CHAR *name, CounterType cntr, UINT action, ULONG events,
|
||||
TaskType task, void (*callback)(), UINT Startup, TickType Alarmtime, TickType Cycle);
|
||||
|
||||
/* OS MANAGEMENT */
|
||||
|
||||
UCHAR *osek_initialize(void *osek_memory, APPLICATION_INFO_PTR application1);
|
||||
UINT osek_cleanup(APPLICATION_INFO_PTR application1);
|
||||
void ShutdownOS(StatusType error);
|
||||
void StartOS(StatusType os_mode);
|
||||
AppModeType GetActiveApplicationMode(void);
|
||||
|
||||
|
||||
void process_ISR2(ISRType isrname);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* End of file ************************/
|
||||
54
utility/rtos_compatibility_layers/OSEK/osek_user.h
Normal file
54
utility/rtos_compatibility_layers/OSEK/osek_user.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** ThreadX Component */
|
||||
/** */
|
||||
/** OSEK User Specific */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* EKV DEFINITIONS RELEASE */
|
||||
/* */
|
||||
/* osek_user.h PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This files contains user configurable compile time paramteres for */
|
||||
/* the OSEK implementation. */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef OSEK_USER_H
|
||||
#define OSEK_USER_H
|
||||
|
||||
/* Set the size of the OSEK memory available for creating OSEK objects and tasks. */
|
||||
#define OSEK_MEMORY_SIZE (64U*1024U)
|
||||
|
||||
#endif
|
||||
|
||||
/******************************* End of file ************************/
|
||||
277
utility/rtos_compatibility_layers/OSEK/threadx_osek_readme.txt
Normal file
277
utility/rtos_compatibility_layers/OSEK/threadx_osek_readme.txt
Normal file
@@ -0,0 +1,277 @@
|
||||
Azure RTOS' OSEK compatibility layer for ThreadX
|
||||
|
||||
1. Installation
|
||||
|
||||
The OSEK compatibility layer for ThreadX is comprised of two files tx_osek.c and os.h
|
||||
which should be copied at a suitable location for inclusion into a ThreadX project. Refer
|
||||
to the ThreadX readme file for installation instructions for ThreadX.
|
||||
|
||||
|
||||
2. Building
|
||||
|
||||
Building the OSEK layer should be as simple as including the tx_osek.c and os.h file to
|
||||
an existing ThreadX project, making sure that the location of the os.h header is in the
|
||||
include paths. The OSEK layer requires that the ThreadX headers such as tx_api.h are
|
||||
reachable in the include paths as well.
|
||||
|
||||
|
||||
3. Initialization
|
||||
|
||||
The OSEK layer initialization can be performed either from the tx_application_define()
|
||||
during the ThreadX initialization or from a running ThreadX thread. It is strongly
|
||||
recommended to initialize and start the OSEK layer as soon as possible. Once started
|
||||
other ThreadX tasks and API call should not be used to prevent resource conflicts with
|
||||
OSEK.
|
||||
|
||||
The OSEK initialization has three phases. First the osek internal initialization which
|
||||
must be performed before calling any other OSEK API functions, by calling
|
||||
osek_initialize() passing it a pointer to the OSEK memory and the application structure.
|
||||
The size of the memory region passed to osek_initialize() must be set at compile time
|
||||
by adjusting the OSEK_MEMORY_SIZE define in osek_uart.h.
|
||||
|
||||
After having initialized the OSEK internally, the application can now create OSEK objects
|
||||
and link or assigned them as needed. See below for a list of object creation functions.
|
||||
|
||||
Finally, after all the objects are created and configured the OSEK layer can be started
|
||||
using StartOS(). Once started it is no longer possible to create or change any OSEK
|
||||
objects.
|
||||
|
||||
|
||||
4. OSEK shutdown and restart
|
||||
|
||||
The OSEK layer can be shutdown using the standard OSEK API ShutdownOS(). As an extension
|
||||
to the OSEK layer offers an osek_cleanup() function which can be used to cleanup and
|
||||
reset the OSEK layer allowing a subsequent restart without having to reset the CPU. This
|
||||
is primarily intended for testing.
|
||||
|
||||
|
||||
5. Hooks
|
||||
|
||||
The various hook routines available within OSEK can be set during initialization by
|
||||
setting the various handler members of the APPLICATION_INFO structure passed to
|
||||
osek_initialize(). See the OSEK documentation for the signature of those hook functions.
|
||||
|
||||
For example:
|
||||
|
||||
app.error_hook_handler = ErrorHook;
|
||||
app.startup_hook_handler = StartupHook;
|
||||
app.shutdown_hook_handler = ShutdownHook;
|
||||
app.pretask_hook_handler = PreTaskHook;
|
||||
app.posttask_hook_handler = PostTaskHook;
|
||||
|
||||
|
||||
6. Interrupts
|
||||
|
||||
As per the OSEK specification, category 1 ISRs are not affected by the OSEK layer
|
||||
execution and are not allowed to call any of the OSEK API. Those ISR are configured and
|
||||
processed just like any other interrupts under ThreadX. Category 2 ISR have to be
|
||||
created using CreateISR() as well as being registered and enable like a category 1 ISR.
|
||||
In the body of the low level ISR process_ISR2() must be called with the return value of
|
||||
the corresponding CreateISR() in argument. This will instruct the OSEK layer to schedule
|
||||
the category 2 ISR as soon as possible.
|
||||
|
||||
A category 2 ISR is made of two handlers, the one that process the hardware interrupt
|
||||
and the OSEK ISR body.
|
||||
|
||||
To define a category 2 ISR body use the standard ISR() macro as follows:
|
||||
|
||||
|
||||
ISRType DemoISR; /* ISR declaration. */
|
||||
|
||||
/* ISR body definition. */
|
||||
ISR(DemoISR)
|
||||
{
|
||||
/* ISR body. */
|
||||
}
|
||||
|
||||
|
||||
This ISR should be created during system initialization:
|
||||
|
||||
|
||||
DemoISR = CreateISR("Demo ISR", ISREntry(DemoISR), CATEGORY2, 1024);
|
||||
|
||||
|
||||
Once properly initialized the ISR can be triggered by calling process_ISR2 with the ISR
|
||||
name in argument from within the hardware ISR handler.
|
||||
|
||||
|
||||
void demo_isr_hardware_handler(void)
|
||||
{
|
||||
/* Call OSEK to process the ISR. */
|
||||
process_ISR2(DemoISR);
|
||||
}
|
||||
|
||||
|
||||
7. Implementation specific information
|
||||
|
||||
Since OSEK requires a static allocation methodology, the number of available OSEK object
|
||||
has to be limited at compile time. By default the following limits apply:
|
||||
|
||||
Maximum number of tasks: 32
|
||||
Maximum number of internal resources: 8
|
||||
Maximum number of external resources: 16
|
||||
Maximum number of alarms: 16
|
||||
Maximum number of counters: 16
|
||||
Maximum number of events: 32
|
||||
Maximum number of category 2 ISRs: 8
|
||||
Minimum OSEK task priority: 0
|
||||
Maximum OSEK task priority: 23
|
||||
Maximum alarm counter value: 0x7FFFFFFFUL
|
||||
Maximum task activation count: 8
|
||||
|
||||
8. Supported OSEK API
|
||||
|
||||
The ThreadX OSEK layer supports all the mandatory APIs specified in version 2.2.3 of
|
||||
the OSEK/VDK Operating System Specification.
|
||||
|
||||
Summary of the supported API, see the OSEK specification and tx_osek.c for the full
|
||||
details of each API.
|
||||
|
||||
TASK MANAGEMENT
|
||||
|
||||
DeclareTask
|
||||
ActivateTask
|
||||
TerminateTask
|
||||
ChainTask
|
||||
Schedule
|
||||
GetTaskID
|
||||
GetTaskState
|
||||
|
||||
INTERRUPT HANDLING
|
||||
|
||||
EnableAllInterrupts
|
||||
DisableAllInterrupts
|
||||
ResumeAllInterrupts
|
||||
SuspendAllInterrupts
|
||||
ResumeOSInterrupts
|
||||
SuspendOSInterrupts
|
||||
|
||||
RESOURCE MANAGEMENT
|
||||
|
||||
DeclareResource
|
||||
GetResource
|
||||
ReleaseResource
|
||||
|
||||
EVENT CONTROL
|
||||
|
||||
DeclareEvent
|
||||
SetEvent
|
||||
ClearEvent
|
||||
GetEvent
|
||||
WaitEvent
|
||||
|
||||
ALARMS
|
||||
|
||||
DeclareAlarm
|
||||
GetAlarmBase
|
||||
GetAlarm
|
||||
SetRelAlarm
|
||||
SetAbsAlarm
|
||||
CancelAlarm
|
||||
|
||||
EXECUTION CONTROL
|
||||
|
||||
GetActiveApplicationMode
|
||||
StartOS
|
||||
ShutdownOS
|
||||
|
||||
Hook Routines
|
||||
|
||||
ErrorHook
|
||||
PreTaskHook
|
||||
PostTaskHook
|
||||
StartupHook
|
||||
ShutdownHook
|
||||
|
||||
9. Object creation API
|
||||
|
||||
The various object creation and registration functions are as follows. See tx_osek.c for a
|
||||
detailed description of each function.
|
||||
|
||||
----
|
||||
CreateTask <20> Creates an OSEK task, the task is returned if successful.
|
||||
|
||||
TaskType CreateTask(CHAR *name,
|
||||
void(*entry_function)(),
|
||||
UINT priority,
|
||||
UINT max_activation,
|
||||
ULONG stack_size,
|
||||
SCHEDULE policy,
|
||||
AUTOSTART start,
|
||||
UINT type,
|
||||
AppModeType mode);
|
||||
|
||||
|
||||
----
|
||||
CreateResource - Creates an OSEK resource, the resource is returned if successful.
|
||||
|
||||
ResourceType CreateResource(const CHAR *name,
|
||||
StatusType type,
|
||||
ResourceType linked_res);
|
||||
|
||||
|
||||
----
|
||||
RegisterTasktoResource - Registers a task to a resource. The resource will be accessible
|
||||
by the registered task.
|
||||
|
||||
StatusType RegisterTasktoResource(ResourceType Resource,
|
||||
TaskType TaskID);
|
||||
|
||||
|
||||
----
|
||||
CreateEvent - Creates an event, the created event is returned if successful. Note that
|
||||
per the OSEK specification an absolute maximum of 32 events can be created.
|
||||
|
||||
EventMaskType CreateEvent(void);
|
||||
|
||||
|
||||
----
|
||||
RegisterEventtoTask - Register an event to a task. The event is now usable from that
|
||||
task. Note that an event can only be registered to a single task.
|
||||
|
||||
StatusType RegisterEventtoTask(EventType eventid,
|
||||
TaskType TaskID);
|
||||
|
||||
|
||||
----
|
||||
CreateISR - Creates an ISR.
|
||||
|
||||
ISRType CreateISR(const CHAR *name,
|
||||
void(*entry_function)(),
|
||||
UINT category,
|
||||
ULONG stack_size);
|
||||
|
||||
|
||||
----
|
||||
RegisterISRtoResource - Register an ISR to a resource. Note that ISR cannot be registered
|
||||
to category 1 ISRS.
|
||||
|
||||
StatusType RegisterISRtoResource(ResourceType Resource,
|
||||
ISRType ISRID);
|
||||
|
||||
|
||||
----
|
||||
CreateCounter - Creates a new counter.
|
||||
|
||||
CounterType CreateCounter(CHAR *name,
|
||||
TickType max_allowed_value,
|
||||
TickType ticks_per_base,
|
||||
TickType min_cycle,
|
||||
TickType start_value);
|
||||
|
||||
----
|
||||
DefineSystemCounter - Assign a counter to be used as the system counter.
|
||||
|
||||
StatusType DefineSystemCounter(CounterType cntr);
|
||||
|
||||
---
|
||||
CreateAlarm - Creates an alarm.
|
||||
|
||||
AlarmType CreateAlarm(CHAR *name,
|
||||
CounterType cntr,
|
||||
UINT action,
|
||||
ULONG events,
|
||||
TaskType task,
|
||||
void (*callback)(),
|
||||
UINT Startup, TickType Alarmtime,
|
||||
TickType Cycle);
|
||||
9113
utility/rtos_compatibility_layers/OSEK/tx_osek.c
Normal file
9113
utility/rtos_compatibility_layers/OSEK/tx_osek.c
Normal file
File diff suppressed because it is too large
Load Diff
220
utility/rtos_compatibility_layers/posix/errno.h
Normal file
220
utility/rtos_compatibility_layers/posix/errno.h
Normal file
@@ -0,0 +1,220 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** ThreadX Component */
|
||||
/** */
|
||||
/** POSIX Compliancy Wrapper (POSIX) */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* EKP DEFINITIONS RELEASE */
|
||||
/* */
|
||||
/* errno.h PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This file defines the constants, structures, etc.needed to */
|
||||
/* implement the Evacuation Kit for POSIX Users (POSIX) */
|
||||
/* */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef _ERRNO_H
|
||||
#define _ERRNO_H
|
||||
|
||||
|
||||
|
||||
#ifndef TX_POSIX_SOURCE
|
||||
#define errno posix_errno
|
||||
#endif
|
||||
|
||||
/* the POSIX standard does not impose particular values for errno.h */
|
||||
/* error codes between 200 and 1000 are not used by the Threadx wrapper */
|
||||
/* but supplied for completeness. */
|
||||
|
||||
|
||||
|
||||
|
||||
#define E2BIG 200
|
||||
|
||||
#define EACCES 13
|
||||
|
||||
#define EADDRINUSE 201
|
||||
|
||||
#define EADDRNOTAVAIL 202
|
||||
|
||||
#define EAFNOSUPPORT 203
|
||||
|
||||
#define EAGAIN 11
|
||||
|
||||
#define EALREADY 204
|
||||
|
||||
#define EBADF 9
|
||||
|
||||
#define EBADMSG 205
|
||||
|
||||
#define EBUSY 9999
|
||||
|
||||
#define ECANCELED 206
|
||||
|
||||
#define ECHILD 207
|
||||
|
||||
#define ECONNABORTED 208
|
||||
|
||||
#define ECONNREFUSED 209
|
||||
|
||||
#define ECONNRESET 210
|
||||
|
||||
#define EDEADLK 3333
|
||||
|
||||
#define EDESTADDRREQ 211
|
||||
|
||||
#define EDOM 212
|
||||
|
||||
#define EDQUOT 213
|
||||
|
||||
#define EEXIST 17
|
||||
|
||||
#define EFAULT 214
|
||||
|
||||
#define EFBIG 215
|
||||
|
||||
#define EHOSTUNREACH 216
|
||||
|
||||
#define EIDRM 217
|
||||
|
||||
#define EILSEQ 218
|
||||
|
||||
#define EINPROGRESS 219
|
||||
|
||||
#define EINTR 4
|
||||
|
||||
#define EINVAL 22
|
||||
|
||||
#define EIO 220
|
||||
|
||||
#define EISCONN 221
|
||||
|
||||
#define EISDIR 222
|
||||
|
||||
#define ELOOP 223
|
||||
|
||||
#define EMFILE 224
|
||||
|
||||
#define EMLINK 225
|
||||
|
||||
#define EMSGSIZE 36
|
||||
|
||||
#define EMULTIHOP 226
|
||||
|
||||
#define ENAMETOOLONG 26
|
||||
|
||||
#define ENETDOWN 227
|
||||
|
||||
#define ENETRESET 228
|
||||
|
||||
#define ENETUNREACH 229
|
||||
|
||||
#define ENFILE 230
|
||||
|
||||
#define ENOBUFS 231
|
||||
|
||||
#define ENODATA 232
|
||||
|
||||
#define ENODEV 233
|
||||
|
||||
#define ENOENT 2
|
||||
|
||||
#define ENOEXEC 234
|
||||
|
||||
#define ENOLCK 235
|
||||
|
||||
#define ENOLINK 236
|
||||
|
||||
#define ENOMEM 4444
|
||||
|
||||
#define ENOMSG 237
|
||||
|
||||
#define ENOPROTOOPT 238
|
||||
|
||||
#define ENOSPC 28
|
||||
|
||||
#define ENOSR 239
|
||||
|
||||
#define ENOSTR 240
|
||||
|
||||
#define ENOSYS 71
|
||||
|
||||
#define ENOTCONN 241
|
||||
|
||||
#define ENOTDIR 242
|
||||
|
||||
#define ENOTEMPTY 243
|
||||
|
||||
#define ENOTSOCK 244
|
||||
|
||||
#define ENOTSUP 126
|
||||
|
||||
#define ENOTTY 245
|
||||
|
||||
#define ENXIO 246
|
||||
|
||||
#define EOPNOTSUPP 247
|
||||
|
||||
#define EOVERFLOW 248
|
||||
|
||||
#define EPERM 2222
|
||||
|
||||
#define EPIPE 249
|
||||
|
||||
#define EPROTO 250
|
||||
|
||||
#define EPROTONOSUPPORT 251
|
||||
|
||||
#define EPROTOTYPE 252
|
||||
|
||||
#define ERANGE 253
|
||||
|
||||
#define EROFS 254
|
||||
|
||||
#define ESPIPE 255
|
||||
|
||||
#define ESRCH 3
|
||||
|
||||
#define ESTALE 256
|
||||
|
||||
#define ETIME 257
|
||||
|
||||
#define ETIMEDOUT 5555
|
||||
|
||||
#define ETXTBSY 258
|
||||
|
||||
#define EWOULDBLOCK 259
|
||||
|
||||
#define EXDEV 260
|
||||
|
||||
#endif
|
||||
93
utility/rtos_compatibility_layers/posix/fcntl.h
Normal file
93
utility/rtos_compatibility_layers/posix/fcntl.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** ThreadX Component */
|
||||
/** */
|
||||
/** POSIX Compliancy Wrapper (POSIX) */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* EKP DEFINITIONS RELEASE */
|
||||
/* */
|
||||
/* fcntl.h PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This file defines the constants, structures, etc.needed to */
|
||||
/* implement the Evacuation Kit for POSIX Users (POSIX) */
|
||||
/* */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef _FCNTL_H
|
||||
#define _FCNTL_H
|
||||
|
||||
#define O_ACCMODE 0x0003
|
||||
#define O_RDONLY 0x0000
|
||||
#define O_WRONLY 0x0001
|
||||
#define O_RDWR 0x0002
|
||||
#define O_APPEND 0x0008
|
||||
#define O_SYNC 0x0010
|
||||
#define O_NONBLOCK 0x0080
|
||||
#define O_CREAT 0x0100
|
||||
#define O_TRUNC 0x0200
|
||||
#define O_EXCL 0x0400
|
||||
#define O_NOCTTY 0x0800
|
||||
#define FASYNC 0x1000
|
||||
#define O_LARGEFILE 0x2000
|
||||
#define O_DIRECT 0x8000
|
||||
#define O_DIRECTORY 0x10000
|
||||
#define O_NOFOLLOW 0x20000
|
||||
|
||||
#define O_NDELAY O_NONBLOCK
|
||||
|
||||
#define F_DUPFD 0
|
||||
#define F_GETFD 1
|
||||
#define F_SETFD 2
|
||||
#define F_GETFL 3
|
||||
#define F_SETFL 4
|
||||
#define F_GETLK 14
|
||||
#define F_SETLK 6
|
||||
#define F_SETLKW 7
|
||||
|
||||
#define F_SETOWN 24
|
||||
#define F_GETOWN 23
|
||||
#define F_SETSIG 10
|
||||
#define F_GETSIG 11
|
||||
|
||||
#define FD_CLOEXEC 1
|
||||
|
||||
# define POSIX_FADV_NORMAL 0
|
||||
# define POSIX_FADV_RANDOM 1
|
||||
# define POSIX_FADV_SEQUENTIAL 2
|
||||
# define POSIX_FADV_WILLNEED 3
|
||||
# define POSIX_FADV_DONTNEED 4
|
||||
# define POSIX_FADV_NOREUSE 5
|
||||
|
||||
/* no flock structure for Threadx at this time */
|
||||
|
||||
#endif
|
||||
344
utility/rtos_compatibility_layers/posix/posix_demo.c
Normal file
344
utility/rtos_compatibility_layers/posix/posix_demo.c
Normal file
@@ -0,0 +1,344 @@
|
||||
/* This is a small demo of the POSIX Compliancy Wrapper for the high-performance ThreadX kernel. */
|
||||
/* It includes examples of six pthreads of different priorities, using a message queue, semaphore and mutex. */
|
||||
|
||||
#include "pthread.h"
|
||||
|
||||
#define DEMO_STACK_SIZE 2048
|
||||
#define MAX_MESSAGE_SIZE 50
|
||||
#define DEMO_BYTE_POOL_SIZE 9120
|
||||
|
||||
/* Define the POSIX pthread object control blocks ... */
|
||||
|
||||
pthread_t pthread_0;
|
||||
pthread_t pthread_1;
|
||||
pthread_t pthread_2;
|
||||
pthread_t pthread_3;
|
||||
pthread_t pthread_4;
|
||||
pthread_t pthread_5;
|
||||
|
||||
/* Define pthread attributes objects */
|
||||
|
||||
pthread_attr_t ptattr0;
|
||||
pthread_attr_t ptattr1;
|
||||
pthread_attr_t ptattr2;
|
||||
pthread_attr_t ptattr3;
|
||||
pthread_attr_t ptattr4;
|
||||
pthread_attr_t ptattr5;
|
||||
|
||||
|
||||
/* Define the message queue attribute. */
|
||||
|
||||
struct mq_attr queue_atrr;
|
||||
|
||||
/* Define a queue descriptor. */
|
||||
|
||||
mqd_t q_des;
|
||||
|
||||
/* Define a semaphore. */
|
||||
|
||||
sem_t *sem;
|
||||
|
||||
/* Define a mutex */
|
||||
|
||||
pthread_mutex_t mutex1;
|
||||
|
||||
/* Define a mutex attributes object */
|
||||
|
||||
pthread_mutexattr_t mta1;
|
||||
|
||||
|
||||
/* Define the counters used in this demo application... */
|
||||
|
||||
ULONG pthread_0_counter;
|
||||
ULONG pthread_1_counter;
|
||||
ULONG pthread_2_counter;
|
||||
ULONG pthread_3_counter;
|
||||
ULONG pthread_4_counter;
|
||||
ULONG pthread_5_counter;
|
||||
ULONG pthread_1_message_sent;
|
||||
ULONG pthread_2_message_received;
|
||||
|
||||
|
||||
/* Define pthread function prototypes. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *);
|
||||
VOID *pthread_1_entry(VOID *);
|
||||
VOID *pthread_2_entry(VOID *);
|
||||
VOID *pthread_3_entry(VOID *);
|
||||
VOID *pthread_4_entry(VOID *);
|
||||
VOID *pthread_5_entry(VOID *);
|
||||
|
||||
|
||||
/* Message to be sent. */
|
||||
CHAR *msg0 = "This is a test message";
|
||||
|
||||
/* Define main entry point. */
|
||||
|
||||
INT main()
|
||||
{
|
||||
|
||||
/* Enter the ThreadX kernel. */
|
||||
tx_kernel_enter();
|
||||
}
|
||||
|
||||
ULONG free_memory[192*1024 / sizeof(ULONG)];
|
||||
/* Define what the initial system looks like. */
|
||||
VOID tx_application_define(VOID *first_unused_memory)
|
||||
{
|
||||
|
||||
VOID* storage_ptr;
|
||||
|
||||
|
||||
struct sched_param param;
|
||||
|
||||
queue_atrr.mq_maxmsg = 124;
|
||||
queue_atrr.mq_msgsize = MAX_MESSAGE_SIZE;
|
||||
|
||||
|
||||
/* Init POSIX Wrapper */
|
||||
storage_ptr = (VOID*) posix_initialize(free_memory);
|
||||
|
||||
/* Put system definition stuff in here, e.g. pthread creates and other assoerted
|
||||
create information. */
|
||||
|
||||
/* Create pthread attributes for pthread 0 to pthread 5 */
|
||||
pthread_attr_init(&ptattr0);
|
||||
pthread_attr_init(&ptattr1);
|
||||
pthread_attr_init(&ptattr2);
|
||||
pthread_attr_init(&ptattr3);
|
||||
pthread_attr_init(&ptattr4);
|
||||
pthread_attr_init(&ptattr5);
|
||||
|
||||
/* Create a sched_param structure */
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
/* Now create all pthreads , firstly modify respective ptheread
|
||||
attribute with desired priority and stack start address and then create the pthread */
|
||||
|
||||
/* Create pthread 0. */
|
||||
param.sched_priority = 10;
|
||||
pthread_attr_setschedparam(&ptattr0, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr0, storage_ptr );
|
||||
storage_ptr = (int *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_0, &ptattr0,pthread_0_entry,NULL);
|
||||
|
||||
/* Create pthread 1. */
|
||||
param.sched_priority = 15;
|
||||
pthread_attr_setschedparam(&ptattr1, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr1, (VOID*) storage_ptr );
|
||||
storage_ptr = (int *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_1, &ptattr1,pthread_1_entry,NULL);
|
||||
|
||||
/* Create pthread 2. */
|
||||
param.sched_priority = 20;
|
||||
pthread_attr_setschedparam(&ptattr2, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr2, (VOID*) storage_ptr );
|
||||
storage_ptr = (int *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_2, &ptattr2,pthread_2_entry,NULL);
|
||||
|
||||
/* Create pthread 3. */
|
||||
param.sched_priority = 25;
|
||||
pthread_attr_setschedparam(&ptattr3, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr3, (VOID*) storage_ptr );
|
||||
storage_ptr = (int *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_3, &ptattr3,pthread_3_entry,NULL);
|
||||
|
||||
/* Create pthread 4. */
|
||||
param.sched_priority = 30;
|
||||
pthread_attr_setschedparam(&ptattr4, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr4, (VOID*) storage_ptr );
|
||||
storage_ptr = (int *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_4, &ptattr4,pthread_4_entry,NULL);
|
||||
|
||||
/* Create pthread 5. */
|
||||
param.sched_priority = 5;
|
||||
pthread_attr_setschedparam(&ptattr5, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr5, (VOID*) storage_ptr );
|
||||
storage_ptr = (int *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_5, &ptattr5,pthread_5_entry,NULL);
|
||||
|
||||
/* Create a Message queue. */
|
||||
q_des = mq_open("Queue",O_CREAT|O_RDWR,0,&queue_atrr);
|
||||
|
||||
/* Create a Semaphore. */
|
||||
sem = sem_open("Sem0", O_CREAT | O_EXCL,0,1);
|
||||
|
||||
/* Create a Mutex */
|
||||
pthread_mutex_init(&mutex1, NULL);
|
||||
|
||||
}
|
||||
|
||||
/* Define the test pthreads */
|
||||
INT pt0_status=0;
|
||||
|
||||
VOID *pthread_0_entry(VOID *pthread0_input)
|
||||
{
|
||||
|
||||
struct timespec thread_0_sleep_time={0,0};
|
||||
|
||||
/* This pthread simply sits in while-forever-sleep loop */
|
||||
while(1)
|
||||
{
|
||||
/* Increment the pthread counter.*/
|
||||
pthread_0_counter++;
|
||||
/* sleep for a while */
|
||||
thread_0_sleep_time.tv_nsec = 999999999;
|
||||
thread_0_sleep_time.tv_sec = 4;
|
||||
pt0_status=nanosleep(&thread_0_sleep_time,0);
|
||||
if(pt0_status)
|
||||
break;
|
||||
}
|
||||
|
||||
return(&pt0_status);
|
||||
}
|
||||
|
||||
|
||||
INT pt1_status=0;
|
||||
|
||||
VOID *pthread_1_entry(VOID *pthread1_input)
|
||||
{
|
||||
|
||||
struct timespec thread_1_sleep_time={0,0};
|
||||
|
||||
/* This thread simply sends a messages to a queue shared by pthread 2. */
|
||||
while(1)
|
||||
{
|
||||
|
||||
/* Increment the thread counter. */
|
||||
pthread_1_counter++;
|
||||
/* Send message to queue 0. */
|
||||
pt1_status = mq_send(q_des,msg0,strlen(msg0),3);
|
||||
|
||||
/* check status. */
|
||||
if(pt1_status)
|
||||
break;
|
||||
|
||||
/* Increment the message sent. */
|
||||
pthread_1_message_sent++;
|
||||
|
||||
/* sleep for a while */
|
||||
thread_1_sleep_time.tv_nsec = 200000000;
|
||||
nanosleep(&thread_1_sleep_time,0);
|
||||
}
|
||||
return(&pt1_status);
|
||||
}
|
||||
|
||||
|
||||
INT pt2_status;
|
||||
|
||||
VOID *pthread_2_entry(VOID *pthread2_input)
|
||||
{
|
||||
|
||||
CHAR msgr0[MAX_MESSAGE_SIZE];
|
||||
ULONG priority;
|
||||
struct timespec thread_2_sleep_time={0,0};
|
||||
|
||||
/* This pthread retrieves messages placed on the queue by pthread 1. */
|
||||
while(1 )
|
||||
{
|
||||
/* Increment the thread counter. */
|
||||
pthread_2_counter++;
|
||||
pt2_status = mq_receive(q_des,msgr0,MAX_MESSAGE_SIZE,&priority);
|
||||
|
||||
if(pt2_status == ERROR)
|
||||
break;
|
||||
|
||||
/* Otherwise, it is OK to increment the received message count. */
|
||||
pthread_2_message_received++;
|
||||
/* sleep for a while */
|
||||
thread_2_sleep_time.tv_nsec = 200000000;
|
||||
nanosleep(&thread_2_sleep_time,0);
|
||||
}
|
||||
return(&pt2_status);
|
||||
}
|
||||
|
||||
INT pt3_status;
|
||||
VOID *pthread_3_entry(VOID *pthread3_input)
|
||||
{
|
||||
|
||||
|
||||
struct timespec thread_3_sleep_time={0,0};
|
||||
|
||||
|
||||
/* This function compete for ownership of semaphore_0. */
|
||||
while(1)
|
||||
{
|
||||
|
||||
/* Increment the thread counter. */
|
||||
pthread_3_counter++;
|
||||
/* Get the semaphore with suspension. */
|
||||
pt3_status = sem_wait(sem);
|
||||
|
||||
/* Check status. */
|
||||
if (pt3_status)
|
||||
break;
|
||||
|
||||
/* Sleep for a while to hold the semaphore. */
|
||||
thread_3_sleep_time.tv_nsec = 200000000;
|
||||
nanosleep(&thread_3_sleep_time,0);
|
||||
|
||||
/* Release the semaphore. */
|
||||
pt3_status = sem_post(sem);
|
||||
|
||||
/* Check status. */
|
||||
if (pt3_status )
|
||||
break;
|
||||
}
|
||||
return(&pt3_status);
|
||||
}
|
||||
|
||||
INT pt4_status;
|
||||
|
||||
VOID *pthread_4_entry(VOID *pthread4_input)
|
||||
{
|
||||
|
||||
struct timespec thread_4_sleep_time={0,0};
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
||||
/* Increment the thread counter. */
|
||||
pthread_4_counter++;
|
||||
/* now lock the mutex */
|
||||
pt4_status = pthread_mutex_lock(&mutex1);
|
||||
if (pt4_status != OK)
|
||||
break;
|
||||
|
||||
/* sleep for a while */
|
||||
thread_4_sleep_time.tv_nsec = 200000000;
|
||||
nanosleep(&thread_4_sleep_time,0);
|
||||
|
||||
pt4_status = pthread_mutex_unlock(&mutex1);
|
||||
if (pt4_status != OK)
|
||||
break;
|
||||
}
|
||||
return(&pt4_status);
|
||||
}
|
||||
|
||||
INT pt5_status;
|
||||
|
||||
VOID *pthread_5_entry(VOID *pthread5_input)
|
||||
{
|
||||
|
||||
struct timespec thread_5_sleep_time={0,0};
|
||||
|
||||
while(1)
|
||||
{
|
||||
/* Increment the thread counter. */
|
||||
pthread_5_counter++;
|
||||
/* now lock the mutex */
|
||||
pt5_status = pthread_mutex_lock(&mutex1);
|
||||
if (pt5_status != OK)
|
||||
break;
|
||||
|
||||
/* sleep for a while */
|
||||
thread_5_sleep_time.tv_nsec = 20000000;
|
||||
nanosleep(&thread_5_sleep_time,0);
|
||||
pt5_status = pthread_mutex_unlock(&mutex1);
|
||||
if (pt5_status != OK)
|
||||
break;
|
||||
}
|
||||
return(&pt5_status);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
/* Simple nested-signaling test. */
|
||||
|
||||
#include "pthread.h"
|
||||
|
||||
#define DEMO_STACK_SIZE 2048
|
||||
#define DEMO_BYTE_POOL_SIZE 9120
|
||||
|
||||
|
||||
/* Define the POSIX pthread object control blocks ... */
|
||||
|
||||
pthread_t pthread_0;
|
||||
|
||||
|
||||
/* Define pthread attributes objects */
|
||||
|
||||
|
||||
pthread_attr_t ptattr0;
|
||||
|
||||
|
||||
/* Define the counters used in this test application... */
|
||||
|
||||
ULONG pthread_0_counter;
|
||||
ULONG pthread_0_signal_counter15;
|
||||
ULONG pthread_0_signal_counter14;
|
||||
ULONG pthread_0_signal_counter13;
|
||||
|
||||
|
||||
/* Define pthread function prototypes. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *);
|
||||
|
||||
|
||||
/* Define signal handlers. */
|
||||
|
||||
VOID pthread_0_signal_handler15(int);
|
||||
VOID pthread_0_signal_handler14(int);
|
||||
VOID pthread_0_signal_handler13(int);
|
||||
|
||||
ULONG free_memory[192*1024 / sizeof(ULONG)];
|
||||
/* Define main entry point. */
|
||||
|
||||
INT main()
|
||||
{
|
||||
|
||||
/* Enter the ThreadX kernel. */
|
||||
tx_kernel_enter();
|
||||
}
|
||||
|
||||
|
||||
/* Define what the initial system looks like. */
|
||||
VOID tx_application_define(VOID *first_unused_memory)
|
||||
{
|
||||
|
||||
VOID* storage_ptr;
|
||||
|
||||
|
||||
struct sched_param param;
|
||||
|
||||
|
||||
/* Init POSIX Wrapper */
|
||||
storage_ptr = (VOID*) posix_initialize((VOID* )free_memory);
|
||||
|
||||
/* Put system definition stuff in here, e.g. pthread creates and other assoerted
|
||||
create information. */
|
||||
|
||||
/* Create pthread attributes. */
|
||||
pthread_attr_init(&ptattr0);
|
||||
|
||||
/* Create a sched_param structure */
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
/* Now create all pthreads , firstly modify respective ptheread
|
||||
attribute with desired priority and stack start address and then create the pthread */
|
||||
|
||||
/* Create pthread 0. */
|
||||
param.sched_priority = 10;
|
||||
pthread_attr_setschedparam(&ptattr0, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr0, storage_ptr );
|
||||
storage_ptr = (int *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_0, &ptattr0,pthread_0_entry,NULL);
|
||||
}
|
||||
|
||||
|
||||
VOID error_handler(void)
|
||||
{
|
||||
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Define the signal handlers. */
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler13(int signo)
|
||||
{
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 13)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter13++;
|
||||
}
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler14(int signo)
|
||||
{
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 14)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter14++;
|
||||
|
||||
/* Raise another signal for nesting test. */
|
||||
pthread_kill(pthread_0, 13);
|
||||
}
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler15(int signo)
|
||||
{
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 15)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter15++;
|
||||
|
||||
/* Raise another signal for nesting test. */
|
||||
pthread_kill(pthread_0, 14);
|
||||
}
|
||||
|
||||
|
||||
/* Define the test pthreads */
|
||||
INT pt0_status=0;
|
||||
|
||||
|
||||
/* Self signal test. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *pthread0_input)
|
||||
{
|
||||
|
||||
/* Register the signal handlers. */
|
||||
pt0_status = signal(15, pthread_0_signal_handler15);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
pt0_status = signal(14, pthread_0_signal_handler14);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
pt0_status = signal(13, pthread_0_signal_handler13);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* This pthread simply sits in while-forever-sleep loop */
|
||||
while(1)
|
||||
{
|
||||
/* Increment the pthread counter.*/
|
||||
pthread_0_counter++;
|
||||
|
||||
/* Raise the signal. */
|
||||
pt0_status = pthread_kill(pthread_0, 15);
|
||||
|
||||
/* Check for errors. */
|
||||
if ((pt0_status) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter15) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter14) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter13))
|
||||
{
|
||||
|
||||
error_handler();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(&pt0_status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,295 @@
|
||||
/* Simple resume from signal handler test. */
|
||||
|
||||
#include "pthread.h"
|
||||
|
||||
#define DEMO_STACK_SIZE 2048
|
||||
#define DEMO_BYTE_POOL_SIZE 9120
|
||||
|
||||
|
||||
/* Define the POSIX pthread object control blocks ... */
|
||||
|
||||
pthread_t pthread_0;
|
||||
pthread_t pthread_1;
|
||||
|
||||
|
||||
/* Define pthread attributes objects */
|
||||
|
||||
|
||||
pthread_attr_t ptattr0;
|
||||
pthread_attr_t ptattr1;
|
||||
|
||||
|
||||
/* Define a semaphore. */
|
||||
|
||||
sem_t *sem;
|
||||
|
||||
|
||||
/* Define the counters used in this test application... */
|
||||
|
||||
ULONG pthread_0_counter;
|
||||
ULONG pthread_0_signal_counter15;
|
||||
ULONG pthread_0_signal_counter14;
|
||||
ULONG pthread_0_signal_counter13;
|
||||
|
||||
ULONG pthread_1_counter;
|
||||
|
||||
|
||||
/* Define pthread function prototypes. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *);
|
||||
VOID *pthread_1_entry(VOID *);
|
||||
|
||||
|
||||
/* Define signal handlers. */
|
||||
|
||||
VOID pthread_0_signal_handler15(int);
|
||||
VOID pthread_0_signal_handler14(int);
|
||||
VOID pthread_0_signal_handler13(int);
|
||||
ULONG free_memory[192*1024 / sizeof(ULONG)];
|
||||
|
||||
/* Define main entry point. */
|
||||
|
||||
INT main()
|
||||
{
|
||||
|
||||
/* Enter the ThreadX kernel. */
|
||||
tx_kernel_enter();
|
||||
}
|
||||
|
||||
|
||||
/* Define what the initial system looks like. */
|
||||
VOID tx_application_define(VOID *first_unused_memory)
|
||||
{
|
||||
|
||||
VOID* storage_ptr;
|
||||
|
||||
|
||||
struct sched_param param;
|
||||
|
||||
|
||||
/* Init POSIX Wrapper */
|
||||
storage_ptr = (VOID*) posix_initialize((VOID*)free_memory);
|
||||
|
||||
/* Put system definition stuff in here, e.g. pthread creates and other assoerted
|
||||
create information. */
|
||||
|
||||
/* Create pthread attributes. */
|
||||
pthread_attr_init(&ptattr0);
|
||||
pthread_attr_init(&ptattr1);
|
||||
|
||||
/* Create a sched_param structure */
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
/* Now create all pthreads , firstly modify respective ptheread
|
||||
attribute with desired priority and stack start address and then create the pthread */
|
||||
|
||||
/* Create pthread 0. */
|
||||
param.sched_priority = 15;
|
||||
pthread_attr_setschedparam(&ptattr0, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr0, storage_ptr );
|
||||
storage_ptr = (int *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_0, &ptattr0,pthread_0_entry,NULL);
|
||||
|
||||
|
||||
/* Create pthread 1. */
|
||||
param.sched_priority = 10;
|
||||
pthread_attr_setschedparam(&ptattr1, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr1, (VOID*) storage_ptr );
|
||||
storage_ptr = (int *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_1, &ptattr1,pthread_1_entry,NULL);
|
||||
|
||||
|
||||
/* Create a Semaphore. */
|
||||
sem = sem_open("Sem0", O_CREAT | O_EXCL,0,1);
|
||||
}
|
||||
|
||||
|
||||
VOID error_handler(void)
|
||||
{
|
||||
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Define the signal handlers. */
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler13(int signo)
|
||||
{
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 13)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter13++;
|
||||
|
||||
/* Release the semaphore, which will wakeup pthread 0. */
|
||||
sem_post(sem);
|
||||
}
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler14(int signo)
|
||||
{
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 14)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter14++;
|
||||
|
||||
/* Raise another signal for nesting test. */
|
||||
pthread_kill(pthread_0, 13);
|
||||
}
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler15(int signo)
|
||||
{
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 15)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter15++;
|
||||
|
||||
/* Raise another signal for nesting test. */
|
||||
pthread_kill(pthread_0, 14);
|
||||
}
|
||||
|
||||
|
||||
/* Define the test pthreads */
|
||||
INT pt0_status=0;
|
||||
|
||||
|
||||
/* Self signal test. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *pthread0_input)
|
||||
{
|
||||
|
||||
/* Register the signal handlers. */
|
||||
pt0_status = signal(15, pthread_0_signal_handler15);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
pt0_status = signal(14, pthread_0_signal_handler14);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
pt0_status = signal(13, pthread_0_signal_handler13);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
|
||||
/* Get the semaphore with suspension. */
|
||||
pt0_status = sem_wait(sem);
|
||||
|
||||
/* This pthread simply sits in while-forever-sleep loop */
|
||||
while(1)
|
||||
{
|
||||
/* Increment the pthread counter.*/
|
||||
pthread_0_counter++;
|
||||
|
||||
/* Get the semaphore with suspension. */
|
||||
pt0_status = sem_wait(sem);
|
||||
|
||||
/* Check for errors. */
|
||||
if ((pt0_status) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter15) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter14) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter13))
|
||||
{
|
||||
|
||||
/* In this test, this thread should never resume! */
|
||||
error_handler();
|
||||
|
||||
/* Break out of the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(&pt0_status);
|
||||
}
|
||||
|
||||
|
||||
INT pt1_status=0;
|
||||
|
||||
VOID *pthread_1_entry(VOID *pthread1_input)
|
||||
{
|
||||
|
||||
|
||||
/* This thread simply sends a messages to a queue shared by pthread 2. */
|
||||
while(1)
|
||||
{
|
||||
|
||||
/* Increment the thread counter. */
|
||||
pthread_1_counter++;
|
||||
|
||||
/* Raise the first signal for pthread 0. */
|
||||
pt1_status = pthread_kill(pthread_0, 15);
|
||||
|
||||
/* Check for errors. */
|
||||
if ((pt1_status) ||
|
||||
(pthread_0_counter != (pthread_1_counter+1)) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter15) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter14) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter13))
|
||||
{
|
||||
|
||||
error_handler();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(&pt1_status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,436 @@
|
||||
/* Simple self-signaling test. */
|
||||
|
||||
#include "pthread.h"
|
||||
|
||||
#define DEMO_STACK_SIZE 2048
|
||||
#if 0
|
||||
#define MAX_MESSAGE_SIZE 50
|
||||
#endif
|
||||
#define DEMO_BYTE_POOL_SIZE 9120
|
||||
|
||||
|
||||
/* Define the POSIX pthread object control blocks ... */
|
||||
|
||||
pthread_t pthread_0;
|
||||
|
||||
#if 0
|
||||
pthread_t pthread_1;
|
||||
pthread_t pthread_2;
|
||||
pthread_t pthread_3;
|
||||
pthread_t pthread_4;
|
||||
pthread_t pthread_5;
|
||||
#endif
|
||||
|
||||
/* Define pthread attributes objects */
|
||||
|
||||
|
||||
pthread_attr_t ptattr0;
|
||||
#if 0
|
||||
pthread_attr_t ptattr1;
|
||||
pthread_attr_t ptattr2;
|
||||
pthread_attr_t ptattr3;
|
||||
pthread_attr_t ptattr4;
|
||||
pthread_attr_t ptattr5;
|
||||
|
||||
|
||||
/* Define the message queue attribute. */
|
||||
|
||||
struct mq_attr queue_atrr;
|
||||
|
||||
/* Define a queue descriptor. */
|
||||
|
||||
mqd_t q_des;
|
||||
|
||||
/* Define a semaphore. */
|
||||
|
||||
sem_t *sem;
|
||||
|
||||
/* Define a mutex */
|
||||
|
||||
pthread_mutex_t mutex1;
|
||||
|
||||
/* Define a mutex attributes object */
|
||||
|
||||
pthread_mutexattr_t mta1;
|
||||
#endif
|
||||
|
||||
/* Define the counters used in this test application... */
|
||||
|
||||
ULONG pthread_0_counter;
|
||||
ULONG pthread_0_signal_counter;
|
||||
|
||||
|
||||
#if 0
|
||||
ULONG pthread_1_counter;
|
||||
ULONG pthread_2_counter;
|
||||
ULONG pthread_3_counter;
|
||||
ULONG pthread_4_counter;
|
||||
ULONG pthread_5_counter;
|
||||
ULONG pthread_1_message_sent;
|
||||
ULONG pthread_2_message_received;
|
||||
#endif
|
||||
|
||||
/* Define pthread function prototypes. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *);
|
||||
|
||||
|
||||
/* Define signal handlers. */
|
||||
|
||||
VOID pthread_0_signal_handler(int);
|
||||
|
||||
|
||||
#if 0
|
||||
VOID *pthread_1_entry(VOID *);
|
||||
VOID *pthread_2_entry(VOID *);
|
||||
VOID *pthread_3_entry(VOID *);
|
||||
VOID *pthread_4_entry(VOID *);
|
||||
VOID *pthread_5_entry(VOID *);
|
||||
|
||||
|
||||
/* Message to be sent. */
|
||||
CHAR *msg0 = "This is a test message";
|
||||
#endif
|
||||
ULONG free_memory[192*1024 / sizeof(ULONG)];
|
||||
|
||||
/* Define main entry point. */
|
||||
|
||||
INT main()
|
||||
{
|
||||
|
||||
/* Enter the ThreadX kernel. */
|
||||
tx_kernel_enter();
|
||||
}
|
||||
|
||||
|
||||
/* Define what the initial system looks like. */
|
||||
VOID tx_application_define(VOID *first_unused_memory)
|
||||
{
|
||||
|
||||
VOID* storage_ptr;
|
||||
|
||||
|
||||
struct sched_param param;
|
||||
|
||||
#if 0
|
||||
queue_atrr.mq_maxmsg = 124;
|
||||
queue_atrr.mq_msgsize = MAX_MESSAGE_SIZE;
|
||||
#endif
|
||||
|
||||
/* Init POSIX Wrapper */
|
||||
storage_ptr = (VOID*) posix_initialize((VOID*)free_memory);
|
||||
|
||||
/* Put system definition stuff in here, e.g. pthread creates and other assoerted
|
||||
create information. */
|
||||
|
||||
/* Create pthread attributes. */
|
||||
pthread_attr_init(&ptattr0);
|
||||
#if 0
|
||||
pthread_attr_init(&ptattr1);
|
||||
pthread_attr_init(&ptattr2);
|
||||
pthread_attr_init(&ptattr3);
|
||||
pthread_attr_init(&ptattr4);
|
||||
pthread_attr_init(&ptattr5);
|
||||
#endif
|
||||
|
||||
/* Create a sched_param structure */
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
/* Now create all pthreads , firstly modify respective ptheread
|
||||
attribute with desired priority and stack start address and then create the pthread */
|
||||
|
||||
/* Create pthread 0. */
|
||||
param.sched_priority = 10;
|
||||
pthread_attr_setschedparam(&ptattr0, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr0, storage_ptr );
|
||||
storage_ptr = (int *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_0, &ptattr0,pthread_0_entry,NULL);
|
||||
|
||||
#if 0
|
||||
/* Create pthread 1. */
|
||||
param.sched_priority = 15;
|
||||
pthread_attr_setschedparam(&ptattr1, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr1, (VOID*) storage_ptr );
|
||||
storage_ptr = storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_1, &ptattr1,pthread_1_entry,NULL);
|
||||
|
||||
/* Create pthread 2. */
|
||||
param.sched_priority = 20;
|
||||
pthread_attr_setschedparam(&ptattr2, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr2, (VOID*) storage_ptr );
|
||||
storage_ptr = storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_2, &ptattr2,pthread_2_entry,NULL);
|
||||
|
||||
/* Create pthread 3. */
|
||||
param.sched_priority = 25;
|
||||
pthread_attr_setschedparam(&ptattr3, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr3, (VOID*) storage_ptr );
|
||||
storage_ptr = storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_3, &ptattr3,pthread_3_entry,NULL);
|
||||
|
||||
/* Create pthread 4. */
|
||||
param.sched_priority = 30;
|
||||
pthread_attr_setschedparam(&ptattr4, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr4, (VOID*) storage_ptr );
|
||||
storage_ptr = storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_4, &ptattr4,pthread_4_entry,NULL);
|
||||
|
||||
/* Create pthread 5. */
|
||||
param.sched_priority = 5;
|
||||
pthread_attr_setschedparam(&ptattr5, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr5, (VOID*) storage_ptr );
|
||||
storage_ptr = storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_5, &ptattr5,pthread_5_entry,NULL);
|
||||
|
||||
/* Create a Message queue. */
|
||||
q_des = mq_open("Queue",O_CREAT|O_RDWR,0,&queue_atrr);
|
||||
|
||||
/* Create a Semaphore. */
|
||||
sem = sem_open("Sem0", O_CREAT | O_EXCL,0,1);
|
||||
|
||||
/* Create a Mutex */
|
||||
pthread_mutex_init(&mutex1, NULL);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
VOID error_handler(void)
|
||||
{
|
||||
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Define the signal handler. */
|
||||
|
||||
VOID pthread_0_signal_handler(int signo)
|
||||
{
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 15)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 1
|
||||
/* Define the test pthreads */
|
||||
INT pt0_status=0;
|
||||
#endif
|
||||
|
||||
/* Self signal test. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *pthread0_input)
|
||||
{
|
||||
|
||||
// struct timespec thread_0_sleep_time={0,0};
|
||||
|
||||
/* Register the signal handler. */
|
||||
pt0_status = signal(15, pthread_0_signal_handler);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* This pthread simply sits in while-forever-sleep loop */
|
||||
while(1)
|
||||
{
|
||||
/* Increment the pthread counter.*/
|
||||
pthread_0_counter++;
|
||||
|
||||
/* Raise the signal. */
|
||||
pt0_status = pthread_kill(pthread_0, 15);
|
||||
|
||||
/* Check for errors. */
|
||||
if ((pt0_status) || (pthread_0_counter != pthread_0_signal_counter))
|
||||
{
|
||||
error_handler();
|
||||
break;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* sleep for a while */
|
||||
thread_0_sleep_time.tv_nsec = 999999999;
|
||||
thread_0_sleep_time.tv_sec = 4;
|
||||
pt0_status=nanosleep(&thread_0_sleep_time,0);
|
||||
if(pt0_status)
|
||||
break;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if 1
|
||||
return(&pt0_status);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
INT pt1_status=0;
|
||||
|
||||
VOID *pthread_1_entry(VOID *pthread1_input)
|
||||
{
|
||||
|
||||
struct timespec thread_1_sleep_time={0,0};
|
||||
|
||||
/* This thread simply sends a messages to a queue shared by pthread 2. */
|
||||
while(1)
|
||||
{
|
||||
|
||||
/* Increment the thread counter. */
|
||||
pthread_1_counter++;
|
||||
/* Send message to queue 0. */
|
||||
pt1_status = mq_send(q_des,msg0,strlen(msg0),3);
|
||||
|
||||
/* check status. */
|
||||
if(pt1_status)
|
||||
break;
|
||||
|
||||
/* Increment the message sent. */
|
||||
pthread_1_message_sent++;
|
||||
|
||||
/* sleep for a while */
|
||||
thread_1_sleep_time.tv_nsec = 200000000;
|
||||
nanosleep(&thread_1_sleep_time,0);
|
||||
}
|
||||
return(&pt1_status);
|
||||
}
|
||||
|
||||
|
||||
INT pt2_status;
|
||||
|
||||
VOID *pthread_2_entry(VOID *pthread2_input)
|
||||
{
|
||||
|
||||
CHAR msgr0[MAX_MESSAGE_SIZE];
|
||||
ULONG priority;
|
||||
struct timespec thread_2_sleep_time={0,0};
|
||||
|
||||
/* This pthread retrieves messages placed on the queue by pthread 1. */
|
||||
while(1 )
|
||||
{
|
||||
/* Increment the thread counter. */
|
||||
pthread_2_counter++;
|
||||
pt2_status = mq_receive(q_des,msgr0,MAX_MESSAGE_SIZE,&priority);
|
||||
|
||||
if(pt2_status != 0)
|
||||
break;
|
||||
|
||||
/* Otherwise, it is OK to increment the received message count. */
|
||||
pthread_2_message_received++;
|
||||
/* sleep for a while */
|
||||
thread_2_sleep_time.tv_nsec = 200000000;
|
||||
nanosleep(&thread_2_sleep_time,0);
|
||||
}
|
||||
return(&pt2_status);
|
||||
}
|
||||
|
||||
INT pt3_status;
|
||||
VOID *pthread_3_entry(VOID *pthread3_input)
|
||||
{
|
||||
|
||||
|
||||
struct timespec thread_3_sleep_time={0,0};
|
||||
|
||||
|
||||
/* This function compete for ownership of semaphore_0. */
|
||||
while(1)
|
||||
{
|
||||
|
||||
/* Increment the thread counter. */
|
||||
pthread_3_counter++;
|
||||
/* Get the semaphore with suspension. */
|
||||
pt3_status = sem_wait(sem);
|
||||
|
||||
/* Check status. */
|
||||
if (pt3_status)
|
||||
break;
|
||||
|
||||
/* Sleep for a while to hold the semaphore. */
|
||||
thread_3_sleep_time.tv_nsec = 200000000;
|
||||
nanosleep(&thread_3_sleep_time,0);
|
||||
|
||||
/* Release the semaphore. */
|
||||
pt3_status = sem_post(sem);
|
||||
|
||||
/* Check status. */
|
||||
if (pt3_status )
|
||||
break;
|
||||
}
|
||||
return(&pt3_status);
|
||||
}
|
||||
|
||||
INT pt4_status;
|
||||
|
||||
VOID *pthread_4_entry(VOID *pthread4_input)
|
||||
{
|
||||
|
||||
struct timespec thread_4_sleep_time={0,0};
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
||||
/* Increment the thread counter. */
|
||||
pthread_4_counter++;
|
||||
/* now lock the mutex */
|
||||
pt4_status = pthread_mutex_lock(&mutex1);
|
||||
if (pt4_status != OK)
|
||||
break;
|
||||
|
||||
/* sleep for a while */
|
||||
thread_4_sleep_time.tv_nsec = 200000000;
|
||||
nanosleep(&thread_4_sleep_time,0);
|
||||
|
||||
pt4_status = pthread_mutex_unlock(&mutex1);
|
||||
if (pt4_status != OK)
|
||||
break;
|
||||
}
|
||||
return(&pt4_status);
|
||||
}
|
||||
|
||||
INT pt5_status;
|
||||
|
||||
VOID *pthread_5_entry(VOID *pthread5_input)
|
||||
{
|
||||
|
||||
struct timespec thread_5_sleep_time={0,0};
|
||||
|
||||
while(1)
|
||||
{
|
||||
/* Increment the thread counter. */
|
||||
pthread_5_counter++;
|
||||
/* now lock the mutex */
|
||||
pt5_status = pthread_mutex_lock(&mutex1);
|
||||
if (pt5_status != OK)
|
||||
break;
|
||||
|
||||
/* sleep for a while */
|
||||
thread_5_sleep_time.tv_nsec = 20000000;
|
||||
nanosleep(&thread_5_sleep_time,0);
|
||||
pt5_status = pthread_mutex_unlock(&mutex1);
|
||||
if (pt5_status != OK)
|
||||
break;
|
||||
}
|
||||
return(&pt5_status);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,450 @@
|
||||
/* Simple signal sigmask test. */
|
||||
|
||||
#include "pthread.h"
|
||||
|
||||
#define DEMO_STACK_SIZE 2048
|
||||
|
||||
/* Define the POSIX pthread object control blocks ... */
|
||||
|
||||
pthread_t pthread_0;
|
||||
pthread_t pthread_1;
|
||||
|
||||
|
||||
/* Define pthread attributes objects */
|
||||
|
||||
|
||||
pthread_attr_t ptattr0;
|
||||
pthread_attr_t ptattr1;
|
||||
|
||||
|
||||
/* Define the counters used in this test application... */
|
||||
|
||||
ULONG pthread_0_counter;
|
||||
ULONG pthread_0_signal_counter16;
|
||||
ULONG pthread_0_signal_counter15;
|
||||
ULONG pthread_0_signal_counter14;
|
||||
ULONG pthread_0_signal_counter13;
|
||||
|
||||
ULONG pthread_1_counter;
|
||||
|
||||
|
||||
/* Define pthread function prototypes. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *);
|
||||
VOID *pthread_1_entry(VOID *);
|
||||
|
||||
|
||||
/* Define signal handlers. */
|
||||
|
||||
VOID pthread_0_signal_handler16(int);
|
||||
VOID pthread_0_signal_handler15(int);
|
||||
VOID pthread_0_signal_handler14(int);
|
||||
VOID pthread_0_signal_handler13(int);
|
||||
|
||||
ULONG free_memory[192*1024 / sizeof(ULONG)];
|
||||
/* Define main entry point. */
|
||||
|
||||
INT main()
|
||||
{
|
||||
|
||||
/* Enter the ThreadX kernel. */
|
||||
tx_kernel_enter();
|
||||
}
|
||||
|
||||
|
||||
/* Define what the initial system looks like. */
|
||||
VOID tx_application_define(VOID *first_unused_memory)
|
||||
{
|
||||
|
||||
VOID* storage_ptr;
|
||||
|
||||
|
||||
struct sched_param param;
|
||||
|
||||
|
||||
/* Init POSIX Wrapper */
|
||||
storage_ptr = (VOID*) posix_initialize((VOID*)free_memory);
|
||||
|
||||
/* Put system definition stuff in here, e.g. pthread creates and other assoerted
|
||||
create information. */
|
||||
|
||||
/* Create pthread attributes. */
|
||||
pthread_attr_init(&ptattr0);
|
||||
pthread_attr_init(&ptattr1);
|
||||
|
||||
/* Create a sched_param structure */
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
/* Now create all pthreads , firstly modify respective ptheread
|
||||
attribute with desired priority and stack start address and then create the pthread */
|
||||
|
||||
/* Create pthread 0. */
|
||||
param.sched_priority = 15;
|
||||
pthread_attr_setschedparam(&ptattr0, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr0, storage_ptr );
|
||||
storage_ptr = (UINT *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_0, &ptattr0,pthread_0_entry,NULL);
|
||||
|
||||
|
||||
/* Create pthread 1. */
|
||||
param.sched_priority = 10;
|
||||
pthread_attr_setschedparam(&ptattr1, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr1, (VOID*) storage_ptr );
|
||||
storage_ptr = (UINT *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_1, &ptattr1,pthread_1_entry,NULL);
|
||||
}
|
||||
|
||||
VOID error_handler(void)
|
||||
{
|
||||
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Define the signal handlers. */
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler13(int signo)
|
||||
{
|
||||
|
||||
sigset_t wait_set;
|
||||
int signal_received;
|
||||
int status;
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 13)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter13++;
|
||||
|
||||
/* Wait on signal 12. */
|
||||
sigemptyset(&wait_set);
|
||||
sigaddset(&wait_set, 12);
|
||||
status = sigwait(&wait_set, &signal_received);
|
||||
|
||||
/* Check for an error. */
|
||||
if ((status) || (signal_received != 12))
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler14(int signo)
|
||||
{
|
||||
|
||||
sigset_t wait_set;
|
||||
int signal_received;
|
||||
int status;
|
||||
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 14)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter14++;
|
||||
|
||||
/* Wait on signal 13. */
|
||||
sigemptyset(&wait_set);
|
||||
sigaddset(&wait_set, 13);
|
||||
status = sigwait(&wait_set, &signal_received);
|
||||
|
||||
/* Check for an error. */
|
||||
if ((status) || (signal_received != 13))
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler15(int signo)
|
||||
{
|
||||
|
||||
sigset_t wait_set;
|
||||
int signal_received;
|
||||
int status;
|
||||
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 15)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter15++;
|
||||
|
||||
/* Wait on signal 14. */
|
||||
sigemptyset(&wait_set);
|
||||
sigaddset(&wait_set, 14);
|
||||
status = sigwait(&wait_set, &signal_received);
|
||||
|
||||
/* Check for an error. */
|
||||
if ((status) || (signal_received != 14))
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler16(int signo)
|
||||
{
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 16)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter16++;
|
||||
}
|
||||
|
||||
|
||||
/* Define the test pthreads */
|
||||
INT pt0_status=0;
|
||||
|
||||
|
||||
/* Self signal test. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *pthread0_input)
|
||||
{
|
||||
|
||||
sigset_t wait_set;
|
||||
sigset_t new_mask;
|
||||
sigset_t old_mask;
|
||||
int signal_received;
|
||||
|
||||
|
||||
/* Register the signal handlers. */
|
||||
pt0_status = signal(16, pthread_0_signal_handler16);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
pt0_status = signal(15, pthread_0_signal_handler15);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
pt0_status = signal(14, pthread_0_signal_handler14);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
pt0_status = signal(13, pthread_0_signal_handler13);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* Setup block for signal 15, that won't actually be used until the sigwait occurs. */
|
||||
sigemptyset(&new_mask);
|
||||
sigaddset(&new_mask, 15);
|
||||
pt0_status = pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* Setup a signal mask for signal 16. */
|
||||
sigemptyset(&new_mask);
|
||||
sigaddset(&new_mask, 16);
|
||||
pt0_status = pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* Simply restore the signal for this first test. */
|
||||
pt0_status = pthread_sigmask(SIG_SETMASK, &old_mask, &old_mask);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* Now do it again, but set a signal when the signal is masked. */
|
||||
pt0_status = pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* Raise the first signal for pthread 0. */
|
||||
pt0_status = pthread_kill(pthread_0, 16);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* Now unblock this signal to trigger the actual activation of the signal. */
|
||||
pt0_status = pthread_sigmask(SIG_UNBLOCK, &new_mask, &old_mask);
|
||||
|
||||
/* Check for error. */
|
||||
if ((pt0_status) || (pthread_0_signal_counter16 != 1))
|
||||
error_handler();
|
||||
|
||||
/* Now do it all again, but perform a sigwait when the signal is masked and pending. */
|
||||
pt0_status = pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* Raise the first signal for pthread 0. */
|
||||
pt0_status = pthread_kill(pthread_0, 16);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* Wait on signal 16. */
|
||||
sigemptyset(&wait_set);
|
||||
sigaddset(&wait_set, 16);
|
||||
|
||||
/* Now perform a sigwait on signal 16. */
|
||||
pt0_status = sigwait(&wait_set, &signal_received);
|
||||
|
||||
/* Check for error. */
|
||||
if ((pt0_status) || (pthread_0_signal_counter16 != 2) || (signal_received != 16))
|
||||
error_handler();
|
||||
|
||||
/* Now unblock this signal to trigger the actual activation of the signal. */
|
||||
pt0_status = pthread_sigmask(SIG_UNBLOCK, &new_mask, &old_mask);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* This pthread simply sits in while-forever-sleep loop */
|
||||
while(1)
|
||||
{
|
||||
/* Increment the pthread counter.*/
|
||||
pthread_0_counter++;
|
||||
|
||||
/* Wait on signal 15. */
|
||||
sigemptyset(&wait_set);
|
||||
sigaddset(&wait_set, 15);
|
||||
|
||||
/* Signal wait. */
|
||||
pt0_status = sigwait(&wait_set, &signal_received);
|
||||
|
||||
/* Check for errors. */
|
||||
if ((pt0_status) ||
|
||||
(signal_received != 15) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter15) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter14) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter13))
|
||||
{
|
||||
|
||||
/* In this test, this thread should never resume! */
|
||||
error_handler();
|
||||
|
||||
/* Break out of the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(&pt0_status);
|
||||
}
|
||||
|
||||
|
||||
INT pt1_status=0;
|
||||
|
||||
VOID *pthread_1_entry(VOID *pthread1_input)
|
||||
{
|
||||
|
||||
|
||||
/* This thread simply sends a messages to a queue shared by pthread 2. */
|
||||
while(1)
|
||||
{
|
||||
|
||||
/* Increment the thread counter. */
|
||||
pthread_1_counter++;
|
||||
|
||||
/* Raise the first signal for pthread 0. */
|
||||
pt1_status = pthread_kill(pthread_0, 15);
|
||||
|
||||
pt1_status += pthread_kill(pthread_0, 14);
|
||||
|
||||
pt1_status += pthread_kill(pthread_0, 13);
|
||||
|
||||
pt1_status += pthread_kill(pthread_0, 12);
|
||||
|
||||
/* Check for errors. */
|
||||
if ((pt1_status) ||
|
||||
(pthread_0_counter != (pthread_1_counter+1)) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter15) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter14) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter13))
|
||||
{
|
||||
|
||||
error_handler();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(&pt1_status);
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
/* Simple signal sigwait test. */
|
||||
|
||||
#include "pthread.h"
|
||||
|
||||
#define DEMO_STACK_SIZE 2048
|
||||
|
||||
/* Define the POSIX pthread object control blocks ... */
|
||||
|
||||
pthread_t pthread_0;
|
||||
pthread_t pthread_1;
|
||||
|
||||
|
||||
/* Define pthread attributes objects */
|
||||
|
||||
|
||||
pthread_attr_t ptattr0;
|
||||
pthread_attr_t ptattr1;
|
||||
|
||||
|
||||
/* Define the counters used in this test application... */
|
||||
|
||||
ULONG pthread_0_counter;
|
||||
ULONG pthread_0_signal_counter15;
|
||||
ULONG pthread_0_signal_counter14;
|
||||
ULONG pthread_0_signal_counter13;
|
||||
|
||||
ULONG pthread_1_counter;
|
||||
|
||||
|
||||
/* Define pthread function prototypes. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *);
|
||||
VOID *pthread_1_entry(VOID *);
|
||||
|
||||
|
||||
/* Define signal handlers. */
|
||||
|
||||
VOID pthread_0_signal_handler15(int);
|
||||
VOID pthread_0_signal_handler14(int);
|
||||
VOID pthread_0_signal_handler13(int);
|
||||
ULONG free_memory[192*1024 / sizeof(ULONG)];
|
||||
|
||||
/* Define main entry point. */
|
||||
|
||||
INT main()
|
||||
{
|
||||
|
||||
/* Enter the ThreadX kernel. */
|
||||
tx_kernel_enter();
|
||||
}
|
||||
|
||||
|
||||
/* Define what the initial system looks like. */
|
||||
VOID tx_application_define(VOID *first_unused_memory)
|
||||
{
|
||||
|
||||
VOID* storage_ptr;
|
||||
|
||||
|
||||
struct sched_param param;
|
||||
|
||||
|
||||
/* Init POSIX Wrapper */
|
||||
storage_ptr = (VOID*) posix_initialize((VOID*)free_memory);
|
||||
|
||||
/* Put system definition stuff in here, e.g. pthread creates and other assoerted
|
||||
create information. */
|
||||
|
||||
/* Create pthread attributes. */
|
||||
pthread_attr_init(&ptattr0);
|
||||
pthread_attr_init(&ptattr1);
|
||||
|
||||
/* Create a sched_param structure */
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
/* Now create all pthreads , firstly modify respective ptheread
|
||||
attribute with desired priority and stack start address and then create the pthread */
|
||||
|
||||
/* Create pthread 0. */
|
||||
param.sched_priority = 15;
|
||||
pthread_attr_setschedparam(&ptattr0, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr0, storage_ptr );
|
||||
storage_ptr = (UINT *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_0, &ptattr0,pthread_0_entry,NULL);
|
||||
|
||||
|
||||
/* Create pthread 1. */
|
||||
param.sched_priority = 10;
|
||||
pthread_attr_setschedparam(&ptattr1, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr1, (VOID*) storage_ptr );
|
||||
storage_ptr = (UINT *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_1, &ptattr1,pthread_1_entry,NULL);
|
||||
}
|
||||
|
||||
VOID error_handler(void)
|
||||
{
|
||||
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Define the signal handlers. */
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler13(int signo)
|
||||
{
|
||||
|
||||
sigset_t wait_set;
|
||||
int signal_received;
|
||||
int status;
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 13)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter13++;
|
||||
|
||||
/* Wait on signal 12. */
|
||||
sigemptyset(&wait_set);
|
||||
sigaddset(&wait_set, 12);
|
||||
status = sigwait(&wait_set, &signal_received);
|
||||
|
||||
/* Check for an error. */
|
||||
if ((status) || (signal_received != 12))
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler14(int signo)
|
||||
{
|
||||
|
||||
sigset_t wait_set;
|
||||
int signal_received;
|
||||
int status;
|
||||
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 14)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter14++;
|
||||
|
||||
/* Wait on signal 13. */
|
||||
sigemptyset(&wait_set);
|
||||
sigaddset(&wait_set, 13);
|
||||
status = sigwait(&wait_set, &signal_received);
|
||||
|
||||
/* Check for an error. */
|
||||
if ((status) || (signal_received != 13))
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler15(int signo)
|
||||
{
|
||||
|
||||
sigset_t wait_set;
|
||||
int signal_received;
|
||||
int status;
|
||||
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 15)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter15++;
|
||||
|
||||
/* Wait on signal 14. */
|
||||
sigemptyset(&wait_set);
|
||||
sigaddset(&wait_set, 14);
|
||||
status = sigwait(&wait_set, &signal_received);
|
||||
|
||||
/* Check for an error. */
|
||||
if ((status) || (signal_received != 14))
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Define the test pthreads */
|
||||
INT pt0_status=0;
|
||||
|
||||
|
||||
/* Self signal test. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *pthread0_input)
|
||||
{
|
||||
|
||||
sigset_t wait_set;
|
||||
int signal_received;
|
||||
|
||||
|
||||
/* Register the signal handlers. */
|
||||
pt0_status = signal(15, pthread_0_signal_handler15);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
pt0_status = signal(14, pthread_0_signal_handler14);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
pt0_status = signal(13, pthread_0_signal_handler13);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
/* This pthread simply sits in while-forever-sleep loop */
|
||||
while(1)
|
||||
{
|
||||
/* Increment the pthread counter.*/
|
||||
pthread_0_counter++;
|
||||
|
||||
/* Wait on signal 15. */
|
||||
sigemptyset(&wait_set);
|
||||
sigaddset(&wait_set, 15);
|
||||
|
||||
/* Signal wait. */
|
||||
pt0_status = sigwait(&wait_set, &signal_received);
|
||||
|
||||
/* Check for errors. */
|
||||
if ((pt0_status) ||
|
||||
(signal_received != 15) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter15) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter14) ||
|
||||
(pthread_0_counter != pthread_0_signal_counter13))
|
||||
{
|
||||
|
||||
/* In this test, this thread should never resume! */
|
||||
error_handler();
|
||||
|
||||
/* Break out of the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(&pt0_status);
|
||||
}
|
||||
|
||||
|
||||
INT pt1_status=0;
|
||||
|
||||
VOID *pthread_1_entry(VOID *pthread1_input)
|
||||
{
|
||||
|
||||
|
||||
/* This thread simply sends a messages to a queue shared by pthread 2. */
|
||||
while(1)
|
||||
{
|
||||
|
||||
/* Increment the thread counter. */
|
||||
pthread_1_counter++;
|
||||
|
||||
/* Raise the first signal for pthread 0. */
|
||||
pt1_status = pthread_kill(pthread_0, 15);
|
||||
|
||||
pt1_status += pthread_kill(pthread_0, 14);
|
||||
|
||||
pt1_status += pthread_kill(pthread_0, 13);
|
||||
|
||||
pt1_status += pthread_kill(pthread_0, 12);
|
||||
|
||||
/* Check for errors. */
|
||||
if ((pt1_status) ||
|
||||
(pthread_0_counter != (pthread_1_counter+1)) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter15) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter14) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter13))
|
||||
{
|
||||
|
||||
error_handler();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(&pt1_status);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
/* Simple nested-signaling test. */
|
||||
|
||||
#include "pthread.h"
|
||||
|
||||
#define DEMO_STACK_SIZE 2048
|
||||
#define DEMO_BYTE_POOL_SIZE 9120
|
||||
|
||||
|
||||
/* Define the POSIX pthread object control blocks ... */
|
||||
|
||||
pthread_t pthread_0;
|
||||
pthread_t pthread_1;
|
||||
|
||||
|
||||
/* Define pthread attributes objects */
|
||||
|
||||
|
||||
pthread_attr_t ptattr0;
|
||||
pthread_attr_t ptattr1;
|
||||
|
||||
|
||||
/* Define a semaphore. */
|
||||
|
||||
sem_t *sem;
|
||||
|
||||
|
||||
/* Define the counters used in this test application... */
|
||||
|
||||
ULONG pthread_0_counter;
|
||||
ULONG pthread_0_signal_counter15;
|
||||
ULONG pthread_0_signal_counter14;
|
||||
ULONG pthread_0_signal_counter13;
|
||||
|
||||
ULONG pthread_1_counter;
|
||||
|
||||
|
||||
/* Define pthread function prototypes. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *);
|
||||
VOID *pthread_1_entry(VOID *);
|
||||
|
||||
|
||||
/* Define signal handlers. */
|
||||
|
||||
VOID pthread_0_signal_handler15(int);
|
||||
VOID pthread_0_signal_handler14(int);
|
||||
VOID pthread_0_signal_handler13(int);
|
||||
|
||||
ULONG free_memory[192*1024 / sizeof(ULONG)];
|
||||
/* Define main entry point. */
|
||||
|
||||
INT main()
|
||||
{
|
||||
|
||||
/* Enter the ThreadX kernel. */
|
||||
tx_kernel_enter();
|
||||
}
|
||||
|
||||
|
||||
/* Define what the initial system looks like. */
|
||||
VOID tx_application_define(VOID *first_unused_memory)
|
||||
{
|
||||
|
||||
VOID* storage_ptr;
|
||||
|
||||
|
||||
struct sched_param param;
|
||||
|
||||
|
||||
/* Init POSIX Wrapper */
|
||||
storage_ptr = (VOID*) posix_initialize((VOID*)free_memory);
|
||||
|
||||
/* Put system definition stuff in here, e.g. pthread creates and other assoerted
|
||||
create information. */
|
||||
|
||||
/* Create pthread attributes. */
|
||||
pthread_attr_init(&ptattr0);
|
||||
pthread_attr_init(&ptattr1);
|
||||
|
||||
/* Create a sched_param structure */
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
/* Now create all pthreads , firstly modify respective ptheread
|
||||
attribute with desired priority and stack start address and then create the pthread */
|
||||
|
||||
/* Create pthread 0. */
|
||||
param.sched_priority = 15;
|
||||
pthread_attr_setschedparam(&ptattr0, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr0, storage_ptr );
|
||||
storage_ptr = (UINT *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_0, &ptattr0,pthread_0_entry,NULL);
|
||||
|
||||
|
||||
/* Create pthread 1. */
|
||||
param.sched_priority = 10;
|
||||
pthread_attr_setschedparam(&ptattr1, ¶m);
|
||||
pthread_attr_setstackaddr(&ptattr1, (VOID*) storage_ptr );
|
||||
storage_ptr = (UINT *) storage_ptr + DEMO_STACK_SIZE;
|
||||
pthread_create (&pthread_1, &ptattr1,pthread_1_entry,NULL);
|
||||
|
||||
|
||||
/* Create a Semaphore. */
|
||||
sem = sem_open("Sem0", O_CREAT | O_EXCL,0,1);
|
||||
}
|
||||
|
||||
|
||||
VOID error_handler(void)
|
||||
{
|
||||
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Define the signal handlers. */
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler13(int signo)
|
||||
{
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 13)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter13++;
|
||||
}
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler14(int signo)
|
||||
{
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 14)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter14++;
|
||||
|
||||
/* Raise another signal for nesting test. */
|
||||
pthread_kill(pthread_0, 13);
|
||||
}
|
||||
|
||||
|
||||
VOID pthread_0_signal_handler15(int signo)
|
||||
{
|
||||
|
||||
/* Check for pthread self call not pthread 0. The signal handler should appear to be
|
||||
called from pthread 0. */
|
||||
if (pthread_self() != pthread_0)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Check for proper signal. */
|
||||
if (signo != 15)
|
||||
{
|
||||
|
||||
/* Call error handler. */
|
||||
error_handler();
|
||||
}
|
||||
|
||||
/* Just increment the signal counter for this test. */
|
||||
pthread_0_signal_counter15++;
|
||||
|
||||
/* Raise another signal for nesting test. */
|
||||
pthread_kill(pthread_0, 14);
|
||||
}
|
||||
|
||||
|
||||
/* Define the test pthreads */
|
||||
INT pt0_status=0;
|
||||
|
||||
|
||||
/* Self signal test. */
|
||||
|
||||
VOID *pthread_0_entry(VOID *pthread0_input)
|
||||
{
|
||||
|
||||
/* Register the signal handlers. */
|
||||
pt0_status = signal(15, pthread_0_signal_handler15);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
pt0_status = signal(14, pthread_0_signal_handler14);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
pt0_status = signal(13, pthread_0_signal_handler13);
|
||||
|
||||
/* Check for error. */
|
||||
if (pt0_status)
|
||||
error_handler();
|
||||
|
||||
|
||||
/* Get the semaphore with suspension. */
|
||||
pt0_status = sem_wait(sem);
|
||||
|
||||
/* This pthread simply sits in while-forever-sleep loop */
|
||||
while(1)
|
||||
{
|
||||
/* Increment the pthread counter.*/
|
||||
pthread_0_counter++;
|
||||
|
||||
/* Get the semaphore with suspension. */
|
||||
pt0_status = sem_wait(sem);
|
||||
|
||||
/* In this test, this thread should never resume! */
|
||||
error_handler();
|
||||
|
||||
/* Check for error condition. */
|
||||
if (pt0_status)
|
||||
{
|
||||
|
||||
/* Break out of the loop. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(&pt0_status);
|
||||
}
|
||||
|
||||
|
||||
INT pt1_status=0;
|
||||
|
||||
VOID *pthread_1_entry(VOID *pthread1_input)
|
||||
{
|
||||
|
||||
|
||||
/* This thread simply sends a messages to a queue shared by pthread 2. */
|
||||
while(1)
|
||||
{
|
||||
|
||||
/* Increment the thread counter. */
|
||||
pthread_1_counter++;
|
||||
|
||||
/* Raise the first signal for pthread 0. */
|
||||
pt1_status = pthread_kill(pthread_0, 15);
|
||||
|
||||
/* Check for errors. */
|
||||
if ((pt1_status) ||
|
||||
(pthread_0_counter != 1) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter15) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter14) ||
|
||||
(pthread_1_counter != pthread_0_signal_counter13))
|
||||
{
|
||||
|
||||
error_handler();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(&pt1_status);
|
||||
}
|
||||
|
||||
58
utility/rtos_compatibility_layers/posix/pthread.h
Normal file
58
utility/rtos_compatibility_layers/posix/pthread.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** ThreadX Component */
|
||||
/** */
|
||||
/** POSIX Compliancy Wrapper (POSIX) */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* EKP DEFINITIONS RELEASE */
|
||||
/* */
|
||||
/* sched.h PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This file defines the constants, structures, etc.needed to */
|
||||
/* implement the Evacuation Kit for POSIX Users (POSIX) */
|
||||
/* */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef _PTHREAD_H
|
||||
#define _PTHREAD_H
|
||||
|
||||
#include "tx_api.h"
|
||||
#include "errno.h"
|
||||
#include "fcntl.h"
|
||||
#include "sched.h"
|
||||
#include "time.h"
|
||||
#include "signal.h"
|
||||
#include "tx_posix.h"
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,92 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
#include "time.h"
|
||||
#include <limits.h>
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_abs_time_to_rel_ticks PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function converts the absolute time specified in a POSIX */
|
||||
/* timespec structure into the relative number of timer ticks until */
|
||||
/* that time will occur. */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
ULONG posix_abs_time_to_rel_ticks(struct timespec *abs_timeout)
|
||||
{
|
||||
ULONG current_ticks, ticks_ns, ticks_sec, timeout_ticks;
|
||||
|
||||
current_ticks = tx_time_get();
|
||||
/* convert ns to ticks (will lose any ns < 1 tick) */
|
||||
ticks_ns = abs_timeout->tv_nsec / NANOSECONDS_IN_CPU_TICK;
|
||||
/*
|
||||
* if ns < 1 tick were lost, bump up to next tick so the delay is never
|
||||
* less than what was specified.
|
||||
*/
|
||||
if (ticks_ns * NANOSECONDS_IN_CPU_TICK != abs_timeout->tv_nsec)
|
||||
{
|
||||
++ticks_ns;
|
||||
}
|
||||
ticks_sec = (ULONG) (abs_timeout->tv_sec * CPU_TICKS_PER_SECOND);
|
||||
/* add in sec. ticks, subtract current ticks to get relative value. */
|
||||
timeout_ticks = ticks_sec + ticks_ns - current_ticks;
|
||||
/*
|
||||
* Unless a relative timeout of zero was specified, bump up 1 tick to
|
||||
* compensate for the fact that there is an unknown time between 0 and
|
||||
* < 1 tick until the next tick. We never want the delay to be less than
|
||||
* what was requested.
|
||||
*/
|
||||
if (timeout_ticks != 0)
|
||||
{
|
||||
++timeout_ticks;
|
||||
}
|
||||
/*
|
||||
* If the absolute time was in the past, then we need to set the
|
||||
* relative time to zero; otherwise, we get an essentially infinite timeout.
|
||||
*/
|
||||
if (timeout_ticks > LONG_MAX)
|
||||
{
|
||||
timeout_ticks = 0;
|
||||
}
|
||||
|
||||
return timeout_ticks;
|
||||
}
|
||||
77
utility/rtos_compatibility_layers/posix/px_clock_getres.c
Normal file
77
utility/rtos_compatibility_layers/posix/px_clock_getres.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* clock_getres PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This subroutine returns the Clock resolution of the Threadx real */
|
||||
/* time clock in nanoseconds */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* clockid_t, tspec */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* error code */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT clock_getres(clockid_t t, struct timespec * tspec)
|
||||
{
|
||||
|
||||
if(t==CLOCK_REALTIME)
|
||||
{
|
||||
if(tspec) tspec->tv_nsec= NANOSECONDS_IN_CPU_TICK;
|
||||
return(OK);
|
||||
}
|
||||
else return(EINVAL);
|
||||
|
||||
}
|
||||
85
utility/rtos_compatibility_layers/posix/px_clock_gettime.c
Normal file
85
utility/rtos_compatibility_layers/posix/px_clock_gettime.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* clock_gettime PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This subroutine returns the time. The source of the time */
|
||||
/* is the internal Threadx timer variable, which keeps track */
|
||||
/* of the number of ticks of the Threadx timer ISR. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* clockid_t, tspec */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* error code */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_time_get ThreadX function */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT clock_gettime(clockid_t t, struct timespec * tspec)
|
||||
{
|
||||
ULONG tx_time;
|
||||
|
||||
if(t==CLOCK_REALTIME)
|
||||
{
|
||||
tx_time=tx_time_get();
|
||||
|
||||
tspec->tv_sec = tx_time / CPU_TICKS_PER_SECOND;
|
||||
|
||||
tspec->tv_nsec = (ULONG) ((tx_time - tspec->tv_sec*CPU_TICKS_PER_SECOND) * NANOSECONDS_IN_CPU_TICK);
|
||||
|
||||
return(OK);
|
||||
}
|
||||
else return(EINVAL);
|
||||
|
||||
}
|
||||
81
utility/rtos_compatibility_layers/posix/px_clock_settime.c
Normal file
81
utility/rtos_compatibility_layers/posix/px_clock_settime.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* clock_settime PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This subroutine sets the internal Threadx timer tick variable */
|
||||
/* to the time specificed in the tspec variable after conversion */
|
||||
/* if tspec->tv_sec is 0 the clock with be set to the value of */
|
||||
/* tspec->tv_nsec */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* clockid_t, tspec */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* error code */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_time_set ThreadX function */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT clock_settime(clockid_t t, const struct timespec * tspec)
|
||||
{
|
||||
ULONG tx_time;
|
||||
|
||||
if(t==CLOCK_REALTIME)
|
||||
{
|
||||
tx_time=(ULONG)((tspec->tv_sec * CPU_TICKS_PER_SECOND) + (tspec->tv_nsec / NANOSECONDS_IN_CPU_TICK));
|
||||
tx_time_set( tx_time);
|
||||
return(OK);
|
||||
}
|
||||
else return(EINVAL);
|
||||
}
|
||||
147
utility/rtos_compatibility_layers/posix/px_cond_broadcast.c
Normal file
147
utility/rtos_compatibility_layers/posix/px_cond_broadcast.c
Normal file
@@ -0,0 +1,147 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_cond_broadcast PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* These functions shall unblock all threads currently blocked on a */
|
||||
/* specified condition variable cond. */
|
||||
/* If more than one thread is blocked on a condition variable, */
|
||||
/* the scheduling policy shall determine the order in which threads are*/
|
||||
/* unblocked. When each thread unblocked as a result of this function */
|
||||
/* call returns from its call to pthread_cond_wait or */
|
||||
/* pthread_cond_timedwait, the thread shall own the mutex with which it*/
|
||||
/* called pthread_cond_wait or pthread_cond_timedwait. The thread(s) */
|
||||
/* that are unblocked shall contend for the mutex according to the */
|
||||
/* scheduling policy (if applicable), and as if each had called */
|
||||
/* pthread_mutex_lock.The pthread_cond_broadcast function may be called*/
|
||||
/* by a thread whether or not it currently owns the mutex that threads */
|
||||
/* calling pthread_cond_wait or pthread_cond_timedwait have associated */
|
||||
/* with the condition variable during their waits; however, */
|
||||
/* if predictable scheduling behavior is required, then that mutex */
|
||||
/* shall be locked by the thread calling pthread_cond_broadcast. */
|
||||
/* The pthread_cond_broadcast function shall have no effect if there */
|
||||
/* are no threads currently blocked on cond. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* cond condition variable */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* Ok if successful */
|
||||
/* Error in case of any errors */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_semaphore_prioritize line up pthreads waiting at semaphore*/
|
||||
/* tx_thread_identify to check which pthread? */
|
||||
/* tx_thread_preemption_change to disable thread preemption */
|
||||
/* tx_semaphore_put ThreadX semaphore put service */
|
||||
/* tx_thread_preemption_change to enable thread preemption */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_cond_broadcast(pthread_cond_t *cond)
|
||||
{
|
||||
|
||||
TX_SEMAPHORE *semaphore_ptr;
|
||||
TX_THREAD *thread;
|
||||
UINT status;
|
||||
ULONG sem_count;
|
||||
UINT old_threshold,dummy;
|
||||
|
||||
|
||||
/* Get the condition variable's internal semaphore. */
|
||||
/* Simply convert the condition variable control block into a semaphore a cast */
|
||||
semaphore_ptr = (&( cond->cond_semaphore ));
|
||||
sem_count = semaphore_ptr->tx_semaphore_suspended_count;
|
||||
|
||||
if (!sem_count)
|
||||
return(OK);
|
||||
|
||||
status = tx_semaphore_prioritize(semaphore_ptr);
|
||||
|
||||
if ( status != TX_SUCCESS)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
/* get to know about current thread */
|
||||
thread = tx_thread_identify();
|
||||
|
||||
/* Got the current thread , now raise its preemption threshold */
|
||||
/* that way the current thread does not get descheduled when */
|
||||
/* threads with higher priority are activated */
|
||||
tx_thread_preemption_change(thread,0,&old_threshold);
|
||||
|
||||
while( sem_count)
|
||||
{
|
||||
|
||||
status = tx_semaphore_put(semaphore_ptr);
|
||||
if ( status != TX_SUCCESS)
|
||||
{
|
||||
|
||||
/* restore changed preemption threshold */
|
||||
tx_thread_preemption_change(thread,old_threshold,&dummy);
|
||||
|
||||
posix_errno = EINVAL;
|
||||
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
sem_count--;
|
||||
}
|
||||
|
||||
/* restore changed preemption threshold */
|
||||
tx_thread_preemption_change(thread,old_threshold,&dummy);
|
||||
return(OK);
|
||||
}
|
||||
101
utility/rtos_compatibility_layers/posix/px_cond_destroy.c
Normal file
101
utility/rtos_compatibility_layers/posix/px_cond_destroy.c
Normal file
@@ -0,0 +1,101 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_cond_destroy PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* The pthread_cond_destroy function shall destroy the given condition */
|
||||
/* variable specified by cond; the object becomes, in effect, */
|
||||
/* uninitialized. */
|
||||
/* A destroyed condition variable object can be reinitialized using */
|
||||
/* pthread_cond_init;referencing the object after it has been destroyed*/
|
||||
/* returns error. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* cond condition variable object */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* OK If successful */
|
||||
/* EINVAL If error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_semaphore_delete Deletes a semaphore internal to */
|
||||
/* to the cond variable */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_cond_destroy(pthread_cond_t *cond)
|
||||
{
|
||||
|
||||
TX_SEMAPHORE *semaphore_ptr;
|
||||
UINT status;
|
||||
|
||||
if (cond->in_use == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
cond->in_use = TX_FALSE;
|
||||
/* Get the condition variable's internal semaphore. */
|
||||
/* Simply convert the Condition variable control block into a semaphore a cast */
|
||||
semaphore_ptr = (&( cond->cond_semaphore ));
|
||||
status = tx_semaphore_delete(semaphore_ptr);
|
||||
if (status != TX_SUCCESS)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
|
||||
93
utility/rtos_compatibility_layers/posix/px_cond_init.c
Normal file
93
utility/rtos_compatibility_layers/posix/px_cond_init.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_cond_init PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall initialize the condition variable referenced by */
|
||||
/* cond with attributes referenced by attr. If attr is NULL,the default*/
|
||||
/* condition variable attributes shall be used; the effect is the same */
|
||||
/* as passing the address of a default condition variable attributes */
|
||||
/* object. Upon successful initialization, the state of the condition */
|
||||
/* variable shall become initialized. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* Nothing */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* cond condition variable object */
|
||||
/* attr attributes */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_semaphore_create create a semaphore internal to */
|
||||
/* cond variable */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr)
|
||||
{
|
||||
|
||||
TX_SEMAPHORE *semaphore_ptr;
|
||||
UINT status;
|
||||
|
||||
cond->in_use = TX_TRUE;
|
||||
/* Get the condition variable's internal semaphore. */
|
||||
/* Simply convert the COndition variable control block into a semaphore a cast */
|
||||
semaphore_ptr = (&( cond->cond_semaphore ));
|
||||
/* Now create the internal semaphore for this cond variable */
|
||||
status = tx_semaphore_create(semaphore_ptr,"csem",0);
|
||||
if (status != TX_SUCCESS)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
return(OK);
|
||||
}
|
||||
113
utility/rtos_compatibility_layers/posix/px_cond_signal.c
Normal file
113
utility/rtos_compatibility_layers/posix/px_cond_signal.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_cond_signal PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall unblock at least one of the threads that are */
|
||||
/* blocked on the specified condition variable cond */
|
||||
/* (if any threads are blocked on cond).If more than one thread is */
|
||||
/* blocked on a condition variable, the scheduling policy shall */
|
||||
/* determine the order in which threads are unblocked.When each thread */
|
||||
/* unblocked as a result of a pthread_cond_signal returns from its call*/
|
||||
/* to pthread_cond_wait or pthread_cond_timedwait, the thread shall own*/
|
||||
/* the mutex with which it called pthread_cond_wait or */
|
||||
/* pthread_cond_timedwait.The thread(s) that are unblocked shall */
|
||||
/* contend for the mutex according to the scheduling policy */
|
||||
/* (if applicable), and as if each had called pthread_mutex_lock. */
|
||||
/* The pthread_cond_broadcast or pthread_cond_signal functions may be */
|
||||
/* called by a thread whether or not it currently owns the mutex that */
|
||||
/* threads calling pthread_cond_wait or pthread_cond_timedwait have */
|
||||
/* associated with the condition variable during their waits; however, */
|
||||
/* if predictable scheduling behavior is required,then that mutex shall*/
|
||||
/* be locked by the thread calling pthread_cond_signal. */
|
||||
/* This function shall have no effect if there are no threads currently*/
|
||||
/* blocked on cond. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* Nothing */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* Nothing */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_semaphore_prioritize line up pthreads waiting at semaphore*/
|
||||
/* tx_semaphore_put ThreadX semaphore put service */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_cond_signal(pthread_cond_t *cond)
|
||||
{
|
||||
|
||||
TX_SEMAPHORE *semaphore_ptr;
|
||||
UINT status;
|
||||
|
||||
/* Get the condition variable's internal semaphore. */
|
||||
/* Simply convert the COndition variable control block into a semaphore a cast */
|
||||
semaphore_ptr = (&( cond->cond_semaphore ));
|
||||
if ( semaphore_ptr->tx_semaphore_suspended_count)
|
||||
{
|
||||
status = tx_semaphore_prioritize(semaphore_ptr);
|
||||
if ( status != TX_SUCCESS)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
status = tx_semaphore_put(semaphore_ptr);
|
||||
if ( status != TX_SUCCESS)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
145
utility/rtos_compatibility_layers/posix/px_cond_timedwait.c
Normal file
145
utility/rtos_compatibility_layers/posix/px_cond_timedwait.c
Normal file
@@ -0,0 +1,145 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_cond_timedwait PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall block on a condition variable. They shall be */
|
||||
/* called with mutex locked by the calling thread or undefined behavior*/
|
||||
/* results.These functions atomically release the mutex and cause the */
|
||||
/* calling thread to block on the condition variable cond; atomically */
|
||||
/* here means <20><>atomically with respect to access by another */
|
||||
/* thread to the mutex and then the request for semaphore. */
|
||||
/* */
|
||||
/* Upon successful return, the mutex shall have been locked and shall */
|
||||
/* be owned by the calling thread. */
|
||||
/* */
|
||||
/* Upon successful return, the mutex shall have been locked and shall */
|
||||
/* be owned by the calling thread. */
|
||||
/* When using condition variables there is always a Boolean predicate */
|
||||
/* involving shared variables associated with each condition wait that */
|
||||
/* is true if the thread should proceed. Spurious wakeups from the */
|
||||
/* pthread_cond_timedwait or pthread_cond_wait functions may occur. */
|
||||
/* Since the return from pthread_cond_timedwait or pthread_cond_wait */
|
||||
/* does not imply anything about the value of this predicate, the */
|
||||
/* predicate should be re-evaluated upon such return. The effect of */
|
||||
/* using more than one mutex for concurrent pthread_cond_timedwait or */
|
||||
/* pthread_cond_wait operations on the same condition variable is */
|
||||
/* undefined; that is, a condition variable becomes bound to a unique */
|
||||
/* mutex when a thread waits on the condition variable, and this */
|
||||
/* (dynamic) binding shall end when the wait returns. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* cond condition variable */
|
||||
/* mutex mutex to be associated with condition */
|
||||
/* variable */
|
||||
/* abstime time interval for wait */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* OK if succesfull */
|
||||
/* ERROR in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* pthread_mutex_unlock unlocks the mutex held by the caller */
|
||||
/* tx_semaphore_get try to get sempaphore internal to cond */
|
||||
/* tx_semaphore_prioritize prioritize all suspended pthreads */
|
||||
/* pthread_mutex_lock lock the mutex */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_cond_timedwait(pthread_cond_t *cond,pthread_mutex_t *mutex,
|
||||
struct timespec *abstime)
|
||||
{
|
||||
|
||||
TX_SEMAPHORE *semaphore_ptr;
|
||||
ULONG wait_option;
|
||||
UINT status;
|
||||
UINT old_threshold,dummy;
|
||||
TX_THREAD *thread;
|
||||
|
||||
/* Find the current thread. */
|
||||
thread = tx_thread_identify();
|
||||
|
||||
/* Raise its preemption threshold so it does not get descheduled. */
|
||||
tx_thread_preemption_change(thread,0,&old_threshold);
|
||||
|
||||
pthread_mutex_unlock(mutex);
|
||||
semaphore_ptr = (&( cond->cond_semaphore ));
|
||||
|
||||
wait_option = posix_abs_time_to_rel_ticks(abstime);
|
||||
|
||||
status = tx_semaphore_get(semaphore_ptr, wait_option);
|
||||
|
||||
/* Restore original preemption threshold */
|
||||
tx_thread_preemption_change(thread, old_threshold, &dummy);
|
||||
|
||||
if( status == TX_NO_INSTANCE)
|
||||
{
|
||||
posix_errno = ETIMEDOUT;
|
||||
posix_set_pthread_errno(ETIMEDOUT);
|
||||
return(ETIMEDOUT);
|
||||
}
|
||||
else if ( status != TX_SUCCESS)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
status = tx_semaphore_prioritize(semaphore_ptr);
|
||||
if (status != TX_SUCCESS)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
pthread_mutex_lock(mutex);
|
||||
|
||||
return(OK);
|
||||
}
|
||||
135
utility/rtos_compatibility_layers/posix/px_cond_wait.c
Normal file
135
utility/rtos_compatibility_layers/posix/px_cond_wait.c
Normal file
@@ -0,0 +1,135 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_cond_wait PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall block on a condition variable. They shall be */
|
||||
/* called with mutex locked by the calling thread or undefined behavior*/
|
||||
/* results. These functions atomically release the mutex and cause the */
|
||||
/* calling thread to block on the condition variable cond; atomically */
|
||||
/* here means atomically with respect to access by another thread to */
|
||||
/* the mutex and then the request for semaphore. */
|
||||
/* */
|
||||
/* Upon successful return, the mutex shall have been locked and shall */
|
||||
/* be owned by the calling thread. */
|
||||
/* */
|
||||
/* When using condition variables there is always a Boolean predicate */
|
||||
/* involving shared variables associated with each condition wait that */
|
||||
/* is true if the thread should proceed. Spurious wakeups from the */
|
||||
/* pthread_cond_timedwait or pthread_cond_wait functions may occur. */
|
||||
/* Since the return from pthread_cond_timedwait or pthread_cond_wait */
|
||||
/* does not imply anything about the value of this predicate, the */
|
||||
/* predicate should be re-evaluated upon such return. The effect of */
|
||||
/* using more than one mutex for concurrent pthread_cond_timedwait or */
|
||||
/* pthread_cond_wait operations on the same condition variable is */
|
||||
/* undefined; that is, a condition variable becomes bound to a unique */
|
||||
/* mutex when a thread waits on the condition variable, and this */
|
||||
/* (dynamic) binding shall end when the wait returns. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* cond condition variable */
|
||||
/* mutex mutex to be associated with condition */
|
||||
/* variable */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* OK if succesfull */
|
||||
/* ERROR in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* pthread_mutex_unlock unlocks the mutex held by the caller */
|
||||
/* tx_semaphore_get try to get sempaphore internal to cond */
|
||||
/* tx_semaphore_prioritize prioritize all suspended pthreads */
|
||||
/* pthread_mutex_lock lock the mutex */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
{
|
||||
|
||||
TX_SEMAPHORE *semaphore_ptr;
|
||||
UINT status;
|
||||
UINT old_threshold,dummy;
|
||||
TX_THREAD *thread;
|
||||
|
||||
/* Find the current thread. */
|
||||
thread = tx_thread_identify();
|
||||
|
||||
/* Raise its preemption threshold so it does not get descheduled. */
|
||||
tx_thread_preemption_change(thread,0,&old_threshold);
|
||||
|
||||
pthread_mutex_unlock(mutex);
|
||||
|
||||
semaphore_ptr = (&( cond->cond_semaphore ));
|
||||
|
||||
status = tx_semaphore_get(semaphore_ptr, TX_WAIT_FOREVER);
|
||||
|
||||
/* Restore original preemption threshold. */
|
||||
tx_thread_preemption_change(thread, old_threshold, &dummy);
|
||||
|
||||
|
||||
if ( status != TX_SUCCESS)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
status = tx_semaphore_prioritize(semaphore_ptr);
|
||||
|
||||
if ( status != TX_SUCCESS)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(mutex);
|
||||
return(OK);
|
||||
}
|
||||
113
utility/rtos_compatibility_layers/posix/px_error.c
Normal file
113
utility/rtos_compatibility_layers/posix/px_error.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_error_handler PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function is invoked whenever an error is encountered */
|
||||
/* in the POSIX code. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* error_code Error code to handle */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_error_handler(ULONG error_code)
|
||||
{
|
||||
while (error_code) { ; }
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_internal_error PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function is invoked whenever an error is encountered */
|
||||
/* in the POSIX code. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* error_code Error code to handle */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_internal_error(ULONG error_code)
|
||||
{
|
||||
while (error_code) { ; }
|
||||
}
|
||||
107
utility/rtos_compatibility_layers/posix/px_in_thread_context.c
Normal file
107
utility/rtos_compatibility_layers/posix/px_in_thread_context.c
Normal file
@@ -0,0 +1,107 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_in_thread_context PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function determines if the system is currently in "thread" */
|
||||
/* context, i.e. not timer routine, not ISR, not idling. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* TX_TRUE | TX_FALSE */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* posix internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
ULONG posix_in_thread_context(VOID)
|
||||
{
|
||||
/* External variables, defined within ThreadX, needed here. */
|
||||
extern TX_THREAD * _tx_thread_current_ptr;
|
||||
extern ULONG _tx_thread_system_state;
|
||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
||||
extern TX_THREAD _tx_timer_thread;
|
||||
#endif
|
||||
|
||||
/* Return TX_FALSE if any of the following are true:
|
||||
- we are in the scheduling loop (not in a thread);
|
||||
- we are in an ISR
|
||||
- we are in a timer routine
|
||||
Return TX_TRUE otherwise (we are in a thread.)
|
||||
*/
|
||||
|
||||
if (_tx_thread_system_state == TX_INITIALIZE_IN_PROGRESS)
|
||||
{
|
||||
|
||||
/* We are calling from initialization, return TRUE. */
|
||||
return(TX_TRUE);
|
||||
}
|
||||
else if ((!_tx_thread_current_ptr) /* Not in a thread */
|
||||
|| (_tx_thread_system_state) /* In an ISR */
|
||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
||||
/* Timer routine */
|
||||
|| (_tx_thread_current_ptr == &_tx_timer_thread)
|
||||
#endif
|
||||
)
|
||||
|
||||
{
|
||||
/* We are NOT in thread (thread) context. */
|
||||
return (TX_FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We ARE in thread (thread) context. */
|
||||
return (TX_TRUE);
|
||||
}
|
||||
}
|
||||
213
utility/rtos_compatibility_layers/posix/px_int.h
Normal file
213
utility/rtos_compatibility_layers/posix/px_int.h
Normal file
@@ -0,0 +1,213 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** ThreadX Component */
|
||||
/** */
|
||||
/** POSIX Compliancy Wrapper (POSIX) */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* EKP DEFINITIONS RELEASE */
|
||||
/* */
|
||||
/* px_int.h PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This file defines the constants, structures, etc.needed to */
|
||||
/* implement the Evacuation Kit for POSIX Users (POSIX) */
|
||||
/* */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef _TX_PX_INT_H
|
||||
#define _TX_PX_INT_H
|
||||
|
||||
#include "string.h"
|
||||
|
||||
/* Define several ThreadX equates for use inside of POSIX. */
|
||||
#define TX_INITIALIZE_IN_PROGRESS 0xF0F0F0F0UL
|
||||
#define TX_INITIALIZE_ALMOST_DONE 0xF0F0F0F1UL
|
||||
|
||||
/* Include necessary definition for memory related routines(from tx_byt.c). */
|
||||
#define TX_BYTE_BLOCK_FREE 0xFFFFEEEEUL
|
||||
#define TX_BYTE_BLOCK_ALLOC 0xAAAAAAAAUL
|
||||
#define TX_BYTE_POOL_ID 0x42595445UL
|
||||
|
||||
/* Threadx min and max priority */
|
||||
#define TX_HIGHEST_PRIORITY 1
|
||||
#define TX_LOWEST_PRIORITY 31
|
||||
|
||||
#define PX_HIGHEST_PRIORITY 31
|
||||
#define PX_LOWEST_PRIORITY 1
|
||||
|
||||
/************ Extern Variables **************/
|
||||
extern TX_THREAD * _tx_thread_current_ptr;
|
||||
extern TX_THREAD * _tx_thread_execute_ptr;
|
||||
|
||||
|
||||
|
||||
/* declares posix objects in the px_pth_init.c file */
|
||||
#ifdef PX_OBJECT_INIT
|
||||
#define PX_OBJECT_DECLARE
|
||||
#else
|
||||
#define PX_OBJECT_DECLARE extern
|
||||
#endif
|
||||
/**************************************************************************/
|
||||
/* Global Definitions */
|
||||
/**************************************************************************/
|
||||
|
||||
/* The ThreadX work queue for the POSIX System Manager. */
|
||||
PX_OBJECT_DECLARE TX_QUEUE posix_work_queue;
|
||||
|
||||
/* Define the thread for the System Manager functionality. */
|
||||
PX_OBJECT_DECLARE TX_THREAD posix_system_manager;
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* Local definitions */
|
||||
/**************************************************************************/
|
||||
|
||||
/* Define a byte pool control block for the heap memory used
|
||||
by POSIX. */
|
||||
|
||||
PX_OBJECT_DECLARE TX_BYTE_POOL posix_heap_byte_pool;
|
||||
|
||||
/* Define a static pool of pthread Control Blocks (TCB). If more pthreades are
|
||||
required the constant PTHREAD_THREADS_MAX (in tx_posix.h) may be modified. */
|
||||
PX_OBJECT_DECLARE POSIX_TCB ptcb_pool[PTHREAD_THREADS_MAX];
|
||||
|
||||
#if POSIX_MAX_QUEUES!= 0
|
||||
/* Define a static pool of queues.If more pthread message queues are required
|
||||
the constant POSIX_MAX_QUEUES (in tx_posix.h) may be modified. */
|
||||
PX_OBJECT_DECLARE POSIX_MSG_QUEUE posix_queue_pool[POSIX_MAX_QUEUES];
|
||||
/* Define a queue attribute. */
|
||||
PX_OBJECT_DECLARE struct mq_attr posix_qattr_default;
|
||||
#endif
|
||||
|
||||
#if SEM_NSEMS_MAX != 0
|
||||
/* Define a static pool of semaphores. If more pthread semaphores required the
|
||||
constant SEM_NSEMS_MAX (in tx_posix.h) may be modified. */
|
||||
PX_OBJECT_DECLARE sem_t posix_sem_pool[SEM_NSEMS_MAX];
|
||||
|
||||
#endif
|
||||
|
||||
/* Define a default pthread attribute. */
|
||||
PX_OBJECT_DECLARE pthread_attr_t posix_default_pthread_attr;
|
||||
|
||||
/* Define a default mutex attribute. */
|
||||
PX_OBJECT_DECLARE pthread_mutexattr_t posix_default_mutex_attr;
|
||||
|
||||
|
||||
|
||||
/* Define a temporary posix errno. */
|
||||
|
||||
PX_OBJECT_DECLARE unsigned int posix_errno;
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* Local prototypes */
|
||||
/**************************************************************************/
|
||||
/* Define Evacuation Kit for POSIX function prototypes. */
|
||||
|
||||
INT posix_get_pthread_errno(pthread_t ptid);
|
||||
|
||||
POSIX_MSG_QUEUE *posix_mq_create ( const CHAR * mq_name,
|
||||
struct mq_attr * msgq_attr);
|
||||
|
||||
POSIX_MSG_QUEUE *posix_find_queue(const CHAR * mq_name);
|
||||
|
||||
POSIX_MSG_QUEUE *posix_get_new_queue(ULONG maxnum);
|
||||
|
||||
ULONG posix_arrange_msg( TX_QUEUE * Queue, ULONG * pMsgPrio );
|
||||
|
||||
ULONG posix_priority_search(mqd_t msgQId ,ULONG priority);
|
||||
|
||||
VOID posix_queue_init(VOID);
|
||||
|
||||
VOID posix_qattr_init(VOID);
|
||||
|
||||
VOID posix_pthread_init(VOID);
|
||||
|
||||
struct mq_des *posix_get_queue_des(POSIX_MSG_QUEUE * q_ptr);
|
||||
|
||||
VOID posix_reset_queue(POSIX_MSG_QUEUE * q_ptr);
|
||||
|
||||
VOID posix_memory_release(VOID * memory_ptr);
|
||||
|
||||
VOID posix_internal_error(ULONG error_code);
|
||||
|
||||
VOID posix_error_handler(ULONG error_code);
|
||||
|
||||
INT posix_memory_allocate(ULONG size, VOID **memory_ptr);
|
||||
|
||||
INT posix_queue_delete(POSIX_MSG_QUEUE * q_ptr);
|
||||
|
||||
VOID posix_putback_queue(TX_QUEUE * qid);
|
||||
|
||||
sem_t *posix_find_sem(const CHAR * name);
|
||||
|
||||
VOID posix_set_sem_name(sem_t * sem, CHAR *name);
|
||||
|
||||
TX_SEMAPHORE *posix_get_new_sem(VOID);
|
||||
|
||||
VOID posix_sem_reset(sem_t *sem);
|
||||
|
||||
ULONG posix_in_thread_context(VOID);
|
||||
|
||||
VOID posix_reset_pthread_t(POSIX_TCB *ptcb);
|
||||
|
||||
TX_THREAD *posix_tid2thread(pthread_t ptid);
|
||||
|
||||
POSIX_TCB *posix_tid2tcb(pthread_t ptid);
|
||||
|
||||
pthread_t posix_thread2tid(TX_THREAD *thread_ptr);
|
||||
|
||||
POSIX_TCB *posix_thread2tcb(TX_THREAD *thread_ptr);
|
||||
|
||||
TX_THREAD *posix_tcb2thread (POSIX_TCB *pthread_ptr);
|
||||
|
||||
VOID posix_thread_wrapper(ULONG pthr_ptr);
|
||||
|
||||
VOID set_default_pthread_attr(pthread_attr_t *attr);
|
||||
|
||||
VOID set_default_mutexattr(pthread_mutexattr_t *attr);
|
||||
|
||||
INT posix_allocate_pthread_t(POSIX_TCB **ptcb_ptr);
|
||||
|
||||
VOID posix_copy_pthread_attr(POSIX_TCB *pthread_ptr,pthread_attr_t *attr);
|
||||
|
||||
VOID posix_destroy_pthread(POSIX_TCB *pthread_ptr, VOID *value_ptr);
|
||||
|
||||
VOID posix_do_pthread_delete(POSIX_TCB *pthread_ptr, VOID *value_ptr);
|
||||
|
||||
VOID posix_system_manager_entry(ULONG input);
|
||||
|
||||
INT posix_set_pthread_errno(ULONG errno_set);
|
||||
|
||||
ULONG posix_abs_time_to_rel_ticks(struct timespec *abs_timeout);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,167 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
#include "tx_thread.h" /* Internal ThreadX thread management. */
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* internal_signal_dispatch PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* Signal handler thread. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* id Signal */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* none */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_internal_error Generic error Handler */
|
||||
/* tx_thread_identify */
|
||||
/* tx_event_flags_set */
|
||||
/* tx_thread_resume */
|
||||
/* posix_destroy_pthread */
|
||||
/* tx_thread_suspend */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Internal Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
void internal_signal_dispatch(ULONG id)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
POSIX_TCB *signal_thread;
|
||||
POSIX_TCB *target_thread;
|
||||
VOID (*handler)(int);
|
||||
|
||||
|
||||
/* Determine if the desired signal is valid. */
|
||||
if (id > SIGRTMAX)
|
||||
{
|
||||
|
||||
/* System error! */
|
||||
posix_internal_error(444);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Pickup signal thread. */
|
||||
signal_thread = (POSIX_TCB *) tx_thread_identify();
|
||||
|
||||
/* Is it non-NULL? */
|
||||
if (!signal_thread)
|
||||
{
|
||||
|
||||
/* System error! */
|
||||
posix_internal_error(444);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Pickup target thread. */
|
||||
target_thread = signal_thread -> signals.base_thread_ptr;
|
||||
|
||||
/* Pickup signal handler function pointer. */
|
||||
handler = target_thread -> signals.signal_func[id];
|
||||
|
||||
/* See if there is a signal handler setup for this signal. */
|
||||
if (handler)
|
||||
{
|
||||
|
||||
/* Yes, there is a signal handler - call it! */
|
||||
(handler)((int) id);
|
||||
}
|
||||
|
||||
/* Set the event flag corresponding the signal. */
|
||||
tx_event_flags_set(&(target_thread -> signals.signal_event_flags), (((ULONG) 1) << id), TX_OR);
|
||||
|
||||
/* Ensure the flag is left in a clear state. */
|
||||
tx_event_flags_set(&(target_thread -> signals.signal_event_flags), ~(((ULONG) 1) << id), TX_AND);
|
||||
|
||||
/* Now we need to clear this signal and terminate this signal handler thread. */
|
||||
|
||||
/* Disable interrupts. */
|
||||
TX_DISABLE
|
||||
|
||||
/* Clear this signal from the pending list. */
|
||||
target_thread -> signals.signal_pending.signal_set = target_thread -> signals.signal_pending.signal_set & ~(((unsigned long) 1) << id);
|
||||
|
||||
/* Decrement the signal nesting count. */
|
||||
target_thread -> signals.signal_nesting_depth--;
|
||||
|
||||
/* Is this the last nested signal leaving? */
|
||||
if (target_thread -> signals.signal_nesting_depth == 0)
|
||||
{
|
||||
|
||||
/* Clear the top signal thread link and resume the target thread. */
|
||||
target_thread -> signals.top_signal_thread = NULL;
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Resume the target thread. */
|
||||
tx_thread_resume((TX_THREAD *) target_thread);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Otherwise, there are more signal threads still active. */
|
||||
|
||||
/* Setup the new top signal thread pointer. */
|
||||
target_thread -> signals.top_signal_thread = signal_thread -> signals.next_signal_thread;
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Resume the signal handler thread. */
|
||||
tx_thread_resume((TX_THREAD *) signal_thread -> signals.next_signal_thread);
|
||||
}
|
||||
|
||||
/* Now we need to mark this signal thread for destruction. */
|
||||
posix_destroy_pthread(signal_thread,(VOID *) 0);
|
||||
|
||||
/* Self-suspend the current signal thread. */
|
||||
tx_thread_suspend((TX_THREAD *) signal_thread);
|
||||
}
|
||||
100
utility/rtos_compatibility_layers/posix/px_memory_allocate.c
Normal file
100
utility/rtos_compatibility_layers/posix/px_memory_allocate.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_memory_allocate PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function attempts to obtain the specified amount of memory */
|
||||
/* from the POSIX heap. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* size Number of bytes in the pool */
|
||||
/* memory_ptr Pointer to memory ptr variable*/
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* ERROR If error occurs */
|
||||
/* retval Return value */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_byte_allocate Allocate from the pool */
|
||||
/* posix_internal_error Generic posix error */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT posix_memory_allocate(ULONG size, VOID **memory_ptr)
|
||||
{
|
||||
|
||||
INT retval;
|
||||
|
||||
/* Init in case we fail. */
|
||||
*memory_ptr = (VOID *)0;
|
||||
|
||||
/* Force all alignments to long word boundaries to be safe. */
|
||||
if (size & 0x03)
|
||||
{
|
||||
/* Bump size up to next 4 byte boundary. */
|
||||
size = ((size + 0x03) & ~0x03);
|
||||
}
|
||||
/* Attempt to allocate the desired memory from the POSIX heap.
|
||||
Do not wait - if memory isn't available, flag an error. */
|
||||
retval = tx_byte_allocate((TX_BYTE_POOL *)&posix_heap_byte_pool, memory_ptr,
|
||||
size, TX_NO_WAIT);
|
||||
|
||||
/* Make sure the memory was obtained successfully. */
|
||||
if (retval)
|
||||
{
|
||||
/* Error obtaining memory. */
|
||||
posix_internal_error(555);
|
||||
/* return error. */
|
||||
return(ERROR);
|
||||
}
|
||||
/* Return to caller. */
|
||||
return(retval);
|
||||
}
|
||||
84
utility/rtos_compatibility_layers/posix/px_memory_release.c
Normal file
84
utility/rtos_compatibility_layers/posix/px_memory_release.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_memory_release PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function attempts to return the specified memory region back */
|
||||
/* into the POSIX heap. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* memory_ptr Memory pointer to return */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_byte_release Release the memory */
|
||||
/* posix_internal_error internal error handler */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_memory_release(VOID * memory_ptr)
|
||||
{
|
||||
|
||||
/* Check if memory_ptr is part of the POSIX byte pool,
|
||||
* if not just return */
|
||||
if (((CHAR *)memory_ptr >=
|
||||
(CHAR *)&posix_heap_byte_pool.tx_byte_pool_start) ||
|
||||
((CHAR *)memory_ptr <=
|
||||
(CHAR *)posix_heap_byte_pool.tx_byte_pool_start
|
||||
+ posix_heap_byte_pool.tx_byte_pool_size)) {
|
||||
tx_byte_release(memory_ptr);
|
||||
}
|
||||
|
||||
/* Return to caller. */
|
||||
return;
|
||||
}
|
||||
178
utility/rtos_compatibility_layers/posix/px_mq_arrange_msg.c
Normal file
178
utility/rtos_compatibility_layers/posix/px_mq_arrange_msg.c
Normal file
@@ -0,0 +1,178 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_arrange_msg PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* arrange messages from the queue */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* Queue queue descriptor */
|
||||
/* *pMsgPrio If not NULL, priority of message */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* OK Always return successful */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
ULONG posix_arrange_msg( TX_QUEUE *Queue, ULONG *pMsgPrio )
|
||||
{
|
||||
|
||||
ULONG* Qread; /* to store read ptr of the queue */
|
||||
ULONG* temp_q = TX_NULL; /* temp storage for the message pointer */
|
||||
ULONG numMsgs; /* no of messages queued */
|
||||
ULONG msg; /* temp variable for thr for loop */
|
||||
ULONG priority; /* priority of the message */
|
||||
ULONG maxPrio; /* max. priority of the messages in queue*/
|
||||
ULONG number2; /* messages */
|
||||
ULONG minNo; /* oldest message in the same priority */
|
||||
ULONG swap; /* temp.variable for the swapping of the */
|
||||
/* messages */
|
||||
|
||||
/* initialize the priority to the lowest priority. */
|
||||
maxPrio = 0;
|
||||
minNo=0;
|
||||
|
||||
/* Copy read pointer to the temporary variable. */
|
||||
Qread = Queue -> tx_queue_read;
|
||||
|
||||
/* Copy no. of messages in the queue to the temporary variable. */
|
||||
numMsgs = Queue -> tx_queue_enqueued;
|
||||
|
||||
if( numMsgs == 0 )
|
||||
return(OK);
|
||||
|
||||
for( msg = 0; msg < numMsgs; msg ++)
|
||||
{
|
||||
|
||||
/* Advance Qread by two pointers to read the priority of the message. */
|
||||
Qread = Qread + 2 ;
|
||||
|
||||
/* Priority of the message queued. */
|
||||
priority = *Qread;
|
||||
|
||||
/* check with maxpriority. */
|
||||
if( priority > maxPrio )
|
||||
{
|
||||
/* copy read pointer to temporary buffer. */
|
||||
temp_q = Qread-2;
|
||||
/* increment read pointer to point to order. */
|
||||
Qread++;
|
||||
|
||||
/* copy FIFO order to the message */
|
||||
minNo = *Qread;
|
||||
/* Found higher priority message. */
|
||||
maxPrio = priority;
|
||||
|
||||
Qread++;
|
||||
}
|
||||
|
||||
/* if more than one same priority messages are in the queue
|
||||
then check if this the oldest one. */
|
||||
else if ( priority == maxPrio )
|
||||
{
|
||||
/* increment read pointer to point to read FIFO order */
|
||||
Qread++;
|
||||
|
||||
/* copy number to the local varialble. */
|
||||
number2 = *Qread;
|
||||
Qread++;
|
||||
/* find the oldest of the messages in this priority level. */
|
||||
if( number2 < minNo )
|
||||
{
|
||||
/* founder older one */
|
||||
minNo = number2;
|
||||
/* copy read pointer to temporary buffer. */
|
||||
temp_q = Qread - 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
Qread = Qread + 2;
|
||||
|
||||
/* Determine if we are at the end. */
|
||||
if ( Qread >= Queue ->tx_queue_end)
|
||||
|
||||
/* Yes, wrap around to the beginning. */
|
||||
Qread = Queue -> tx_queue_start;
|
||||
}
|
||||
|
||||
/* All messages checked temp holds address of highest priority message and
|
||||
maxPrio holds the highest priority*/
|
||||
|
||||
if( pMsgPrio != NULL )
|
||||
{
|
||||
/* copy message priority. */
|
||||
*pMsgPrio = maxPrio;
|
||||
}
|
||||
|
||||
/* Get the current queue read pointer */
|
||||
Qread = Queue -> tx_queue_read;
|
||||
|
||||
/* if(*pMsgPrio != *(Qread + 2) || minNo < *(Qread + 3))*/
|
||||
{
|
||||
/* Swap the messages. */
|
||||
for ( msg = 0; msg < 4; msg++)
|
||||
{
|
||||
|
||||
swap = *temp_q;
|
||||
*temp_q = *Qread;
|
||||
*Qread = swap;
|
||||
temp_q++;
|
||||
Qread++;
|
||||
}
|
||||
}
|
||||
|
||||
return(OK);
|
||||
}
|
||||
80
utility/rtos_compatibility_layers/posix/px_mq_attr_init.c
Normal file
80
utility/rtos_compatibility_layers/posix/px_mq_attr_init.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_qattr_init PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function initializes the mq_attr structure a ThreadX queue */
|
||||
/* into the POSIX variable length message queue pool. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_qattr_init(VOID)
|
||||
{
|
||||
|
||||
struct mq_attr * q_attr;
|
||||
|
||||
q_attr = &(posix_qattr_default);
|
||||
|
||||
/* This queue is not currently in use. */
|
||||
q_attr->mq_flags = MQ_FLAGS;
|
||||
q_attr->mq_maxmsg = MQ_MAXMSG;
|
||||
q_attr->mq_msgsize = MQ_MSGSIZE;
|
||||
return;
|
||||
}
|
||||
146
utility/rtos_compatibility_layers/posix/px_mq_close.c
Normal file
146
utility/rtos_compatibility_layers/posix/px_mq_close.c
Normal file
@@ -0,0 +1,146 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* mq_close PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* close a message queue */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mqdes message queue descriptor */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* OK If successful */
|
||||
/* ERROR If error occurs */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_internal_error Generic error handler */
|
||||
/* tx_byte_release Release bytes */
|
||||
/* tx_thread_identify Returns currently running thread */
|
||||
/* posix_queue_delete Deletes specific queue */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT mq_close(mqd_t mqdes)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
TX_QUEUE * Queue;
|
||||
POSIX_MSG_QUEUE * q_ptr;
|
||||
|
||||
/* Assign a temporary variable for clarity. */
|
||||
Queue = &(mqdes->f_data->queue);
|
||||
q_ptr = (POSIX_MSG_QUEUE * )Queue;
|
||||
|
||||
/* First, check for an invalid queue pointer. */
|
||||
if ( (!q_ptr) || ( (q_ptr -> px_queue_id) != PX_QUEUE_ID))
|
||||
{
|
||||
/* Queue pointer is invalid, return appropriate error code. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* If we are not calling this routine from a thread context. */
|
||||
if (!(tx_thread_identify()))
|
||||
{
|
||||
/* return appropriate error code. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Free the system resource allocated by open call. */
|
||||
if( tx_byte_release( ( VOID *) mqdes ))
|
||||
{
|
||||
/* return generic error. */
|
||||
posix_internal_error(100);
|
||||
|
||||
/* Return error. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Disable interrupts. */
|
||||
TX_DISABLE
|
||||
|
||||
/* Decrement ref count. */
|
||||
if( q_ptr->open_count )
|
||||
|
||||
q_ptr ->open_count--;
|
||||
|
||||
/* Destroy the basic Queue is the ref count is zero and
|
||||
it is marked by unlink. */
|
||||
if( (! q_ptr ->open_count ) && (q_ptr->unlink_flag == TX_TRUE))
|
||||
{
|
||||
/* Free the system resource allocated by open call. */
|
||||
if( posix_queue_delete( q_ptr ))
|
||||
{
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* return generic type. */
|
||||
posix_internal_error(100);
|
||||
|
||||
/* Return error. */
|
||||
return(ERROR);
|
||||
}
|
||||
}
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Return OK. */
|
||||
return(OK);
|
||||
}
|
||||
225
utility/rtos_compatibility_layers/posix/px_mq_create.c
Normal file
225
utility/rtos_compatibility_layers/posix/px_mq_create.c
Normal file
@@ -0,0 +1,225 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_mq_create PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This subroutine creates and initializes a message queue */
|
||||
/* As the message length is user defined, message pointer and message */
|
||||
/* length is stored in a ThreadX queue(instead of the actual message) */
|
||||
/* The actual message is stored in a dedicated byte pool for the */
|
||||
/* queue */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mq_name name of the Queue */
|
||||
/* msgq_attr Pointer to mq_attr structure */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* posix_q If success */
|
||||
/* NULL If failure */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_in_thread_context Make sure caller is thread */
|
||||
/* tx_queue_create to create a ThreadX Queue */
|
||||
/* posix_internal_error Generic error Handler */
|
||||
/* posix_memory_allocate to create a byte pool */
|
||||
/* tx_queue_delete to delete the queue */
|
||||
/* posix_putback_queue to delete the queue */
|
||||
/* tx_byte_pool_create to create a byte pool */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
POSIX_MSG_QUEUE * posix_mq_create (const CHAR * mq_name,
|
||||
struct mq_attr * msgq_attr)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
POSIX_MSG_QUEUE *posix_q;
|
||||
UINT temp1;
|
||||
VOID *bp;
|
||||
INT retval;
|
||||
ULONG size;
|
||||
TX_QUEUE *TheQ;
|
||||
|
||||
/* Make sure we're calling this routine from a thread context. */
|
||||
if (!posix_in_thread_context())
|
||||
{
|
||||
/* return POSIX error. */
|
||||
posix_internal_error(444);
|
||||
|
||||
/* return error. */
|
||||
return ((POSIX_MSG_QUEUE *)ERROR);
|
||||
}
|
||||
/* Disable interrupts.*/
|
||||
TX_DISABLE
|
||||
|
||||
/* Get a new queue from the POSIX queue pool. */
|
||||
/* Make sure we have enough space for the size. */
|
||||
|
||||
posix_q = posix_get_new_queue(msgq_attr->mq_maxmsg);
|
||||
|
||||
/* Make sure we actually got a queue. */
|
||||
if (!posix_q)
|
||||
{
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* User configuration error - not enough memory. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
|
||||
/* Return ERROR. */
|
||||
return(TX_NULL);
|
||||
}
|
||||
|
||||
/* Now create a ThreadX message queue.
|
||||
to store only the message pointer and message length. */
|
||||
temp1 = tx_queue_create((&(posix_q->queue)),
|
||||
(CHAR *)mq_name,
|
||||
TX_4_ULONG,
|
||||
posix_q->storage,
|
||||
(msgq_attr->mq_maxmsg * 16));
|
||||
|
||||
/* Make sure it worked. */
|
||||
if (temp1 != TX_SUCCESS)
|
||||
{
|
||||
/*. Return generic error. */
|
||||
posix_internal_error(188);
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Return ERROR. */
|
||||
return(TX_NULL);
|
||||
}
|
||||
/* Restore no. of maximum messages. */
|
||||
posix_q->q_attr.mq_maxmsg = msgq_attr->mq_maxmsg;
|
||||
|
||||
/* Restore maximum message length. */
|
||||
posix_q->q_attr.mq_msgsize = msgq_attr->mq_msgsize;
|
||||
|
||||
/* Flags are stored in que descriptor structure and
|
||||
not in mq_att structure. */
|
||||
|
||||
/* Create a byte pool for the queue.
|
||||
Determine how much memory we need to store all messages in this queue.
|
||||
11 bytes are added to counter overhead as well as alignment problem if any. */
|
||||
size = ( ((msgq_attr->mq_maxmsg) + 1) * (msgq_attr->mq_msgsize + 11) );
|
||||
|
||||
if(size < 100)
|
||||
size = 100;
|
||||
|
||||
/* Now attempt to allocate that much memory for the queue. */
|
||||
|
||||
retval = posix_memory_allocate(size,&bp);
|
||||
|
||||
/* Make sure we obtained the memory we requested. */
|
||||
if (retval)
|
||||
{
|
||||
/* Created queue Control block, got memory to store message pointers
|
||||
and lengths which means that created a fixed length message queue but
|
||||
not enough memory to store actual messages. */
|
||||
|
||||
/* Delete the queue. */
|
||||
|
||||
/* Assign a temporary variable for clarity. */
|
||||
TheQ = (TX_QUEUE * )posix_q;
|
||||
retval = tx_queue_delete(TheQ);
|
||||
|
||||
/* Make sure the queue was deleted. */
|
||||
if (retval != TX_SUCCESS)
|
||||
{
|
||||
/* Return generic error. */
|
||||
posix_internal_error(799);
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Return ERROR. */
|
||||
return(TX_NULL);
|
||||
}
|
||||
/* Put the queue back into the POSIX queue pool. */
|
||||
posix_putback_queue(TheQ);
|
||||
|
||||
/* User configuration error - not enough memory. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
TX_RESTORE;
|
||||
|
||||
/* Return ERROR. */
|
||||
return(TX_NULL);
|
||||
}
|
||||
/* Create a ThreadX byte pool that will provide memory needed by the queue. */
|
||||
retval = tx_byte_pool_create((&(posix_q->vq_message_area)), "POSIX Queue",
|
||||
bp, size);
|
||||
|
||||
/* Make sure the byte pool was created successfully. */
|
||||
if (retval)
|
||||
{
|
||||
/* Error creating byte pool. */
|
||||
posix_internal_error(9999);
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Return ERROR.*/
|
||||
return(TX_NULL);
|
||||
}
|
||||
|
||||
posix_q->name = (CHAR*) mq_name;
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* All done. */
|
||||
return(posix_q);
|
||||
}
|
||||
113
utility/rtos_compatibility_layers/posix/px_mq_find_queue.c
Normal file
113
utility/rtos_compatibility_layers/posix/px_mq_find_queue.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_find_queue PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This routine returns queue descriptor indicating that name of */
|
||||
/* in the message queue.exists. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* const char * mq_name Name of the message queue */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* q_ptr If successful */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
POSIX_MSG_QUEUE * posix_find_queue(const CHAR *mq_name)
|
||||
{
|
||||
|
||||
POSIX_MSG_QUEUE *q_ptr;
|
||||
ULONG index;
|
||||
ULONG match;
|
||||
CHAR *dummy_name;
|
||||
CHAR *dummy_queue_name;
|
||||
ULONG namelength;
|
||||
|
||||
q_ptr = (POSIX_MSG_QUEUE*)NULL;
|
||||
|
||||
/* For checking the name. */
|
||||
for(index = 0,q_ptr = posix_queue_pool;index < POSIX_MAX_QUEUES ;index ++,q_ptr ++)
|
||||
{
|
||||
/* Assume the worst case. */
|
||||
match = TX_FALSE;
|
||||
if(q_ptr->in_use == TX_TRUE)
|
||||
{
|
||||
dummy_queue_name = q_ptr->name;
|
||||
for(namelength = 0 ,dummy_name = (CHAR *) mq_name ; namelength < PATH_MAX ;
|
||||
namelength ++, dummy_name++,dummy_queue_name ++)
|
||||
{
|
||||
/* Copy name. */
|
||||
if (*dummy_name == *dummy_queue_name)
|
||||
{
|
||||
/* End of the string. */
|
||||
if(*dummy_name == '\0')
|
||||
{
|
||||
match = TX_TRUE;
|
||||
break;
|
||||
}
|
||||
}/* Copy name. */
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(match==TX_TRUE)
|
||||
break;
|
||||
}
|
||||
/* For each message queue. */
|
||||
if(match==TX_TRUE)
|
||||
return(q_ptr);
|
||||
/* Returns NULL if match not found. */
|
||||
q_ptr = (POSIX_MSG_QUEUE*)NULL;
|
||||
return (q_ptr);
|
||||
}
|
||||
121
utility/rtos_compatibility_layers/posix/px_mq_get_new_queue.c
Normal file
121
utility/rtos_compatibility_layers/posix/px_mq_get_new_queue.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_get_new_queue PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function attempts to build a ThreadX message queue */
|
||||
/* for variable length message queues */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* maxnum Number of queue entries */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* q_ptr Pointer to posix queue */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_memory_allocate Memory allocate */
|
||||
/* posix_memory_release Memory free */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
POSIX_MSG_QUEUE * posix_get_new_queue(ULONG maxnum)
|
||||
{
|
||||
|
||||
ULONG i;
|
||||
POSIX_MSG_QUEUE *q_ptr;
|
||||
VOID *bp;
|
||||
INT retval;
|
||||
ULONG size;
|
||||
|
||||
|
||||
/* Determine how much memory we need for the queue.
|
||||
The queue holds "maxnum" entries; each entry is 2 ULONG. */
|
||||
size = (maxnum * (TX_4_ULONG * sizeof(ULONG)));
|
||||
|
||||
/* Now attempt to allocate memory for the queue. */
|
||||
retval = posix_memory_allocate(size, &bp);
|
||||
|
||||
/* Make sure we obtained the memory we requested. */
|
||||
if (retval)
|
||||
{
|
||||
return((POSIX_MSG_QUEUE *)NULL);
|
||||
}
|
||||
/* Loop through the list of queues - */
|
||||
/* try to find one that is not "in use". */
|
||||
/* Search the queue pool for an available queue. */
|
||||
for (i = 0, q_ptr = &(posix_queue_pool[0]);
|
||||
i < POSIX_MAX_QUEUES;
|
||||
i++, q_ptr++)
|
||||
{
|
||||
/* Make sure the queue is not "in use". */
|
||||
if (q_ptr->in_use == TX_FALSE)
|
||||
{
|
||||
/* This queue is now in use. */
|
||||
q_ptr->in_use = TX_TRUE;
|
||||
|
||||
/* Point to allocated memory. */
|
||||
q_ptr->storage = bp;
|
||||
|
||||
q_ptr->px_queue_id = PX_QUEUE_ID;
|
||||
|
||||
/* Stop searching. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* If we didn't find a free queue, free the allocated memory. */
|
||||
if ( i >= POSIX_MAX_QUEUES)
|
||||
{
|
||||
posix_memory_release(bp);
|
||||
return((POSIX_MSG_QUEUE *)0);
|
||||
}
|
||||
/* Return home. */
|
||||
return(q_ptr);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_get_queue_desc PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function returns a message queue descriptor pointer of valid */
|
||||
/* message queue */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* q_ptr message queue pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* q_des message queue descriptor */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_internal_error Returns a Generic error */
|
||||
/* tx_byte_allocate Allocates bytes */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
struct mq_des * posix_get_queue_des(POSIX_MSG_QUEUE * q_ptr)
|
||||
{
|
||||
|
||||
struct mq_des *q_des = NULL;
|
||||
VOID *bp;
|
||||
|
||||
/* allocate the system resource allocated by open call. */
|
||||
if( tx_byte_allocate((TX_BYTE_POOL *)&posix_heap_byte_pool, &bp,
|
||||
sizeof(struct mq_des), TX_NO_WAIT))
|
||||
{
|
||||
/* return generic error. */
|
||||
posix_internal_error(100);
|
||||
/* Return error. */
|
||||
return((struct mq_des *)ERROR);
|
||||
}
|
||||
q_des = (struct mq_des *)bp;
|
||||
/* Get message queue data to mq_des structure. */
|
||||
q_des->f_data = q_ptr;
|
||||
return(q_des);
|
||||
}
|
||||
202
utility/rtos_compatibility_layers/posix/px_mq_open.c
Normal file
202
utility/rtos_compatibility_layers/posix/px_mq_open.c
Normal file
@@ -0,0 +1,202 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* mq_open PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This routine establishes connection between a named message queue */
|
||||
/* and the calling a thread */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mqName name of the queue to open. */
|
||||
/* oflags O_RDONLY, O_WRONLY, O_RDWR, or O_CREAT, */
|
||||
/* O_EXCEL,O_NONBLOCK. */
|
||||
/* extra optional parameters. */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* queue_des If successful */
|
||||
/* ERROR If fails */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_find_queue find queue of given name */
|
||||
/* posix_mq_create create a queue */
|
||||
/* posix_get_queue_des gets a queue-descriptor for Queue */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
mqd_t mq_open(const CHAR * mqName, ULONG oflags,...)
|
||||
{
|
||||
|
||||
POSIX_MSG_QUEUE *posix_queue;
|
||||
struct mq_des *queue_des;
|
||||
struct mq_attr *q_attr;
|
||||
mode_t mode;
|
||||
va_list create_queue;
|
||||
ULONG len;
|
||||
ULONG temp1;
|
||||
|
||||
len = strlen(mqName);
|
||||
if(len > PATH_MAX)
|
||||
{
|
||||
/* Return error. */
|
||||
posix_errno = ENAMETOOLONG;
|
||||
posix_set_pthread_errno(ENAMETOOLONG);
|
||||
|
||||
/*. Return error. */
|
||||
return((struct mq_des *)ERROR);
|
||||
}
|
||||
switch(oflags & 0xFF00)
|
||||
{
|
||||
case O_CREAT:
|
||||
|
||||
case (O_EXCL | O_CREAT):
|
||||
|
||||
va_start(create_queue, oflags);
|
||||
mode = va_arg(create_queue, mode_t);
|
||||
mode = mode; /* just to keep the complier happy */
|
||||
q_attr = va_arg(create_queue, struct mq_attr *);
|
||||
va_end(create_queue);
|
||||
|
||||
/* Check for valid messages and its size. */
|
||||
if(!q_attr || q_attr->mq_maxmsg > MQ_MAXMSG || q_attr->mq_msgsize > MQ_MSGSIZE)
|
||||
{
|
||||
/* return POSIX error.for invalid oflag. */
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
/* return error. */
|
||||
return ((struct mq_des *)ERROR);
|
||||
}
|
||||
|
||||
/* Check if name is exist. NULL if successful. */
|
||||
if(posix_queue = posix_find_queue(mqName))
|
||||
{
|
||||
if(posix_queue->unlink_flag == TX_TRUE)
|
||||
{
|
||||
/* return POSIX error. */
|
||||
posix_errno = ENOENT;
|
||||
posix_set_pthread_errno(ENOENT);
|
||||
/* return error. */
|
||||
return ((struct mq_des *)ERROR);
|
||||
}
|
||||
|
||||
/* Set Posix error if name exist. */
|
||||
posix_errno = EEXIST;
|
||||
posix_set_pthread_errno(EEXIST);
|
||||
/* return error */
|
||||
return((struct mq_des *)ERROR);
|
||||
}
|
||||
|
||||
/* If q_attr is NULL then the default attributes of the struct
|
||||
mq_attr are used */
|
||||
if(q_attr == NULL)
|
||||
{
|
||||
q_attr = &(posix_qattr_default);
|
||||
temp1 = q_attr->mq_maxmsg;
|
||||
temp1= temp1 ; /* Just to keep complier happy */
|
||||
}
|
||||
|
||||
/* Create a queue which returns posix queue if successful and
|
||||
NULL if fails. */
|
||||
if(!(posix_queue = posix_mq_create(mqName, q_attr)))
|
||||
{
|
||||
|
||||
/* posix_errno is filled up in mq_create. */
|
||||
return((struct mq_des *)ERROR);
|
||||
}
|
||||
/* open count incremented by one. */
|
||||
posix_queue->open_count += 1;
|
||||
break;
|
||||
|
||||
case O_EXCL:
|
||||
/* Check if name is exist. NULL if successful. */
|
||||
if(!(posix_queue = posix_find_queue(mqName)))
|
||||
{
|
||||
/* return POSIX error. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
/* return error. */
|
||||
return ((struct mq_des *)ERROR);
|
||||
}
|
||||
|
||||
return(OK);
|
||||
|
||||
case O_RDONLY:
|
||||
case O_WRONLY:
|
||||
case O_RDWR:
|
||||
case O_NONBLOCK:
|
||||
/* Check if name is exist. NULL if successful. */
|
||||
if(posix_queue = posix_find_queue(mqName))
|
||||
{
|
||||
if(posix_queue->unlink_flag == TX_TRUE)
|
||||
{
|
||||
/* return POSIX error. */
|
||||
posix_errno = ENOENT;
|
||||
posix_set_pthread_errno(ENOENT);
|
||||
/* return error. */
|
||||
return ((struct mq_des *)ERROR);
|
||||
}
|
||||
/* open count incremented by one. */
|
||||
posix_queue->open_count += 1;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/* return POSIX error.for invalid oflag. */
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
/* return error. */
|
||||
return ((struct mq_des *)ERROR);
|
||||
}
|
||||
|
||||
queue_des = posix_get_queue_des(posix_queue);
|
||||
/* Store the flags. */
|
||||
queue_des->f_flag = oflags;
|
||||
return(queue_des);
|
||||
}
|
||||
104
utility/rtos_compatibility_layers/posix/px_mq_priority_search.c
Normal file
104
utility/rtos_compatibility_layers/posix/px_mq_priority_search.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_priority_search PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This routine returns the no. of messages of the same priority */
|
||||
/* in the message queue. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* msgQId message queue ID */
|
||||
/* priority priority of the message */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* order Returns the number of same priority messages.*/
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
ULONG posix_priority_search(mqd_t msgQId ,ULONG priority)
|
||||
{
|
||||
|
||||
TX_QUEUE *queue;
|
||||
POSIX_MSG_QUEUE *q_ptr;
|
||||
ULONG order;
|
||||
ULONG numMsgs;
|
||||
UINT index;
|
||||
ULONG *source;
|
||||
ULONG msgp;
|
||||
|
||||
queue = &(msgQId->f_data->queue);
|
||||
q_ptr = (POSIX_MSG_QUEUE * )queue;
|
||||
|
||||
/* No. of messages in the queue. */
|
||||
numMsgs = q_ptr -> queue.tx_queue_enqueued;
|
||||
|
||||
/* retrieving the message pointer. */
|
||||
source = q_ptr->queue.tx_queue_read;
|
||||
|
||||
/* check for same priority. */
|
||||
for(index = 0,order = 1;index <= numMsgs ;index++)
|
||||
{
|
||||
source += 2;
|
||||
msgp = *source;
|
||||
source += 2;
|
||||
|
||||
if(source == q_ptr->queue.tx_queue_end)
|
||||
source = q_ptr->queue.tx_queue_start;
|
||||
|
||||
if(priority == msgp)
|
||||
order += 1;
|
||||
}
|
||||
/* Returns the number of same priority messages. */
|
||||
return(order);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_putback_queue PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function "puts back" a ThreadX queue into the POSIX */
|
||||
/* variable length message queue pool. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* qid Queue ID */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_memory_putback Free memory */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_putback_queue(TX_QUEUE * qid)
|
||||
{
|
||||
|
||||
POSIX_MSG_QUEUE * q_ptr;
|
||||
|
||||
/* Convert TX_QUEUE into POSIX_QUEUE datatype. */
|
||||
q_ptr = MAKE_POSIX_QUEUE(qid);
|
||||
|
||||
/* Free the queue's memory. */
|
||||
posix_memory_release(q_ptr->storage);
|
||||
|
||||
/* This queue is no longer in use. */
|
||||
q_ptr->in_use = TX_FALSE;
|
||||
return;
|
||||
}
|
||||
90
utility/rtos_compatibility_layers/posix/px_mq_queue_delete.c
Normal file
90
utility/rtos_compatibility_layers/posix/px_mq_queue_delete.c
Normal file
@@ -0,0 +1,90 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_queue_delete PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* deletes a message queue */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* q_ptr message queue pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* ERROR If fails */
|
||||
/* OK If successful */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_queue_delete Detectes a Queue */
|
||||
/* posix_internal_error Generic error */
|
||||
/* posix_reset queue Resets queue structure */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT posix_queue_delete(POSIX_MSG_QUEUE * q_ptr)
|
||||
{
|
||||
|
||||
TX_QUEUE *queue;
|
||||
|
||||
queue = &(q_ptr->queue);
|
||||
|
||||
/* Delete the Threadx queue. */
|
||||
if(tx_queue_delete(queue))
|
||||
{
|
||||
/* return generic error. */
|
||||
posix_internal_error(444);
|
||||
/* return error. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Release the queue back to the pool. */
|
||||
posix_reset_queue(q_ptr);
|
||||
q_ptr = NULL;
|
||||
return(OK);
|
||||
}
|
||||
85
utility/rtos_compatibility_layers/posix/px_mq_queue_init.c
Normal file
85
utility/rtos_compatibility_layers/posix/px_mq_queue_init.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_queue_init PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function initializes the POSIX's internal variable length */
|
||||
/* message queue pool. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_queue_init(VOID)
|
||||
{
|
||||
|
||||
ULONG i;
|
||||
POSIX_MSG_QUEUE *queue_ptr;
|
||||
|
||||
for (i = 0, queue_ptr = &(posix_queue_pool[0]);
|
||||
i < POSIX_MAX_QUEUES;
|
||||
i++, queue_ptr++)
|
||||
{
|
||||
/* This queue is not currently in use.*/
|
||||
queue_ptr->in_use = TX_FALSE;
|
||||
queue_ptr->name = "";
|
||||
queue_ptr->open_count = 0;
|
||||
queue_ptr->storage = NULL;
|
||||
queue_ptr->unlink_flag = TX_FALSE;
|
||||
}
|
||||
}
|
||||
264
utility/rtos_compatibility_layers/posix/px_mq_receive.c
Normal file
264
utility/rtos_compatibility_layers/posix/px_mq_receive.c
Normal file
@@ -0,0 +1,264 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* mq_receive PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* */
|
||||
/* Receive a message from a message queue. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mqdes message queue descriptor */
|
||||
/* *pMsg buffer to receive message */
|
||||
/* msgLen size of buffer, in bytes */
|
||||
/* *pMsgPrio If not NULL, return message priority */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* temp1 no of bytes received */
|
||||
/* ERROR If error occurs */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_internal_error Generic error handler */
|
||||
/* tx_queue_receive ThreadX queue receive */
|
||||
/* tx_byte_release Release bytes */
|
||||
/* posix_memory_allocate Allocate memory */
|
||||
/* tx_thread_identify Returns currently running thread */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
ssize_t mq_receive( mqd_t mqdes, VOID * pMsg, size_t msgLen, ULONG *pMsgPrio)
|
||||
{
|
||||
|
||||
TX_QUEUE * Queue;
|
||||
POSIX_MSG_QUEUE * q_ptr;
|
||||
INT temp1, retval = ERROR;
|
||||
ULONG wait_option,length_of_message, priority_of_message,mycount;
|
||||
ULONG * my_ptr;
|
||||
CHAR * this_ptr;
|
||||
VOID * msgbuf1;
|
||||
UCHAR * msgbuf2;
|
||||
VOID * message_source;
|
||||
|
||||
/* Assign a temporary variable for clarity. */
|
||||
Queue = &(mqdes->f_data->queue);
|
||||
q_ptr = (POSIX_MSG_QUEUE * )mqdes->f_data;
|
||||
|
||||
/* First, check for an invalid queue pointer. */
|
||||
if ((!q_ptr) || ( (q_ptr -> px_queue_id) != PX_QUEUE_ID))
|
||||
{
|
||||
/* Queue pointer is invalid, return appropriate error code. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
if(((mqdes ->f_flag & O_RDONLY) != O_RDONLY ) && ((mqdes->f_flag & O_RDWR) != O_RDWR))
|
||||
{
|
||||
/* Queue pointer is invalid, return appropriate error code. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Check if message length provided is less q size provided while creation. */
|
||||
if( msgLen < q_ptr -> q_attr.mq_msgsize )
|
||||
{
|
||||
/* Return appropriate error. */
|
||||
posix_errno = EMSGSIZE;
|
||||
posix_set_pthread_errno(EMSGSIZE);
|
||||
|
||||
/* Return error. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* User has indicated a wait is acceptable. */
|
||||
/* if a message is not immediately available. */
|
||||
/* If we are not calling this routine from a thread context. */
|
||||
if (!(tx_thread_identify()))
|
||||
{
|
||||
/* return appropriate error code. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
if ( ( mqdes ->f_flag & O_NONBLOCK ) == O_NONBLOCK )
|
||||
wait_option = TX_NO_WAIT;
|
||||
else
|
||||
wait_option = TX_WAIT_FOREVER;
|
||||
|
||||
|
||||
/* Try to get a message from the message queue. */
|
||||
/* Create a temporary buffer to get message pointer and message length. */
|
||||
temp1 = posix_memory_allocate((sizeof(ULONG)) * 4 , (VOID**)&msgbuf1);
|
||||
if(temp1 != TX_SUCCESS )
|
||||
{
|
||||
/* Return generic error. */
|
||||
posix_internal_error(100);
|
||||
|
||||
/* Return error. */
|
||||
return(ERROR);
|
||||
}
|
||||
/* Arrange the messages in the queue as per the required priority. */
|
||||
temp1 = posix_arrange_msg( Queue, pMsgPrio );
|
||||
/* Receive the message */
|
||||
temp1 = tx_queue_receive(Queue, msgbuf1, wait_option);
|
||||
/* Some ThreadX error codes map to posix error codes. */
|
||||
switch(temp1)
|
||||
{
|
||||
case TX_SUCCESS:
|
||||
{
|
||||
|
||||
/* All ok */
|
||||
temp1 = OK;
|
||||
break;
|
||||
}
|
||||
|
||||
case TX_DELETED:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case TX_QUEUE_EMPTY:
|
||||
{
|
||||
if (wait_option == TX_NO_WAIT)
|
||||
{
|
||||
/* No message to receive while NO_WAIT option is set */
|
||||
posix_errno = EAGAIN;
|
||||
posix_set_pthread_errno(EAGAIN);
|
||||
|
||||
/* Return error */
|
||||
temp1 = ERROR;
|
||||
return(temp1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TX_QUEUE_ERROR:
|
||||
case TX_PTR_ERROR:
|
||||
{
|
||||
/* Queue pointer is invalid, return appropriate error code. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
|
||||
/* Return ERROR. */
|
||||
temp1 = ERROR;
|
||||
return(temp1);
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
/* should not come here but send the default error. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
|
||||
/* Return error. */
|
||||
temp1 = ERROR;
|
||||
return(temp1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Assign a variable for clarity. */
|
||||
my_ptr = ( ULONG *)msgbuf1;
|
||||
|
||||
/* Retrieve Message pointer, message Length and message priority. */
|
||||
this_ptr = (CHAR *)(*my_ptr);
|
||||
message_source = (VOID *)this_ptr;
|
||||
length_of_message = *(++my_ptr);
|
||||
priority_of_message = *(++my_ptr);
|
||||
|
||||
/* Copy message into supplied buffer. */
|
||||
msgbuf2 = (UCHAR *)pMsg;
|
||||
|
||||
/* Release memory after storing data into destination. */
|
||||
retval = tx_byte_release(msgbuf1);
|
||||
|
||||
if( retval)
|
||||
{
|
||||
/* return generic error. */
|
||||
posix_internal_error(100);
|
||||
|
||||
/* Return error. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
if ( temp1 == OK)
|
||||
{
|
||||
for (mycount = 0; ( (mycount < length_of_message) && (mycount < msgLen)); mycount++)
|
||||
{
|
||||
*(msgbuf2++) = *((UCHAR *)(this_ptr++));
|
||||
}
|
||||
|
||||
temp1 = mycount;
|
||||
}
|
||||
|
||||
retval = tx_byte_release(message_source);
|
||||
|
||||
if( retval)
|
||||
{
|
||||
/* return generic error. */
|
||||
posix_internal_error(100);
|
||||
|
||||
/* Return error. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Copy message priority */
|
||||
if (pMsgPrio)
|
||||
{
|
||||
*pMsgPrio = priority_of_message;
|
||||
}
|
||||
|
||||
/* All done */
|
||||
return(length_of_message);
|
||||
}
|
||||
93
utility/rtos_compatibility_layers/posix/px_mq_reset_queue.c
Normal file
93
utility/rtos_compatibility_layers/posix/px_mq_reset_queue.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_reset_queue PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function resets a message queue structure */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* q_ptr q_ptr */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_byte_pool_delete Deletes byte pool */
|
||||
/* posix_internal_error Returns generic error */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_reset_queue(POSIX_MSG_QUEUE * q_ptr)
|
||||
{
|
||||
/* Indicate this entry is not in use. */
|
||||
q_ptr->in_use = TX_FALSE;
|
||||
|
||||
/* Reset thread name to NULL string. */
|
||||
q_ptr -> name = NULL;
|
||||
|
||||
/* Reset open count. */
|
||||
q_ptr -> open_count = 0;
|
||||
|
||||
/* Reset storage */
|
||||
q_ptr -> storage = NULL;
|
||||
|
||||
/* Delete message area. */
|
||||
if (tx_byte_pool_delete(&(q_ptr ->vq_message_area)))
|
||||
{
|
||||
/* Internal error. */
|
||||
posix_internal_error(444);
|
||||
}
|
||||
/* Reset queue id. */
|
||||
q_ptr -> px_queue_id = 0;
|
||||
|
||||
/* Reset Unlink Flag */
|
||||
q_ptr -> unlink_flag = TX_FALSE;
|
||||
}
|
||||
214
utility/rtos_compatibility_layers/posix/px_mq_send.c
Normal file
214
utility/rtos_compatibility_layers/posix/px_mq_send.c
Normal file
@@ -0,0 +1,214 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* mq_send PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* The mq_send() function puts a message of size msg_len and pointed to*/
|
||||
/* by msg_ptr into the queue indicated by mqdes. The new message has a */
|
||||
/* priority of msg_prio. */
|
||||
/* The queue maintained is in priority order (priorities may range from*/
|
||||
/* 0 to MQ_PRIO_MAX), and in FIFO order within the same priority. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mqdes Queue descriptor */
|
||||
/* msg_ptr Message pointer */
|
||||
/* msg_len length of message */
|
||||
/* msg_prio Priority of the message */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* OK no of bytes received */
|
||||
/* ERROR If error occurs */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_thread_identify returns currently running thread */
|
||||
/* tx_byte_allocate allocate memory */
|
||||
/* tx_queue_send ThreadX queue send */
|
||||
/* posix_priority_search search message for same priority */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT mq_send( mqd_t mqdes, const CHAR * msg_ptr, size_t msg_len,
|
||||
ULONG msg_prio )
|
||||
{
|
||||
|
||||
TX_QUEUE *Queue;
|
||||
UINT temp1;
|
||||
POSIX_MSG_QUEUE *q_ptr;
|
||||
VOID *bp;
|
||||
UCHAR *source;
|
||||
UCHAR *destination;
|
||||
UCHAR *save_ptr;
|
||||
ULONG mycount;
|
||||
ULONG msg[4];
|
||||
|
||||
/* Assign a temporary variable for clarity. */
|
||||
Queue = &(mqdes->f_data->queue);
|
||||
q_ptr = (POSIX_MSG_QUEUE * )mqdes->f_data;
|
||||
|
||||
/* First, check for an invalid queue pointer. */
|
||||
if ( (!q_ptr) || ( (q_ptr -> px_queue_id) != PX_QUEUE_ID))
|
||||
{
|
||||
/* Queue pointer is invalid, return appropriate error code. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
/* Make sure if we're calling this routine from a ISR timeout
|
||||
is set to zero. */
|
||||
if (!(tx_thread_identify()))
|
||||
{
|
||||
/* POSIX doesn't have error for this, hence give default. */
|
||||
posix_errno = EINTR ;
|
||||
posix_set_pthread_errno(EINTR);
|
||||
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* First, check for an invalid queue pointer. */
|
||||
if ( (!q_ptr) || ( (q_ptr->queue.tx_queue_id) != TX_QUEUE_ID))
|
||||
{
|
||||
/* Queue descriptor is invalid, set appropriate error code. */
|
||||
posix_errno = EBADF ;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
if(((mqdes->f_flag & O_WRONLY) != O_WRONLY) && ((mqdes->f_flag & O_RDWR) != O_RDWR))
|
||||
{
|
||||
/* Queue pointer is invalid, return appropriate error code. */
|
||||
posix_errno = EBADF;
|
||||
posix_set_pthread_errno(EBADF);
|
||||
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
if( msg_prio > MQ_PRIO_MAX)
|
||||
{
|
||||
/* Return appropriate error. */
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
|
||||
/* Return error. */
|
||||
return(ERROR);
|
||||
}
|
||||
/* Check for an invalid source for message. */
|
||||
if (! msg_ptr)
|
||||
{
|
||||
/* POSIX doesn't have error for this, hence give default. */
|
||||
posix_errno = EINTR ;
|
||||
posix_set_pthread_errno(EINTR);
|
||||
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Now check the length of message. */
|
||||
if ( msg_len > (q_ptr->q_attr.mq_msgsize ) )
|
||||
{
|
||||
/* Return message length exceeds max length. */
|
||||
posix_errno = EMSGSIZE ;
|
||||
posix_set_pthread_errno(EMSGSIZE);
|
||||
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Now try to allocate memory to save the message from the
|
||||
queue's byte pool. */
|
||||
temp1 = tx_byte_allocate((TX_BYTE_POOL * )&(q_ptr->vq_message_area), &bp,
|
||||
msg_len, TX_NO_WAIT);
|
||||
|
||||
if (temp1 != TX_SUCCESS)
|
||||
{
|
||||
posix_internal_error(9999);
|
||||
}
|
||||
/* Got the memory , Setup source and destination pointers
|
||||
Cast them in UCHAR as message length is in bytes. */
|
||||
source = (UCHAR * ) msg_ptr;
|
||||
destination = (UCHAR * ) bp;
|
||||
|
||||
/* Save start of message storage. */
|
||||
save_ptr = destination;
|
||||
|
||||
/* Copy the message into private buffer. */
|
||||
for ( mycount = 0; mycount < msg_len; mycount++)
|
||||
{
|
||||
|
||||
* destination++ = * source++;
|
||||
}
|
||||
/* Restore the pointer of save message. */
|
||||
source = save_ptr ;
|
||||
/* Create message that holds saved message pointer and message length. */
|
||||
msg[0] = (ULONG)source;
|
||||
msg[1] = msg_len;
|
||||
msg[2] = msg_prio;
|
||||
msg[3] = posix_priority_search(mqdes, msg_prio);
|
||||
|
||||
/* Attempt to post the message to the queue. */
|
||||
temp1 = tx_queue_send(Queue, msg, TX_WAIT_FOREVER);
|
||||
if ( temp1 != TX_SUCCESS)
|
||||
{
|
||||
/* POSIX doesn't have error for this, hence give default. */
|
||||
posix_errno = EINTR ;
|
||||
posix_set_pthread_errno(EINTR);
|
||||
|
||||
/* Return ERROR. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* All done. */
|
||||
return(OK);
|
||||
}
|
||||
120
utility/rtos_compatibility_layers/posix/px_mq_unlink.c
Normal file
120
utility/rtos_compatibility_layers/posix/px_mq_unlink.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* mq_unlink PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This routine removes the named message queue */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* const CHAR * mqName Message Queue name. */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* OK If successful */
|
||||
/* ERROR IF fails */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_internal_error Generic error handler */
|
||||
/* posix_find_queue Finds the required queue */
|
||||
/* posix_queue_delete Deletes specific queue */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT mq_unlink(const CHAR * mqName)
|
||||
{
|
||||
|
||||
POSIX_MSG_QUEUE *q_ptr;
|
||||
ULONG len;
|
||||
ULONG temp1;
|
||||
|
||||
/* Checking for the invalid length. */
|
||||
len = strlen(mqName);
|
||||
if(len > 10)
|
||||
{
|
||||
/* Return appropriate error. */
|
||||
posix_errno = ENAMETOOLONG;
|
||||
posix_set_pthread_errno(ENAMETOOLONG);
|
||||
|
||||
/* Return Error. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* For checking the name. */
|
||||
if(!(q_ptr = posix_find_queue(mqName)))
|
||||
{
|
||||
/* Set Posix error if name exist. */
|
||||
posix_errno = EEXIST;
|
||||
posix_set_pthread_errno(EEXIST);
|
||||
|
||||
/* Return error. */
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
if(q_ptr)
|
||||
/* Unlinks the message Queue. */
|
||||
q_ptr->unlink_flag = TX_TRUE;
|
||||
|
||||
/* check if the message queue is not open in any task. */
|
||||
if(q_ptr->open_count == 0)
|
||||
{
|
||||
/* Free the system resource allocated by open call. */
|
||||
temp1 = posix_queue_delete( q_ptr );
|
||||
|
||||
if( temp1 != TX_SUCCESS)
|
||||
{
|
||||
/*. Return generic error. */
|
||||
posix_internal_error(100);
|
||||
|
||||
/* Return error. */
|
||||
return(ERROR);
|
||||
}
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
91
utility/rtos_compatibility_layers/posix/px_mx_attr_destroy.c
Normal file
91
utility/rtos_compatibility_layers/posix/px_mx_attr_destroy.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutexattr_destroy PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall destroy a mutex attributes object; the object */
|
||||
/* becomes,in effect,uninitialized.A destroyed attr attributes object */
|
||||
/* can be reinitialized using pthread_mutexattr_init(); */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the mutex attributes */
|
||||
/* object to be destroyed. */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 If successful */
|
||||
/* Value In case of any error or the results */
|
||||
/* of referencing the object after it */
|
||||
/* has been destroyed. */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
|
||||
{
|
||||
|
||||
/* Clear the flag and make this pthread_mutexattr structure free */
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->in_use == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No then destroy the attributes object */
|
||||
attr->in_use = TX_FALSE;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutexattr_getprotocol PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall gets the mutex protocol attribute. */
|
||||
/* The protocol of a mutex is contained in the protocol attribute. */
|
||||
/* attributes. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Pointer to the mutex attributes */
|
||||
/* protocol Pointer to return mutex protocol */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 If successful */
|
||||
/* Value In case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutexattr_getprotocol( pthread_mutexattr_t *attr, INT *protocol)
|
||||
{
|
||||
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->in_use == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*protocol = attr->protocol;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutexattr_getpshared PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall gets the mutex protocol attribute. */
|
||||
/* The protocol of a mutex is contained in the protocol attribute. */
|
||||
/* attributes. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Pointer to the mutex attributes */
|
||||
/* pshared Pointer to return mutex pshared attr */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 If successful */
|
||||
/* Value In case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutexattr_getpshared( pthread_mutexattr_t *attr, INT *pshared)
|
||||
{
|
||||
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->in_use == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*pshared = attr->pshared;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
87
utility/rtos_compatibility_layers/posix/px_mx_attr_gettype.c
Normal file
87
utility/rtos_compatibility_layers/posix/px_mx_attr_gettype.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutexattr_gettype PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall gets the mutex type attribute. */
|
||||
/* The type of mutex is contained in the type attribute of the mutex */
|
||||
/* attributes. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the mutex attributes */
|
||||
/* type Pointer to return mutex type */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 If successful */
|
||||
/* Value In case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutexattr_gettype( pthread_mutexattr_t *attr, INT *type)
|
||||
{
|
||||
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->in_use == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*type = attr->type ;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
92
utility/rtos_compatibility_layers/posix/px_mx_attr_initi.c
Normal file
92
utility/rtos_compatibility_layers/posix/px_mx_attr_initi.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutexattr_init PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function initializes a pthread mutex attributes object to */
|
||||
/* default values, if the object is already created this call will */
|
||||
/* return an error. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Pointer to a mutex attributes */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 If successful */
|
||||
/* Value In case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_allocate_pthread_mutexattr Get a new mutexattr object */
|
||||
/* set_default_mutexattr Set mutexattr with default values */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutexattr_init(pthread_mutexattr_t *attr)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
|
||||
/* Disable interrupts. */
|
||||
TX_DISABLE
|
||||
|
||||
/* Check this attributes object exists ? */
|
||||
if (attr->in_use == TX_TRUE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
TX_RESTORE
|
||||
return (EINVAL);
|
||||
}
|
||||
attr->in_use = TX_TRUE;
|
||||
set_default_mutexattr(attr);
|
||||
TX_RESTORE
|
||||
return(OK);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutexattr_setprotocol PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall sets the mutex protocol attribute. */
|
||||
/* The protocol of a mutex is contained in the protocol attribute of */
|
||||
/* the mutex attributes */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Pointer to the mutex attributes */
|
||||
/* protocol mutex protocol */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 If successful */
|
||||
/* Value In case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, INT protocol)
|
||||
{
|
||||
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->in_use == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (protocol == PTHREAD_PRIO_INHERIT )
|
||||
{
|
||||
attr->protocol = protocol;
|
||||
return(OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
posix_errno = ENOSYS;
|
||||
posix_set_pthread_errno(ENOSYS);
|
||||
return(ENOSYS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutexattr_setpshared PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall sets the mutex pshared attribute. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Pointer to the mutex attributes */
|
||||
/* pshared mutex pshared attr */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 If successful */
|
||||
/* Value In case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutexattr_setpshared (pthread_mutexattr_t *attr, INT pshared)
|
||||
{
|
||||
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->in_use == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pshared == PTHREAD_PROCESS_PRIVATE)||(pshared == PTHREAD_PROCESS_SHARED) )
|
||||
{
|
||||
attr->type = pshared;
|
||||
return(OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
posix_errno = ENOSYS;
|
||||
posix_set_pthread_errno(ENOSYS);
|
||||
return(ENOSYS);
|
||||
}
|
||||
}
|
||||
}
|
||||
96
utility/rtos_compatibility_layers/posix/px_mx_attr_settype.c
Normal file
96
utility/rtos_compatibility_layers/posix/px_mx_attr_settype.c
Normal file
@@ -0,0 +1,96 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutexattr_settype PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall sets the mutex type attribute. */
|
||||
/* The type of mutex is contained in the type attribute of the mutex */
|
||||
/* attributes. */
|
||||
/* ***** Only PTHREAD_MUTEX_RECURSIVE type is supported ****** */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the mutex attributes */
|
||||
/* type mutex type. */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutexattr_settype( pthread_mutexattr_t *attr, INT type)
|
||||
{
|
||||
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->in_use == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type == PTHREAD_MUTEX_RECURSIVE)
|
||||
{
|
||||
attr->type = type ;
|
||||
return(OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
posix_errno = ENOSYS;
|
||||
posix_set_pthread_errno(ENOSYS);
|
||||
return(ENOSYS);
|
||||
}
|
||||
}
|
||||
}
|
||||
100
utility/rtos_compatibility_layers/posix/px_mx_destroy.c
Normal file
100
utility/rtos_compatibility_layers/posix/px_mx_destroy.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutex_destroy PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall destroy the mutex object referenced by mutex; */
|
||||
/* the mutex object becomes,in effect, uninitialized.A destroyed mutex */
|
||||
/* object can be reinitialized using pthread_mutex_init() */
|
||||
/* It shall be safe to destroy an initialized mutex that is unlocked. */
|
||||
/* Attempting to destroy a locked mutex results in undefined behavior. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mutex Address of the mutex */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 If successful */
|
||||
/* Value In case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_mutex_delete ThreadX Mutex service */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutex_destroy(pthread_mutex_t *mutex)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
TX_MUTEX *mutex_ptr;
|
||||
INT status,retval;
|
||||
|
||||
/* Disable interrupts. */
|
||||
TX_DISABLE
|
||||
|
||||
mutex_ptr = (TX_MUTEX*) mutex;
|
||||
|
||||
status = tx_mutex_delete(mutex_ptr);
|
||||
if (status == TX_SUCCESS)
|
||||
{
|
||||
mutex->in_use = TX_FALSE;
|
||||
retval = OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
retval = EINVAL;
|
||||
}
|
||||
|
||||
TX_RESTORE
|
||||
return(retval);
|
||||
}
|
||||
136
utility/rtos_compatibility_layers/posix/px_mx_init.c
Normal file
136
utility/rtos_compatibility_layers/posix/px_mx_init.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutex_init PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall init the mutex object referenced by mutex with */
|
||||
/* attributes specified by attr. */
|
||||
/* If attr is NULL, the default mutex attributes are used; the effect */
|
||||
/* shall be the same as passing the address of a default mutex */
|
||||
/* attributes object. Upon successful initialization,the state of the */
|
||||
/* mutex becomes initialized and unlocked. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mutex Pointer to a pthread mutex object */
|
||||
/* attr Pointer to mutex attributes */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 If successful */
|
||||
/* Value In case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_internal_error In case of some special errors */
|
||||
/* posix_in_thread_context Check whether called from a thread */
|
||||
/* tx_mutex_create Create a ThreadX Mutex object */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutex_init(pthread_mutex_t *mutex ,pthread_mutexattr_t *attr)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
TX_MUTEX *mutex_ptr;
|
||||
ULONG status,retval;
|
||||
|
||||
|
||||
|
||||
/* Make sure we're calling this routine from a thread context. */
|
||||
if (!posix_in_thread_context())
|
||||
{
|
||||
/* return POSIX error. */
|
||||
posix_internal_error(444);
|
||||
}
|
||||
|
||||
/* Disable interrupts. */
|
||||
TX_DISABLE
|
||||
|
||||
/* Check for any pthread_mutexattr_t suggested */
|
||||
if (!attr)
|
||||
{
|
||||
/* no attributes passed so assume default attributes */
|
||||
attr = &(posix_default_mutex_attr);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* attributes passed , check for validity */
|
||||
if (( (attr->in_use) == TX_FALSE)|| (attr->type!=PTHREAD_MUTEX_RECURSIVE))
|
||||
{
|
||||
/* attributes passed is not valid, return with an error */
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
}
|
||||
|
||||
mutex_ptr = (&(mutex->mutex_info)) ;
|
||||
|
||||
/* Now actually create the mutex */
|
||||
status = tx_mutex_create(mutex_ptr, "PMTX", TX_INHERIT);
|
||||
|
||||
if ( status == TX_SUCCESS)
|
||||
{
|
||||
mutex->in_use = TX_TRUE;
|
||||
retval = OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
mutex->in_use = TX_FALSE;
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
retval = EINVAL;
|
||||
}
|
||||
|
||||
TX_RESTORE
|
||||
return(retval);
|
||||
}
|
||||
103
utility/rtos_compatibility_layers/posix/px_mx_lock.c
Normal file
103
utility/rtos_compatibility_layers/posix/px_mx_lock.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutex_lock PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function locks the mutex object referenced. If the mutex is */
|
||||
/* already locked, the calling thread shall block until the mutex */
|
||||
/* becomes available. This operation shall return with the mutex object*/
|
||||
/* referenced by mutex in the locked state with the calling thread as */
|
||||
/* its owner. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mutex Address of the mutex */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_thread_identify Get calling thread's pointer */
|
||||
/* tx_mutex_get ThreadX Mutex Service */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutex_lock(pthread_mutex_t *mutex )
|
||||
{
|
||||
|
||||
TX_MUTEX *mutex_ptr;
|
||||
TX_THREAD *thread_ptr;
|
||||
INT retval,status;
|
||||
|
||||
mutex_ptr = (TX_MUTEX*)mutex;
|
||||
|
||||
thread_ptr = tx_thread_identify();
|
||||
if ( (mutex_ptr->tx_mutex_ownership_count > 0 ) && (thread_ptr == (mutex_ptr->tx_mutex_owner )))
|
||||
{
|
||||
posix_errno = EDEADLK;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return (EDEADLK);
|
||||
}
|
||||
status = tx_mutex_get( mutex_ptr, TX_WAIT_FOREVER);
|
||||
switch ( status)
|
||||
{
|
||||
case TX_SUCCESS:
|
||||
retval = OK;
|
||||
break;
|
||||
|
||||
default:
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
retval = EINVAL;
|
||||
break;
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* set_default_mutexattr PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function sets default mutex attr w/ default information. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mutexattr mutex attr object pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Start-up code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID set_default_mutexattr(pthread_mutexattr_t *mutexattr)
|
||||
{
|
||||
mutexattr->type = PTHREAD_MUTEX_DEFAULT;
|
||||
mutexattr->protocol = PTHREAD_PRIO_INHERIT;
|
||||
mutexattr->pshared = PTHREAD_PROCESS_PRIVATE;
|
||||
mutexattr->in_use = TX_TRUE;
|
||||
return;
|
||||
}
|
||||
120
utility/rtos_compatibility_layers/posix/px_mx_timedlock.c
Normal file
120
utility/rtos_compatibility_layers/posix/px_mx_timedlock.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutex_timedlock PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function locks the mutex object referenced. If the mutex is */
|
||||
/* already locked, the calling thread shall block until the mutex */
|
||||
/* becomes available as in the pthread_mutex_lock( ) function. If the */
|
||||
/* mutex cannot be locked without waiting for another thread to unlock */
|
||||
/* the mutex, this wait shall be terminated when the specified timeout */
|
||||
/* expires. This operation shall return with the mutex object */
|
||||
/* referenced by mutex in the locked state with the calling thread as */
|
||||
/* its owner. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mutex Address of the mutex */
|
||||
/* timespec Pointer to timespec structure which */
|
||||
/* holds timeout period in clock ticks */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_thread_identify Get calling thread's pointer */
|
||||
/* tx_mutex_get ThreadX Mutex Service */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutex_timedlock(pthread_mutex_t *mutex, struct timespec *abs_timeout)
|
||||
{
|
||||
|
||||
TX_MUTEX *mutex_ptr;
|
||||
TX_THREAD *thread_ptr;
|
||||
INT retval,status;
|
||||
ULONG timeout_ticks;
|
||||
|
||||
|
||||
mutex_ptr = (TX_MUTEX*)mutex;
|
||||
|
||||
thread_ptr = tx_thread_identify();
|
||||
if ( (mutex_ptr->tx_mutex_ownership_count > 0 ) && (thread_ptr == (mutex_ptr->tx_mutex_owner )))
|
||||
{
|
||||
posix_errno = EDEADLK;
|
||||
posix_set_pthread_errno(EDEADLK);
|
||||
return (EDEADLK);
|
||||
}
|
||||
|
||||
timeout_ticks = posix_abs_time_to_rel_ticks(abs_timeout);
|
||||
|
||||
status = tx_mutex_get( mutex_ptr, timeout_ticks);
|
||||
|
||||
switch ( status)
|
||||
{
|
||||
case TX_SUCCESS:
|
||||
retval = OK;
|
||||
break;
|
||||
|
||||
case TX_NOT_AVAILABLE:
|
||||
posix_errno = ETIMEDOUT;
|
||||
posix_set_pthread_errno(ETIMEDOUT);
|
||||
retval = ETIMEDOUT;
|
||||
break;
|
||||
|
||||
default:
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
retval = EINVAL;
|
||||
break;
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
111
utility/rtos_compatibility_layers/posix/px_mx_trylock.c
Normal file
111
utility/rtos_compatibility_layers/posix/px_mx_trylock.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutex_trylock PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall be equivalent to pthread_mutex_lock(), except */
|
||||
/* that if the mutex object referenced by mutex is currently locked */
|
||||
/* (by any thread,including the current thread), the call shall return */
|
||||
/* immediately. If the mutex type is PTHREAD_MUTEX_RECURSIVE and the */
|
||||
/* mutex is currently owned by the calling thread,the mutex lock count */
|
||||
/* shall be incremented by one and the pthread_mutex_trylock()function */
|
||||
/* shall immediately return success. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mutex Pointer to the mutex object */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 If successful */
|
||||
/* Value In case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_mutex_get ThreadX Mutex get service. */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutex_trylock(pthread_mutex_t *mutex)
|
||||
{
|
||||
|
||||
TX_MUTEX *mutex_ptr;
|
||||
INT retval,status;
|
||||
|
||||
/* convert pthread mutex object to ThreadX mutex */
|
||||
mutex_ptr = (TX_MUTEX *)mutex;
|
||||
|
||||
/* Try to get the mutex */
|
||||
status = tx_mutex_get( mutex_ptr, TX_NO_WAIT);
|
||||
|
||||
switch ( status)
|
||||
{
|
||||
case TX_SUCCESS:
|
||||
retval = OK;
|
||||
break;
|
||||
|
||||
case TX_DELETED:
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
retval = EINVAL;
|
||||
break;
|
||||
|
||||
case TX_NOT_AVAILABLE:
|
||||
posix_errno = EBUSY;
|
||||
posix_set_pthread_errno(EBUSY);
|
||||
retval = EBUSY;
|
||||
break;
|
||||
|
||||
default:
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
retval = EINVAL;
|
||||
break;
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
108
utility/rtos_compatibility_layers/posix/px_mx_unlock.c
Normal file
108
utility/rtos_compatibility_layers/posix/px_mx_unlock.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_mutex_unlock PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall release the mutex object referenced by mutex. */
|
||||
/* The manner in which a mutex is released is dependent upon the mutex */
|
||||
/* type attribute. If there are threads blocked on the mutex object */
|
||||
/* referenced by mutex when pthread_mutex_unlock() is called,resulting */
|
||||
/* in the mutex becoming available,the scheduling policy shall */
|
||||
/* determine which thread shall acquire the mutex. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* mutex Address of the mutex */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_mutex_put ThreadX Mutex service */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_mutex_unlock(pthread_mutex_t *mutex )
|
||||
{
|
||||
|
||||
TX_MUTEX *mutex_ptr;
|
||||
INT retval,status;
|
||||
|
||||
|
||||
/* convert pthread mutex object to ThreadX mutex */
|
||||
mutex_ptr = (TX_MUTEX*)mutex;
|
||||
status = tx_mutex_put( mutex_ptr);
|
||||
switch ( status)
|
||||
{
|
||||
case TX_SUCCESS:
|
||||
retval = OK;
|
||||
break;
|
||||
|
||||
case TX_MUTEX_ERROR:
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
retval = EINVAL;
|
||||
break;
|
||||
|
||||
case TX_NOT_OWNED:
|
||||
posix_errno = EPERM;
|
||||
posix_set_pthread_errno(EPERM);
|
||||
retval = EPERM;
|
||||
break;
|
||||
|
||||
default:
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
retval = EINVAL;
|
||||
break;
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
113
utility/rtos_compatibility_layers/posix/px_nanosleep.c
Normal file
113
utility/rtos_compatibility_layers/posix/px_nanosleep.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* nanosleep PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall cause the current thread to be suspended from */
|
||||
/* execution until the time interval specified by the req argument has */
|
||||
/* elapsed */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* req Is the number of real-time (as opposed */
|
||||
/* to CPU-time) seconds and nanoseconds to */
|
||||
/* suspend the calling thread. */
|
||||
/* rem Points to a structure to receive the */
|
||||
/* remaining time if the function is */
|
||||
/* interrupted by a signal. This pointer */
|
||||
/* may be NULL. */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* zero If the function returns because the */
|
||||
/* requested time has elapsed. */
|
||||
/* */
|
||||
/* -1 If this functions fails if req argument */
|
||||
/* specified a value less than zero or */
|
||||
/* greater than or equal to 1 000 million. */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_thread_sleep ThreadX thread sleep service */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT nanosleep(struct timespec *req, struct timespec *rem)
|
||||
{
|
||||
|
||||
ULONG timer_ticks;
|
||||
|
||||
/* Check for valid inputs */
|
||||
/* The nanosecond value must be greater than zero or less than 1 000 million. */
|
||||
if ( (!req) || ((req->tv_nsec) <= 0) || (req->tv_nsec > 999999999 )) /* 08-11-2005 */
|
||||
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Convert sleep time into Clock ticks */
|
||||
/* Also add some padding so that the thread will sleep no less than the
|
||||
specified time */
|
||||
|
||||
timer_ticks = (ULONG) ( ( req->tv_sec * CPU_TICKS_PER_SECOND ) + ( req->tv_nsec/ NANOSECONDS_IN_CPU_TICK) + 1 ); /* 08-11-2005 */
|
||||
|
||||
/* Now call ThreadX thread sleep service */
|
||||
tx_thread_sleep(timer_ticks);
|
||||
|
||||
/* Sleep completed */
|
||||
if ( rem ) /* 08-11-2005 */
|
||||
{
|
||||
rem->tv_nsec = 0;
|
||||
rem->tv_sec = 0; /* 08-11-2005 */
|
||||
}
|
||||
return(OK);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_destroy PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function destroys a pthread attributes object and allows the */
|
||||
/* system to reclaim any resources associated with that pthread */
|
||||
/* attributes object.This doesn't have an effect on any threads created*/
|
||||
/* using this pthread attributes object. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the pthread attributes */
|
||||
/* object to be destroyed. */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 If successful */
|
||||
/* Value In case of any error or the results */
|
||||
/* of referencing the object after it */
|
||||
/* has been destroyed. */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_destroy(pthread_attr_t *attr)
|
||||
{
|
||||
|
||||
/* Clear the flag and make this pthread_attr structure free */
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
return(EINVAL);
|
||||
else
|
||||
{
|
||||
/* No then destroy the attributes object */
|
||||
attr->inuse = TX_FALSE;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_getdetachstate PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function returns the detach state attribute from a pthread */
|
||||
/* attributes object specified.The detach state of a thread indicates */
|
||||
/* whether the system is allowed to free thread resources when the */
|
||||
/* thread terminates. */
|
||||
/* The detach state specifies one of: */
|
||||
/* PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE. */
|
||||
/* The default detach state (DEFAULT_DETACHSTATE) is: */
|
||||
/* PTHREAD_CREATE_JOINABLE. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* detachstate Address of variable to contain the */
|
||||
/* returned detach state */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_getdetachstate( pthread_attr_t *attr,INT *detachstate)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*detachstate = attr->detach_state ;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_getinheritsched PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function returns the inheritsched attribute from the thread */
|
||||
/* attributes object specified.The inheritsched attribute will be one */
|
||||
/* of PTHREAD_EXPLICIT_SCHED or PTHREAD_INHERIT_SCHED. */
|
||||
/* The default inheritsched attribute is PTHREAD_EXPLICIT_SCHED, */
|
||||
/* with a default priority of 0. */
|
||||
/* Use the inheritsched parameter to inherit or explicitly specify the */
|
||||
/* scheduling attributes when creating new threads. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* inheritsched Address of variable to contain the */
|
||||
/* returned inheritsched attribute */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_getinheritsched(pthread_attr_t *attr, INT *inheritsched)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*inheritsched = attr->inherit_sched ;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_getschedparam PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function returns the scheduling parameters attribute from the */
|
||||
/* pthread attributes object. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* sched_param Address of structure to contain the */
|
||||
/* returned scheduling parameters */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_getschedparam(pthread_attr_t *attr,struct sched_param *param)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
param->sched_priority = attr->sched_attr.sched_priority;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_getschedpolicy PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function returns the scheduling policy from the pthread */
|
||||
/* attributes object. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* policy Address of variable to contain the */
|
||||
/* returned scheduling policy */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_getschedpolicy(pthread_attr_t *attr, INT *policy)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*policy = attr->sched_policy;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_getstack PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function gets the thread creation stack attributes stackaddr */
|
||||
/* and stacksize in the attr object. */
|
||||
/* The stack attributes specify the area of storage to be used for the*/
|
||||
/* created thread's stack. The base (lowest addressable byte) of the */
|
||||
/* storage shall be stackaddr , and the size of the storage shall be */
|
||||
/* stacksize bytes. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* stackaddr Pointer to hold Address of stack */
|
||||
/* stacksize Holds the stack size */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_getstack( pthread_attr_t *attr,void **stackaddr,
|
||||
size_t *stacksize)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*stackaddr = attr->stack_address;
|
||||
*stacksize = attr->stack_size ;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_getstackaddr PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function returns the stack address associated with a pthread */
|
||||
/* attributes */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* stackaddr Address of variable to contain the */
|
||||
/* returned stack address */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_getstackaddr( pthread_attr_t *attr,void **stackaddr)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*stackaddr = attr->stack_address ;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_getstacksize PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function returns the stack size associated with a pthread */
|
||||
/* The stacksize is the minimum stack size (in bytes) allocated for */
|
||||
/* the created threads stack. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* stacksize Address of variable to contain the */
|
||||
/* returned stack size */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize)
|
||||
{
|
||||
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*stacksize = attr->stack_size;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
86
utility/rtos_compatibility_layers/posix/px_pth_attr_init.c
Normal file
86
utility/rtos_compatibility_layers/posix/px_pth_attr_init.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_init PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function initializes a pthread attributes object to default */
|
||||
/* values,if the object is already created this call will reinitialize */
|
||||
/* it else it will create a new attr object and initializes it. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* set_default_pthread_attr to reset with defualt parameters */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_init(pthread_attr_t *attr)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
TX_DISABLE
|
||||
|
||||
/* Check this attributes object exists ? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
attr->inuse = TX_TRUE;
|
||||
|
||||
set_default_pthread_attr(attr);
|
||||
|
||||
TX_RESTORE
|
||||
return(OK);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_setdetachstate PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function sets the detach state attribute from a pthread */
|
||||
/* attributes object specified.The detach state of a thread indicates */
|
||||
/* whether the system is allowed to free thread resources when the */
|
||||
/* thread terminates. */
|
||||
/* The detach state specifies one of: */
|
||||
/* PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE. */
|
||||
/* The default detach state (DEFAULT_DETACHSTATE) is: */
|
||||
/* PTHREAD_CREATE_JOINABLE. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* detachstate detach state to set */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
INT pthread_attr_setdetachstate(pthread_attr_t *attr,INT detachstate)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
attr->detach_state = detachstate ;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_setinheritsched PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function sets the inheritsched attribute from the thread */
|
||||
/* attributes object specified.The inheritsched attribute will be one */
|
||||
/* of PTHREAD_EXPLICIT_SCHED or PTHREAD_INHERIT_SCHED. */
|
||||
/* The default inheritsched attribute is PTHREAD_EXPLICIT_SCHED, */
|
||||
/* with a default priority of 0. */
|
||||
/* Use the inheritsched parameter to inherit or explicitly specify the */
|
||||
/* scheduling attributes when creating new threads. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* inheritsched inheritsched attribute to set */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_setinheritsched(pthread_attr_t *attr, INT inheritsched)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
attr->inherit_sched = inheritsched ;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_setschedparam PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function sets the scheduling parameters attribute for the */
|
||||
/* pthread attributes object. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* sched_param Address of structure containing the */
|
||||
/* scheduling parameters to set */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_setschedparam(pthread_attr_t *attr,struct sched_param *param)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
if (param->sched_priority == 0)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
if(param->sched_priority >= PX_LOWEST_PRIORITY && param->sched_priority <= PX_HIGHEST_PRIORITY )
|
||||
{
|
||||
|
||||
attr->sched_attr.sched_priority = param->sched_priority;
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_setschedpolicy PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function sets the scheduling policy from the pthread */
|
||||
/* attributes object. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* policy variable holding the scheduling */
|
||||
/* policy to set */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_setschedpolicy(pthread_attr_t *attr, INT policy)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
attr->sched_policy = policy;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_setstack PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function sets the thread creation stack attributes stackaddr */
|
||||
/* and stacksize in the attr object. */
|
||||
/* The stack attributes specify the area of storage to be used for the*/
|
||||
/* created thread<61>s stack. The base (lowest addressable byte) of */
|
||||
/* the storage shall be stackaddr , and the size of the storage shall */
|
||||
/* be stacksize bytes. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* stackaddr Address of stack */
|
||||
/* stacksize Holds the stack size */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_setstack( pthread_attr_t *attr,void *stackaddr,
|
||||
size_t stacksize)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
attr->stack_address = stackaddr; /* This has got no effect */
|
||||
attr->stack_size = stacksize;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_setstackaddr PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function sets the stack address associated with a pthread */
|
||||
/* attributes */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* stackaddr Address of variable to contain the */
|
||||
/* stack address to set */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_setstackaddr(pthread_attr_t *attr,void *stackaddr)
|
||||
{
|
||||
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
attr->stack_address = stackaddr;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_attr_setstacksize PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function sets the stack size associated with a pthread attr */
|
||||
/* The stacksize is the minimum stack size (in bytes) allocated for */
|
||||
/* the created threads stack. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr Address of the thread attributes */
|
||||
/* stacksize stack size */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
|
||||
{
|
||||
/* First check the attribute object is already destroyed? */
|
||||
if (attr->inuse == TX_FALSE)
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
attr->stack_size = stacksize;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
120
utility/rtos_compatibility_layers/posix/px_pth_cancel.c
Normal file
120
utility/rtos_compatibility_layers/posix/px_pth_cancel.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_cancel PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* The pthread_cancel function shall request that thread be canceled. */
|
||||
/* The target thread<61>s cancelability state and type determines when */
|
||||
/* the cancellation takes effect. When the cancellation is acted on, */
|
||||
/* the cancelation cleanup handlers for thread shall be called. When */
|
||||
/* the last cancelation cleanup handler returns, the thread-specific */
|
||||
/* data destructor functions shall be called for thread. When the last */
|
||||
/* destructor function returns, thread shall be terminated. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread pthread handle to thread to be canceled */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* zero If successful */
|
||||
/* error number If fails */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_cancel(pthread_t thread)
|
||||
{
|
||||
|
||||
TX_THREAD *thread_ptr;
|
||||
POSIX_TCB *pthread_ptr;
|
||||
|
||||
|
||||
|
||||
|
||||
/* Get the thread identifier of the pthread to be canceled */
|
||||
thread_ptr = posix_tid2thread(thread);
|
||||
|
||||
if( (thread_ptr->tx_thread_state == TX_COMPLETED) || (thread_ptr->tx_thread_state == TX_TERMINATED) )
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
/* get posix TCB for this pthread */
|
||||
pthread_ptr = (POSIX_TCB *)thread_ptr;
|
||||
|
||||
/* Check if target pthread is created with cancel enable */
|
||||
if ( pthread_ptr->cancel_state != PTHREAD_CANCEL_ENABLE)
|
||||
{
|
||||
posix_errno= EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
if( pthread_ptr->cancel_type==PTHREAD_CANCEL_DEFERRED )
|
||||
{
|
||||
/* set cancel request for cancelation point */
|
||||
pthread_ptr->cancel_request=TRUE;
|
||||
}
|
||||
else if(pthread_ptr->cancel_type==PTHREAD_CANCEL_ASYNCHRONOUS )
|
||||
{
|
||||
/* Signal the housekeeping ThreadX thread to cancel (delete) the requested pthread now */
|
||||
|
||||
posix_destroy_pthread(pthread_ptr,(VOID *)0);
|
||||
}
|
||||
else /* illegal value in pthread_ptr->cancel_type */
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
/* Indicate success. */
|
||||
return(OK);
|
||||
}
|
||||
260
utility/rtos_compatibility_layers/posix/px_pth_create.c
Normal file
260
utility/rtos_compatibility_layers/posix/px_pth_create.c
Normal file
@@ -0,0 +1,260 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_create PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This creates a new thread with attributes specified by attr within */
|
||||
/* a process.If the attr is NULL,then default attributes are used. */
|
||||
/* Upon successful completion, pthread_create() stores the ID of the */
|
||||
/* created thread in the location referenced by thread. */
|
||||
/* The thread is created executing start_routine with arg as its sole */
|
||||
/* argument. */
|
||||
/* Initially, threads are created from within a process. Once created, */
|
||||
/* threads are peers, and may create other threads. Note that an */
|
||||
/* "initial thread" exists by default which runs 'main' */
|
||||
/* If pthread_create( ) fails,no new thread is created and the contents*/
|
||||
/* of the location referenced by thread are undefined. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread place to store newly created thread ID */
|
||||
/* Each thread in a process is uniquely */
|
||||
/* identified during its lifetime by a */
|
||||
/* value of type pthread_t called as */
|
||||
/* thread ID. */
|
||||
/* */
|
||||
/* attr attributes object , NULL = Default attr.*/
|
||||
/* start_routine thread start up routine */
|
||||
/* arg arguments to start up routine by ref. */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* zero If successful */
|
||||
/* error number If fails */
|
||||
/* pthread_create() function will fail if: */
|
||||
/* [EAGAIN] system lacked the necessary */
|
||||
/* resources to create a thread, */
|
||||
/* or the system-imposed limit on */
|
||||
/* the number of pthreads in */
|
||||
/* a process PTHREAD_THREADS_MAX */
|
||||
/* would be exceeded. */
|
||||
/* [EINVAL] value specified by attr is */
|
||||
/* invalid. */
|
||||
/* [EPERM] The caller does not have */
|
||||
/* appropriate permission to set */
|
||||
/* the required scheduling */
|
||||
/* parameters or scheduling policy*/
|
||||
/* */
|
||||
/* This call will not return an error code of [EINTR]*/
|
||||
/* */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_in_thread_context To check calling context. */
|
||||
/* posix_internal_error Internal error */
|
||||
/* posix_allocate_pthread_t Allocate control block for pthread */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_create (pthread_t *thread, pthread_attr_t *attr,
|
||||
void *(*start_routine)(void*),void *arg)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
|
||||
TX_THREAD *thread_ptr;
|
||||
POSIX_TCB *pthread_ptr, *current_thread_ptr;
|
||||
INT status,retval;
|
||||
|
||||
|
||||
|
||||
/* Make sure we're calling this routine from a thread context. */
|
||||
if (!posix_in_thread_context())
|
||||
{
|
||||
/* return POSIX error. */
|
||||
posix_internal_error(444);
|
||||
}
|
||||
|
||||
/* Disable interrupts. */
|
||||
|
||||
|
||||
/* check for any pthread_t attr suggested */
|
||||
if (!attr)
|
||||
{
|
||||
/* no attributes passed so assume default attributes */
|
||||
attr = &(posix_default_pthread_attr);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check attributes passed , check for validity */
|
||||
if ( (attr->inuse) == TX_FALSE)
|
||||
{
|
||||
/* attributes passed are not valid, return with an error */
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Get a pthread control block for this new pthread */
|
||||
TX_DISABLE
|
||||
status = posix_allocate_pthread_t(&pthread_ptr);
|
||||
TX_RESTORE
|
||||
/* Make sure we got a Thread control block */
|
||||
if ((status == ERROR) || (!pthread_ptr))
|
||||
{
|
||||
/* Configuration/resource error. */
|
||||
return(EAGAIN);
|
||||
}
|
||||
|
||||
if(attr->inherit_sched==PTHREAD_INHERIT_SCHED)
|
||||
{
|
||||
/* get current thread tcb */
|
||||
current_thread_ptr=posix_tid2tcb(pthread_self());
|
||||
|
||||
/* copy scheduling attributes */
|
||||
pthread_ptr->current_priority = current_thread_ptr->current_priority ;
|
||||
pthread_ptr->detach_state = current_thread_ptr->detach_state ;
|
||||
pthread_ptr->inherit_sched = current_thread_ptr->inherit_sched ;
|
||||
pthread_ptr->orig_priority = current_thread_ptr->orig_priority ;
|
||||
pthread_ptr->sched_attr.sched_priority= current_thread_ptr->sched_attr.sched_priority ;
|
||||
pthread_ptr->pthread_flags = current_thread_ptr->pthread_flags ;
|
||||
pthread_ptr->sched_policy = current_thread_ptr->sched_policy;
|
||||
pthread_ptr->stack_size = current_thread_ptr->stack_size ;
|
||||
pthread_ptr->stack_address = NULL; /* will allocate our own stack */
|
||||
pthread_ptr->threshold = pthread_ptr->current_priority ; /* preemption threshold */
|
||||
}
|
||||
else /* assume PTHREAD_EXPLICIT_SCHED */
|
||||
{
|
||||
|
||||
/* copy pthread-attr to TCB */
|
||||
posix_copy_pthread_attr(pthread_ptr,attr);
|
||||
|
||||
/* preemption treshold */
|
||||
pthread_ptr->threshold = pthread_ptr->current_priority ;
|
||||
/* scheduling */
|
||||
if(pthread_ptr->sched_policy==SCHED_RR) pthread_ptr->time_slice = SCHED_RR_TIME_SLICE;
|
||||
else pthread_ptr->time_slice = 0;
|
||||
}
|
||||
|
||||
/* Now set up pthread initial parameters */
|
||||
|
||||
pthread_ptr->entry_parameter = arg;
|
||||
pthread_ptr->start_routine = start_routine;
|
||||
/* Newly created pthread not joined by anybody! */
|
||||
pthread_ptr->is_joined_by = TX_FALSE;
|
||||
pthread_ptr->joined_by_pthreadID =TX_FALSE;
|
||||
/* Newly created pthread not yet joined to any other pthread */
|
||||
pthread_ptr->is_joined_to = TX_FALSE;
|
||||
pthread_ptr->joined_to_pthreadID = TX_FALSE;
|
||||
|
||||
|
||||
/* Allow cancel */
|
||||
pthread_ptr->cancel_state = PTHREAD_CANCEL_ENABLE;
|
||||
pthread_ptr->cancel_type = PTHREAD_CANCEL_DEFERRED;
|
||||
pthread_ptr->cancel_request = FALSE;
|
||||
|
||||
pthread_ptr->value_ptr = NULL;
|
||||
|
||||
|
||||
/* default stack allocation */
|
||||
if((attr->stack_address)==NULL)
|
||||
{
|
||||
pthread_ptr->stack_size = attr->stack_size ;
|
||||
status = posix_memory_allocate( pthread_ptr->stack_size, &(pthread_ptr->stack_address));
|
||||
|
||||
/* problem allocating stack space */
|
||||
if ((status == ERROR))
|
||||
{
|
||||
/* Configuration/resource error. */
|
||||
return(EAGAIN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Create an event flags group for sigwait. */
|
||||
retval = tx_event_flags_create(&(pthread_ptr -> signals.signal_event_flags), "posix sigwait events");
|
||||
|
||||
/* Get the thread info from the TCB. */
|
||||
thread_ptr = posix_tcb2thread(pthread_ptr);
|
||||
|
||||
/* Now actually create and start the thread. */
|
||||
/* convert Posix priorities to Threadx priority */
|
||||
retval += tx_thread_create( thread_ptr,
|
||||
"pthr",
|
||||
posix_thread_wrapper,
|
||||
(ULONG)pthread_ptr,
|
||||
pthread_ptr->stack_address,
|
||||
pthread_ptr->stack_size,
|
||||
(TX_LOWEST_PRIORITY - pthread_ptr->current_priority + 1),
|
||||
(TX_LOWEST_PRIORITY - pthread_ptr->threshold + 1),
|
||||
pthread_ptr->time_slice,
|
||||
TX_AUTO_START);
|
||||
|
||||
/* See if ThreadX encountered an error */
|
||||
if (retval)
|
||||
{
|
||||
/* Internal error */
|
||||
posix_error_handler(3333);
|
||||
retval = EACCES;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Everything is fine. */
|
||||
/* create a pthreadID by type casting POSIX_TCB into pthread_t */
|
||||
pthread_ptr->pthreadID = (pthread_t )pthread_ptr;
|
||||
*thread = pthread_ptr->pthreadID ;
|
||||
retval = OK;
|
||||
}
|
||||
|
||||
/* Everything worked fine if we got here */
|
||||
return(retval);
|
||||
|
||||
}
|
||||
107
utility/rtos_compatibility_layers/posix/px_pth_detach.c
Normal file
107
utility/rtos_compatibility_layers/posix/px_pth_detach.c
Normal file
@@ -0,0 +1,107 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_detach PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* */
|
||||
/* The pthread_detach() function indicates that system resources for */
|
||||
/* the specified thread should be reclaimed when the thread ends. */
|
||||
/* If the thread is already ended, resources are reclaimed immediately.*/
|
||||
/* This routine does not cause the thread to end. */
|
||||
/* After pthread_detach() has been issued, it is not valid to try to */
|
||||
/* pthread_join() with the target thread. */
|
||||
/* Eventually, you should call pthread_join() or pthread_detach() for */
|
||||
/* every thread that is created joinable (with a detachstate of */
|
||||
/* PTHREAD_CREATE_JOINABLE)so that the system can reclaim all resources*/
|
||||
/* associated with the thread. Failure to join to or detach joinable */
|
||||
/* threads will result in memory and other resource leaks until the */
|
||||
/* process ends. If thread doesn't represent a valid undetached thread,*/
|
||||
/* pthread_detach() will return ESRCH. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread pthread handle to the target thread */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* zero If successful */
|
||||
/* error number If fails */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_detach(pthread_t thread)
|
||||
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
POSIX_TCB *pthread_ptr;
|
||||
|
||||
TX_DISABLE
|
||||
|
||||
pthread_ptr = posix_tid2tcb(thread);
|
||||
if(pthread_ptr==NULL)
|
||||
{
|
||||
TX_RESTORE
|
||||
return(ESRCH);
|
||||
}
|
||||
if(pthread_ptr->is_detached==TX_TRUE)
|
||||
{
|
||||
TX_RESTORE
|
||||
return (EINVAL);
|
||||
}
|
||||
pthread_ptr->is_detached = TX_TRUE;
|
||||
|
||||
TX_RESTORE
|
||||
return(OK);
|
||||
}
|
||||
80
utility/rtos_compatibility_layers/posix/px_pth_equal.c
Normal file
80
utility/rtos_compatibility_layers/posix/px_pth_equal.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_equal PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* */
|
||||
/* This function compares two pthread handles for equality. */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread1 pthread handle to the first thread */
|
||||
/* thread2 pthread handle to the second thread */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 The pthread handles do not refer to the */
|
||||
/* same thread */
|
||||
/* 1 The pthread handles refer to the same */
|
||||
/* thread */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_equal(pthread_t thread1, pthread_t thread2)
|
||||
{
|
||||
if (thread1 == thread2)
|
||||
|
||||
return(1);
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
94
utility/rtos_compatibility_layers/posix/px_pth_exit.c
Normal file
94
utility/rtos_compatibility_layers/posix/px_pth_exit.c
Normal file
@@ -0,0 +1,94 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_exit PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* */
|
||||
/* The pthread_exit() function terminates the calling thread, making */
|
||||
/* its exit status available to any waiting threads.Normally,a thread */
|
||||
/* terminates by returning from the start routine that was specified */
|
||||
/* in the pthread_create() call which started it. */
|
||||
/* An implicit call to pthread_exit() occurs when any thread returns */
|
||||
/* from its start routine. (With the exception of the initial thread, */
|
||||
/* at which time an implicit call to exit() occurs). */
|
||||
/* The pthread_exit() function provides an interface similar to exit()*/
|
||||
/* but on a per-thread basis. */
|
||||
/* */
|
||||
/* pthread_exit() does not return. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* value_ptr exit parameter */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* none pthread_exit() does not return. */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID pthread_exit(void *value_ptr)
|
||||
{
|
||||
|
||||
TX_THREAD *thread_ptr;
|
||||
POSIX_TCB *pthread_ptr;
|
||||
|
||||
/* Get the thread identifier of the currently running thread */
|
||||
thread_ptr = tx_thread_identify();
|
||||
/* get posix TCB for this pthread */
|
||||
pthread_ptr = (POSIX_TCB *)thread_ptr;
|
||||
|
||||
/* Signal the housekeeping ThreadX thread to delete the requested pthread */
|
||||
posix_destroy_pthread(pthread_ptr,value_ptr);
|
||||
|
||||
/* Indicate success. */
|
||||
return;
|
||||
|
||||
}
|
||||
100
utility/rtos_compatibility_layers/posix/px_pth_getcanceltype.c
Normal file
100
utility/rtos_compatibility_layers/posix/px_pth_getcanceltype.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_getcanceltype PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* The pthread_fetcancelstate()function shall atomically both get the */
|
||||
/* calling thread<61>s cancelability type to the indicated type and */
|
||||
/* return the previous cancelability type at the location referenced */
|
||||
/* by oldtype. Legal values for type are PTHREAD_CANCEL_DEFERRED and */
|
||||
/* PTHREAD_CANCEL_ASYNCHRONOUS. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* type New cancelability type to be set */
|
||||
/* oldtype Pointer to old cancelability type */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_getcanceltype (INT type, INT *oldtype)
|
||||
{
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
TX_THREAD *thread_ptr;
|
||||
POSIX_TCB *pthread_ptr;
|
||||
|
||||
/* First check for validity of the new cancel type to be set */
|
||||
if ( ( type == PTHREAD_CANCEL_DEFERRED ) || ( type == PTHREAD_CANCEL_ASYNCHRONOUS ) )
|
||||
{
|
||||
TX_DISABLE
|
||||
|
||||
/* Get the thread identifier of the currently running thread */
|
||||
thread_ptr = tx_thread_identify();
|
||||
/* get posix TCB for this pthread */
|
||||
pthread_ptr = (POSIX_TCB *)thread_ptr;
|
||||
*oldtype = pthread_ptr->cancel_type;
|
||||
pthread_ptr->cancel_type = type;
|
||||
|
||||
TX_RESTORE
|
||||
|
||||
return(OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_getschedparam PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function returns the scheduling parameters attribute from the */
|
||||
/* pthread TCB. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread POSIX thread ID */
|
||||
/* policy Address of the scheduling policy */
|
||||
/* sched_param Address of structure to contain the */
|
||||
/* returned scheduling parameters */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_getschedparam(pthread_t thread, INT *policy, struct sched_param *param)
|
||||
{
|
||||
|
||||
POSIX_TCB *thread_tcb;
|
||||
|
||||
|
||||
thread_tcb=posix_tid2tcb(thread);
|
||||
|
||||
if(thread_tcb==NULL)
|
||||
{
|
||||
return(ESRCH);
|
||||
}
|
||||
else
|
||||
{
|
||||
*policy=thread_tcb->sched_policy;
|
||||
*param=thread_tcb->sched_attr;
|
||||
return(OK);
|
||||
}
|
||||
|
||||
}
|
||||
959
utility/rtos_compatibility_layers/posix/px_pth_init.c
Normal file
959
utility/rtos_compatibility_layers/posix/px_pth_init.c
Normal file
@@ -0,0 +1,959 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
|
||||
/* this define will force declaration of the */
|
||||
/* posix objects to happen in this file */
|
||||
#define PX_OBJECT_INIT
|
||||
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* is_posix_thread PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* Verify that the control block belongs to a POSIX thread and not */
|
||||
/* a ThreadX thread */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread_ptr Pointer to a thread control block */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* TX_FALSE if not POSIX thread. TX_TRUE if POSIX thread. */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
static INT is_posix_thread(TX_THREAD *thread_ptr)
|
||||
{
|
||||
if (((POSIX_TCB *)thread_ptr < ptcb_pool) ||
|
||||
((POSIX_TCB *)thread_ptr > &ptcb_pool[PTHREAD_THREADS_MAX - 1]))
|
||||
{
|
||||
return TX_FALSE;
|
||||
}
|
||||
return TX_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_pthread_init PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function sets up / configures / initializes all the */
|
||||
/* pthread Control Blocks that we define at compile-time in order to */
|
||||
/* ensure that there is sufficient memory. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_reset_pthread_t Reset a task control block */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Start-up code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_pthread_init(VOID)
|
||||
{
|
||||
|
||||
ULONG index;
|
||||
|
||||
/* Loop through array of TCBs and initialize each one. */
|
||||
for (index = 0; index < PTHREAD_THREADS_MAX; index++)
|
||||
{
|
||||
posix_reset_pthread_t(&(ptcb_pool[index]));
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_reset_pthread_t PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function resets a pthread w/ default information. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* ptcb pthread control block pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Start-up code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_reset_pthread_t (POSIX_TCB *ptcb)
|
||||
{
|
||||
/* Indicate this entry is not in use. */
|
||||
ptcb->in_use = TX_FALSE;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_copy_pthread_attr PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function copies pthread attributes from a pthread_attr object */
|
||||
/* to a pthread TCB */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr pthread attr object pointer */
|
||||
/* pthread_ptr target pthread TCB */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Start-up code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_copy_pthread_attr(POSIX_TCB *pthread_ptr,pthread_attr_t *attr)
|
||||
{
|
||||
|
||||
pthread_ptr->current_priority = attr->sched_attr.sched_priority ;
|
||||
pthread_ptr->detach_state = attr->detach_state ;
|
||||
pthread_ptr->inherit_sched = attr->inherit_sched ;
|
||||
pthread_ptr->orig_priority = attr->sched_attr.sched_priority ;
|
||||
pthread_ptr->sched_attr.sched_priority= attr->sched_attr.sched_priority ;
|
||||
pthread_ptr->pthread_flags = attr->pthread_flags ;
|
||||
pthread_ptr->sched_policy = attr->sched_policy;
|
||||
pthread_ptr->stack_size = attr->stack_size ;
|
||||
pthread_ptr->stack_address = attr->stack_address;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_allocate_pthread_t PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function attempts to allocate memory for a pthread stack and */
|
||||
/* a POSIX pthread Control Block (PTCB). */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* stack_size Requested task stack size */
|
||||
/* tcb_ptr Pointer to tcb pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* Completion Status */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* Nothing */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT posix_allocate_pthread_t(POSIX_TCB **ptcb_ptr)
|
||||
{
|
||||
|
||||
POSIX_TCB *ptcb;
|
||||
ULONG index;
|
||||
|
||||
/* Assume the worst. */
|
||||
*ptcb_ptr = (POSIX_TCB *)0;
|
||||
|
||||
/* This next search is optimized for simplicity, not speed. */
|
||||
for (index = 0, ptcb = ptcb_pool;
|
||||
index < PTHREAD_THREADS_MAX;
|
||||
index++, ptcb++)
|
||||
{
|
||||
/* Is this guy in use? If not, we can use it. */
|
||||
if (ptcb->in_use == TX_FALSE)
|
||||
{
|
||||
/* This pTCB is now in use. */
|
||||
ptcb->in_use = TX_TRUE;
|
||||
|
||||
/* Stop searching. */
|
||||
break;
|
||||
}
|
||||
} /* for each POSIX Thread Control Block */
|
||||
|
||||
/* Did we search all pTCBs and come up empty? */
|
||||
if (index == PTHREAD_THREADS_MAX)
|
||||
{
|
||||
/* No more pTCBs available - user configuration error. */
|
||||
return(ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Make sure the signal handler information is cleared when the new TCB is allocated. */
|
||||
memset(&(ptcb -> signals), 0, sizeof(signal_info));
|
||||
|
||||
/* Found one. */
|
||||
*ptcb_ptr = ptcb;
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_thread_wrapper PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* Every thread that is modeling a ThreadX thread has this routine as */
|
||||
/* its entry point.This routine simply calls the pthread entry routine */
|
||||
/* with its sole argument passed in pthread-create(). */
|
||||
/* */
|
||||
/* The main purpose of this function is to mimic the pthread interface */
|
||||
/* which allows 1 argument to be passed to the entry point of a thread */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* pthread_ptr pthread control block pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* *(pthread_start_routine) Application pthread entry */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* POSIX only (internal) */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_thread_wrapper(ULONG pthr_ptr)
|
||||
{
|
||||
|
||||
POSIX_TCB *pthread_ptr;
|
||||
VOID *value_ptr;
|
||||
|
||||
/* The input argument is really a pointer to the pthread's control block */
|
||||
pthread_ptr = (POSIX_TCB *) pthr_ptr;
|
||||
/* Invoke the pthread start routine with appropriate arguments */
|
||||
value_ptr = (pthread_ptr->start_routine)((VOID *)pthread_ptr->entry_parameter);
|
||||
|
||||
/* In ThreadX, when a thread returns from its entry point, it enters the */
|
||||
/* "completed" state, which is basically an infinite suspension. */
|
||||
/* now use pthread_exit call to end this pthread */
|
||||
pthread_exit(value_ptr);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_thread2tcb PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function converts a ThreadX thread identifier into */
|
||||
/* a posix pthread control block (TCB) */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread_ptr Thread pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* pthread pthread Task control block */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_internal_error Internal error */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* posix internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
POSIX_TCB *posix_thread2tcb(TX_THREAD *thread_ptr)
|
||||
{
|
||||
|
||||
POSIX_TCB *p_tcb;
|
||||
|
||||
/* Make sure we were called from a thread. */
|
||||
if (!thread_ptr)
|
||||
{
|
||||
/* Not called from a thread - error! */
|
||||
posix_internal_error(333);
|
||||
}
|
||||
|
||||
/* Make sure thread is a POSIX thread else following case is illegal. */
|
||||
if (!is_posix_thread(thread_ptr)) {
|
||||
/* Not called from a POSIX thread - error! */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* We can do this because the Thread information is intentionally */
|
||||
/* located as the first field in the structure. */
|
||||
p_tcb = (POSIX_TCB *)thread_ptr;
|
||||
|
||||
/* All done. */
|
||||
return(p_tcb);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_tcb2thread PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function converts a POSIX TCB into ThreadX thread */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* pthread_ptr pthread TCB */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* thread ThreadX thread */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_internal_error Internal error */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* posix internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
TX_THREAD *posix_tcb2thread (POSIX_TCB *pthread_ptr)
|
||||
{
|
||||
|
||||
TX_THREAD *thread;
|
||||
|
||||
/* Make sure we don't have a NULL pointer. */
|
||||
if (pthread_ptr)
|
||||
{
|
||||
/* Simply convert the TCB to a Thread via a cast */
|
||||
thread = (&(pthread_ptr->thread_info ));
|
||||
}
|
||||
else
|
||||
{
|
||||
thread = ((TX_THREAD *)0);
|
||||
}
|
||||
|
||||
return(thread);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_thread2tid PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function converts a ThreadX thread identifier into */
|
||||
/* posix thread ID */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread_ptr Thread pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* thread_ID thread_ID */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_internal_error Internal error */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* posix internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
pthread_t posix_thread2tid(TX_THREAD *thread_ptr)
|
||||
{
|
||||
|
||||
pthread_t thread_ID;
|
||||
POSIX_TCB *p_tcb;
|
||||
|
||||
/* Make sure we were called from a thread. */
|
||||
if (!thread_ptr)
|
||||
{
|
||||
/* Not called from a thread - error! */
|
||||
posix_internal_error(222);
|
||||
}
|
||||
|
||||
/* Get the TCB for this pthread */
|
||||
|
||||
p_tcb = posix_thread2tcb(thread_ptr);
|
||||
thread_ID = p_tcb->pthreadID;
|
||||
|
||||
/* All done. */
|
||||
return(thread_ID);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_tid2thread PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function converts a posix thread ID into a thread. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* tid Thread ID */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* thread_ptr Thread pointer */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* posix internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
TX_THREAD *posix_tid2thread(pthread_t ptid)
|
||||
{
|
||||
|
||||
TX_THREAD *thread;
|
||||
POSIX_TCB *pthread;
|
||||
|
||||
/* Make sure we don't have a NULL TID. */
|
||||
if (ptid)
|
||||
{
|
||||
/* convert the pthread ID to a pThread TCB */
|
||||
pthread = posix_tid2tcb(ptid);
|
||||
/* convert the pthread TCB to a pThread TCB */
|
||||
thread= posix_tcb2thread(pthread);
|
||||
}
|
||||
else
|
||||
{
|
||||
thread = ((TX_THREAD *)0);
|
||||
}
|
||||
return(thread);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_tid2tcb PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function converts a posix thread ID into a posix pthread TCB */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* tid Thread ID */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* pthread_ptr pthread pointer */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* posix internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
POSIX_TCB *posix_tid2tcb(pthread_t ptid)
|
||||
{
|
||||
|
||||
POSIX_TCB *pthread;
|
||||
|
||||
/* Make sure we don't have a NULL TID. */
|
||||
if (ptid)
|
||||
/* Simply convert the thread ID to a pthread TCB via a cast */
|
||||
pthread = (POSIX_TCB *)ptid;
|
||||
else
|
||||
pthread = ((POSIX_TCB *)0);
|
||||
|
||||
return(pthread);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_destroy_pthread PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function performs internal cleanup and housekeeping */
|
||||
/* when a pthread exits. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* pthread_ptr pointer to TCB of the pthread */
|
||||
/* to be deleted */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* OK If successful */
|
||||
/* ERROR If fails */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_queue_send Send to system mgr queue */
|
||||
/* posix_internal_error Internal error handling */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* posix internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_destroy_pthread(POSIX_TCB *pthread_ptr, VOID *value_ptr)
|
||||
{
|
||||
|
||||
ULONG request[WORK_REQ_SIZE];
|
||||
INT status;
|
||||
|
||||
/* Build the request. */
|
||||
|
||||
request[0] = (ULONG)pthread_ptr;
|
||||
request[1] = (ULONG)value_ptr;
|
||||
|
||||
/* Send a message to the SysMgr supervisor thread, asking it to delete */
|
||||
/* the pthread. Since the SysMgr supervisor thread is the highest */
|
||||
/* possible priority, this routine will be preempted when we */
|
||||
/* post the message to the SysMgr's work queue. */
|
||||
|
||||
status = tx_queue_send(&posix_work_queue, request, TX_NO_WAIT);
|
||||
/* This should always succeed. */
|
||||
if (status != TX_SUCCESS)
|
||||
{
|
||||
posix_internal_error(1001);
|
||||
}
|
||||
|
||||
/* Return the pthread's TCB to the pool of available TCB's. */
|
||||
posix_reset_pthread_t(pthread_ptr);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_do_pthread_delete PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function deletes the pthread and reclaims the stack memory. */
|
||||
/* Also it resumes any pthread joined to this exiting pthread. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* pthread_ptr pointer to TCB of the pthread */
|
||||
/* to be deleted */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* OK If successful */
|
||||
/* ERROR If fails */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_thread_terminate Terminate ThreadX thread */
|
||||
/* tx_thread_delete Delete the ThreadX thread */
|
||||
/* posix_memory_release Release the task's stack */
|
||||
/* posix_free_tcb Free pthread control block */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* posix internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID posix_do_pthread_delete(POSIX_TCB *pthread_ptr, VOID *value_ptr)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
POSIX_TCB *joined_pthread_ptr;
|
||||
TX_THREAD *thread_ptr,*thread1_ptr;
|
||||
pthread_t joined_pthread_ID;
|
||||
ULONG status;
|
||||
|
||||
TX_DISABLE
|
||||
/* preserve the thread's return value regardless */
|
||||
pthread_ptr->value_ptr = value_ptr;
|
||||
|
||||
if ( pthread_ptr->is_joined_by == TX_TRUE)
|
||||
{
|
||||
joined_pthread_ID = pthread_ptr->joined_by_pthreadID ;
|
||||
joined_pthread_ptr = posix_tid2tcb(joined_pthread_ID);
|
||||
|
||||
joined_pthread_ptr->is_joined_to = TX_FALSE;
|
||||
joined_pthread_ptr->joined_to_pthreadID =TX_FALSE;
|
||||
|
||||
thread_ptr = (TX_THREAD *)joined_pthread_ptr;
|
||||
|
||||
/* Now resume the suspended pthread joined to this pthread */
|
||||
tx_thread_resume(thread_ptr);
|
||||
}
|
||||
/* Terminate the pthread's ThreadX thread. */
|
||||
thread1_ptr = posix_tcb2thread(pthread_ptr);
|
||||
status = tx_thread_terminate(thread1_ptr);
|
||||
if (status != TX_SUCCESS)
|
||||
{
|
||||
posix_internal_error(2244);
|
||||
}
|
||||
|
||||
/* Delete the pthread's ThreadX thread. */
|
||||
status = tx_thread_delete(&(pthread_ptr->thread_info));
|
||||
if (status != TX_SUCCESS)
|
||||
{
|
||||
posix_internal_error(2255);
|
||||
}
|
||||
/* Free the memory allocated for pthread's stack allocated from the posix heap */
|
||||
/* if the memory was not from the posix heap this call has no effect */
|
||||
/* it will be the user's responsibility to manage such memory */
|
||||
|
||||
posix_memory_release(pthread_ptr->stack_address);
|
||||
|
||||
/* Determine if this thread is NOT a signal handler thread. If this is the case,
|
||||
delete the event flag group. */
|
||||
if (pthread_ptr -> signals.signal_handler == FALSE)
|
||||
{
|
||||
|
||||
/* Delete the event flag group. */
|
||||
tx_event_flags_delete(&(pthread_ptr -> signals.signal_event_flags));
|
||||
}
|
||||
|
||||
/* Return the pthread's TCB to the pool of available TCB's. */
|
||||
pthread_ptr->in_use = TX_FALSE;
|
||||
|
||||
TX_RESTORE
|
||||
|
||||
/* All done. */
|
||||
return;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_set_pthread_errno PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function sets the pthread error number. */
|
||||
/* Each pthread has got its very own erron number. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* errno_set error number to set */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* OK Always return successful */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_thread_identify get calling ThreadX thread */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* posix internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT posix_set_pthread_errno(ULONG errno_set)
|
||||
{
|
||||
|
||||
TX_THREAD *thread_ptr;
|
||||
POSIX_TCB *pthread_ptr;
|
||||
|
||||
/* Get the thread identifier of the currently running thread */
|
||||
thread_ptr = tx_thread_identify();
|
||||
/* get posix TCB for this pthread */
|
||||
pthread_ptr = (POSIX_TCB *)thread_ptr;
|
||||
/* Set the error number */
|
||||
pthread_ptr->perrno = errno_set;
|
||||
|
||||
/* Always return success!*/
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* posix_get_pthread_errno PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function gets the erron number for a pthread. */
|
||||
/* Each pthread has got its very own erron number. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* ptid pthread id */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* error_number error number for the pthread */
|
||||
/* ERROR In case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* tx_thread_identify get calling ThreadX thread */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* posix internal code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT posix_get_pthread_errno(pthread_t ptid)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
INT error_number;
|
||||
POSIX_TCB *pthread_ptr;
|
||||
|
||||
TX_DISABLE
|
||||
|
||||
/* Get the POSIX pthread structure pointer for the ptid */
|
||||
pthread_ptr = posix_tid2tcb(ptid);
|
||||
/* Check whether we got NULL pointer */
|
||||
if (pthread_ptr)
|
||||
/* Retrive the stored error number for this pthread */
|
||||
error_number = pthread_ptr->perrno;
|
||||
else
|
||||
error_number = ERROR;
|
||||
|
||||
TX_RESTORE
|
||||
return(error_number);
|
||||
}
|
||||
185
utility/rtos_compatibility_layers/posix/px_pth_join.c
Normal file
185
utility/rtos_compatibility_layers/posix/px_pth_join.c
Normal file
@@ -0,0 +1,185 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_join PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall suspend execution of the calling thread until */
|
||||
/* the target thread terminates, unless the target thread has already */
|
||||
/* terminated. On return from a successful pthread_join ( ) call with */
|
||||
/* a non-NULL value_ptr argument, the value passed to pthread_exit( ) */
|
||||
/* by the terminating thread shall be made available in the location */
|
||||
/* referenced by value_ptr. When a pthread_join returns successfully, */
|
||||
/* the target thread has been terminated. The results of multiple */
|
||||
/* simultaneous calls to pthread_join specifying the same target thread*/
|
||||
/* are undefined. If the thread calling pthread_join is canceled, then */
|
||||
/* the target thread shall not be detached. */
|
||||
/* Eventually, you should call pthread_join() or pthread_detach() for */
|
||||
/* every thread that is created joinable (with a detachstate of */
|
||||
/* PTHREAD_CREATE_JOINABLE)so that the system can reclaim all resources*/
|
||||
/* associated with the thread. Failure to join to or detach joinable */
|
||||
/* threads will result in memory and other resource leaks until the */
|
||||
/* process ends. If thread doesn't represent a valid undetached thread,*/
|
||||
/* pthread_detach() will return ESRCH. */
|
||||
/* */
|
||||
/* Note: this function must be called from a POSIX context; if it is */
|
||||
/* called from ThreadX context an error is returned. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread pthread handle to the target thread */
|
||||
/* value_ptr To receive return value of terminating */
|
||||
/* thread */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* zero If successful */
|
||||
/* error number If fails */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_join(pthread_t thread, VOID **value_ptr)
|
||||
|
||||
{
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
POSIX_TCB *current_ptr, *target_ptr;
|
||||
TX_THREAD *target_thread;
|
||||
|
||||
|
||||
/* Get the TCB for the currently running pthread */
|
||||
current_ptr = posix_thread2tcb(tx_thread_identify());
|
||||
|
||||
/* Make sure that a TCB was returned. */
|
||||
if (!current_ptr)
|
||||
{
|
||||
posix_errno = ECANCELED;
|
||||
posix_set_pthread_errno(ECANCELED);
|
||||
return(ECANCELED);
|
||||
}
|
||||
|
||||
/* Check trying to join to self ! */
|
||||
if ( current_ptr->pthreadID == thread)
|
||||
{
|
||||
posix_errno= EDEADLK;
|
||||
posix_set_pthread_errno(EDEADLK);
|
||||
return(EDEADLK);
|
||||
}
|
||||
/* Check if calling thread is already joined to other thread */
|
||||
|
||||
if ( current_ptr->is_joined_to == TX_TRUE)
|
||||
{
|
||||
posix_errno= EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
/* Sure, calling pthread can be joined to target pthread */
|
||||
|
||||
target_thread = posix_tid2thread(thread);
|
||||
|
||||
if (!target_thread)
|
||||
{
|
||||
/* Invalid target pthread object */
|
||||
posix_errno= ESRCH;
|
||||
posix_set_pthread_errno(ESRCH);
|
||||
return(ESRCH);
|
||||
}
|
||||
|
||||
if ( (target_thread->tx_thread_state == TX_COMPLETED) || (target_thread->tx_thread_state == TX_TERMINATED) )
|
||||
{
|
||||
/* but target pthread is already terminated */
|
||||
/* return the return value of the terminated thread */
|
||||
target_ptr = posix_tid2tcb(thread);
|
||||
if(value_ptr)*value_ptr = target_ptr->value_ptr;
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/* Now check the target thread, whether it is already joined to any other thread? */
|
||||
target_ptr = posix_tid2tcb(thread);
|
||||
|
||||
/* Now check the target thread, whether it is already joined to any other thread? */
|
||||
if (target_ptr->is_joined_by == TX_TRUE)
|
||||
{
|
||||
/* but target pthread is already terminated */
|
||||
posix_errno= EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
/* check joinability of target thread */
|
||||
if ( target_ptr->detach_state != PTHREAD_CREATE_JOINABLE)
|
||||
{
|
||||
posix_errno= EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
/* Now it is Okay to join */
|
||||
|
||||
TX_DISABLE
|
||||
|
||||
/* declare that this calling pthread is joined to other pthread */
|
||||
current_ptr->is_joined_to = TX_TRUE;
|
||||
/* register the target pthread */
|
||||
current_ptr->joined_to_pthreadID = thread;
|
||||
/* declare that the target pthread is joined by calling pthread */
|
||||
target_ptr->is_joined_by = TX_TRUE;
|
||||
/* and register the caller pthread with target pthread */
|
||||
target_ptr->joined_by_pthreadID = current_ptr->pthreadID ;
|
||||
|
||||
TX_RESTORE
|
||||
|
||||
/* Now calling pthread will suspend itself and wait till target pthread exits */
|
||||
tx_thread_suspend ( &(current_ptr->thread_info));
|
||||
/* target pthread exited and thus current pthread will resume now */
|
||||
/* store return value if value_ptr is valid */
|
||||
if(value_ptr)*value_ptr = target_ptr->value_ptr;
|
||||
return(OK);
|
||||
}
|
||||
327
utility/rtos_compatibility_layers/posix/px_pth_kill.c
Normal file
327
utility/rtos_compatibility_layers/posix/px_pth_kill.c
Normal file
@@ -0,0 +1,327 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
#include "tx_thread.h" /* Internal ThreadX thread management. */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_kill PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function is used to request that a signal be delivered to */
|
||||
/* the specified thread. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread_id Thread ID */
|
||||
/* sig Signal */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_in_thread_context Make sure caller is thread */
|
||||
/* posix_internal_error Generic error Handler */
|
||||
/* tx_event_flags_set */
|
||||
/* posix_memory_allocate Create a byte pool for stack */
|
||||
/* tx_thread_create */
|
||||
/* tx_event_flags_delete */
|
||||
/* posix_memory_release */
|
||||
/* tx_thread_suspend */
|
||||
/* _tx_thread_system_preempt_check */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
int pthread_kill(ULONG thread_id, int sig)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
POSIX_TCB *target_thread;
|
||||
POSIX_TCB *new_signal_thread;
|
||||
VOID (*handler)(int);
|
||||
INT status;
|
||||
UINT retval;
|
||||
|
||||
|
||||
/* Make sure we're calling this routine from a thread context. */
|
||||
if (!posix_in_thread_context())
|
||||
{
|
||||
/* return POSIX error. */
|
||||
posix_internal_error(444);
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Determine if the desired signal is valid. */
|
||||
if ((sig < 0) || (sig > SIGRTMAX))
|
||||
{
|
||||
|
||||
/* Return an error. */
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Pickup target thread. */
|
||||
target_thread = (POSIX_TCB *) thread_id;
|
||||
|
||||
/* Is it non-NULL? */
|
||||
if (!target_thread)
|
||||
{
|
||||
|
||||
/* Invalid target pthread object */
|
||||
posix_errno= ESRCH;
|
||||
posix_set_pthread_errno(ESRCH);
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Pickup signal handler function pointer. */
|
||||
handler = target_thread -> signals.signal_func[sig];
|
||||
|
||||
/* See if there is a signal handler setup for this signal. */
|
||||
if (!handler)
|
||||
{
|
||||
|
||||
/* No handler, just set/clear the event flags to handle the sigwait condition. */
|
||||
|
||||
/* Set the event flag corresponding the signal. */
|
||||
tx_event_flags_set(&(target_thread -> signals.signal_event_flags), (((ULONG) 1) << sig), TX_OR);
|
||||
|
||||
/* Ensure the flag is left in a clear state. */
|
||||
tx_event_flags_set(&(target_thread -> signals.signal_event_flags), ~(((ULONG) 1) << sig), TX_AND);
|
||||
|
||||
/* We are done, just return success. */
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/* Now, let's look to see if the same signal is already pending. */
|
||||
if (target_thread -> signals.signal_pending.signal_set & (((unsigned long) 1) << sig))
|
||||
{
|
||||
|
||||
/* Yes, the same signal is already pending, just return. */
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/* Now determine if the thread's signals are masked by pthread_sigmask. */
|
||||
if (target_thread -> signals.signal_mask.signal_set & (((unsigned long) 1) << sig))
|
||||
{
|
||||
|
||||
/* Yes, simply set the pending bit so we know that the signal must be activated later when the
|
||||
signal mask for this signal is cleared. */
|
||||
target_thread -> signals.signal_pending.signal_set = target_thread -> signals.signal_pending.signal_set | (((unsigned long) 1) << sig);
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/* At this point we know that we need to create a new signal handler thread for processing this signal. */
|
||||
|
||||
/* Get a pthread control block for this new signal pthread */
|
||||
|
||||
/* Disable interrupts for protection. */
|
||||
TX_DISABLE
|
||||
|
||||
/* Disable preemption temporarily. */
|
||||
_tx_thread_preempt_disable++;
|
||||
|
||||
/* Allocate a POSIX thread control block. */
|
||||
status = posix_allocate_pthread_t(&new_signal_thread);
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Make sure we got a new thread control block */
|
||||
if ((status == ERROR) || (!new_signal_thread))
|
||||
{
|
||||
|
||||
/* Disable interrupts. */
|
||||
TX_DISABLE
|
||||
|
||||
/* Enable preemption. */
|
||||
_tx_thread_preempt_disable--;
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Configuration/resource error. */
|
||||
posix_set_pthread_errno(EAGAIN);
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Inherit the stack size for the new signal thread. */
|
||||
new_signal_thread -> stack_size = target_thread -> stack_size ;
|
||||
|
||||
/* Allocate memory for stack. */
|
||||
status = posix_memory_allocate(new_signal_thread -> stack_size, &new_signal_thread -> stack_address);
|
||||
|
||||
/* problem allocating stack space */
|
||||
if ((status == ERROR))
|
||||
{
|
||||
|
||||
/* Mark the previously allocated control block as available. */
|
||||
new_signal_thread -> in_use = FALSE;
|
||||
|
||||
/* Disable interrupts. */
|
||||
TX_DISABLE
|
||||
|
||||
/* Enable preemption. */
|
||||
_tx_thread_preempt_disable--;
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Configuration/resource error. */
|
||||
posix_set_pthread_errno(EAGAIN);
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Inherit scheduling attributes from base thread. */
|
||||
new_signal_thread -> current_priority = target_thread -> current_priority ;
|
||||
new_signal_thread -> detach_state = target_thread -> detach_state ;
|
||||
new_signal_thread -> inherit_sched = target_thread -> inherit_sched ;
|
||||
new_signal_thread -> orig_priority = target_thread -> orig_priority ;
|
||||
new_signal_thread -> sched_attr.sched_priority= target_thread -> sched_attr.sched_priority ;
|
||||
new_signal_thread -> pthread_flags = target_thread -> pthread_flags ;
|
||||
new_signal_thread -> sched_policy = target_thread -> sched_policy;
|
||||
new_signal_thread -> is_joined_by = TX_FALSE;
|
||||
new_signal_thread -> joined_by_pthreadID = TX_FALSE;
|
||||
new_signal_thread -> is_joined_to = TX_FALSE;
|
||||
new_signal_thread -> joined_to_pthreadID = TX_FALSE;
|
||||
new_signal_thread -> cancel_state = PTHREAD_CANCEL_ENABLE;
|
||||
new_signal_thread -> cancel_type = PTHREAD_CANCEL_DEFERRED;
|
||||
new_signal_thread -> cancel_request = FALSE;
|
||||
new_signal_thread -> value_ptr = NULL;
|
||||
|
||||
/* Increment the target thread's signal nesting depth. */
|
||||
target_thread -> signals.signal_nesting_depth++;
|
||||
|
||||
/* Mark this signal as pending in the signal set. */
|
||||
target_thread -> signals.signal_pending.signal_set = target_thread -> signals.signal_pending.signal_set | (((unsigned long) 1) << sig);
|
||||
|
||||
/* Mark the new thread as a signal thread, clear signal info, and setup links. */
|
||||
new_signal_thread -> signals.signal_handler = TRUE;
|
||||
new_signal_thread -> signals.signal_nesting_depth = target_thread -> signals.signal_nesting_depth;
|
||||
new_signal_thread -> signals.signal_pending.signal_set = target_thread -> signals.signal_pending.signal_set;
|
||||
new_signal_thread -> signals.saved_thread_state = ((TX_THREAD *) target_thread) -> tx_thread_state;
|
||||
new_signal_thread -> signals.base_thread_ptr = target_thread;
|
||||
new_signal_thread -> signals.next_signal_thread = target_thread -> signals.top_signal_thread;
|
||||
|
||||
/* Remember the top signal thread in the base thread. */
|
||||
target_thread -> signals.top_signal_thread = new_signal_thread;
|
||||
|
||||
/* Now actually create and start the signal thread. */
|
||||
retval = tx_thread_create( (TX_THREAD *) new_signal_thread,
|
||||
"signal pthr",
|
||||
internal_signal_dispatch,
|
||||
(ULONG) sig,
|
||||
new_signal_thread -> stack_address,
|
||||
new_signal_thread -> stack_size,
|
||||
(TX_LOWEST_PRIORITY - new_signal_thread -> current_priority + 1),
|
||||
(TX_LOWEST_PRIORITY - new_signal_thread -> current_priority + 1),
|
||||
new_signal_thread -> time_slice,
|
||||
TX_AUTO_START);
|
||||
|
||||
/* See if ThreadX encountered an error */
|
||||
if (retval)
|
||||
{
|
||||
|
||||
/* Create an event flags group. */
|
||||
tx_event_flags_delete(&(new_signal_thread -> signals.signal_event_flags));
|
||||
|
||||
/* Release the stack memory. */
|
||||
posix_memory_release(new_signal_thread -> stack_address);
|
||||
|
||||
/* Mark the previously allocated control block as available. */
|
||||
new_signal_thread -> in_use = FALSE;
|
||||
|
||||
/* Disable interrupts. */
|
||||
TX_DISABLE
|
||||
|
||||
/* Enable preemption. */
|
||||
_tx_thread_preempt_disable--;
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Internal error */
|
||||
posix_error_handler(3333);
|
||||
posix_set_pthread_errno(EACCES);
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
/* Disable interrupts. */
|
||||
TX_DISABLE
|
||||
|
||||
/* Enable preemption. */
|
||||
_tx_thread_preempt_disable--;
|
||||
|
||||
/* At this point, we need to suspend the target thread if we are the first signal handler to run. */
|
||||
if (new_signal_thread -> signals.signal_nesting_depth == 1)
|
||||
{
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Suspend the base thread so that it doesn't run again until all the signals have been processed. */
|
||||
tx_thread_suspend((TX_THREAD *) target_thread);
|
||||
}
|
||||
else if (new_signal_thread -> signals.next_signal_thread)
|
||||
{
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Make sure the current top level signal handler thread is suspended. */
|
||||
tx_thread_suspend((TX_THREAD *) new_signal_thread -> signals.next_signal_thread);
|
||||
}
|
||||
|
||||
/* At this point, the new signal has been set and the signal handler is ready for execution. */
|
||||
|
||||
/* Check for a preemption condition. */
|
||||
_tx_thread_system_preempt_check();
|
||||
|
||||
/* Return success! */
|
||||
return(OK);
|
||||
}
|
||||
121
utility/rtos_compatibility_layers/posix/px_pth_once.c
Normal file
121
utility/rtos_compatibility_layers/posix/px_pth_once.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_once PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* The pthread_once function shall call the init_routine with no */
|
||||
/* arguments. Subsequent calls of pthread_once() with the same */
|
||||
/* once_control shall not call the init_routine. On return from */
|
||||
/* pthread_once(), init_routine shall have completed. The */
|
||||
/* once_control parameter shall determine whether the associated */
|
||||
/* initialization routine has been called. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* once_control */
|
||||
/* init_routine */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* zero If successful */
|
||||
/* error number If fails */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* tx_thread_preemption_change */
|
||||
/* tx_event_flags_create */
|
||||
/* tx_event_flags_set */
|
||||
/* tx_event_flags_get */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_once (pthread_once_t * once_control, VOID (*init_routine) (VOID))
|
||||
{
|
||||
|
||||
INT result;
|
||||
UINT old_treshold, temp;
|
||||
|
||||
if (once_control == NULL || init_routine == NULL)
|
||||
{
|
||||
result = EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( once_control->state==PTH_ONCE_DONE)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
|
||||
/* suspend preemption */
|
||||
tx_thread_preemption_change( tx_thread_identify(), 0, &old_treshold);
|
||||
|
||||
if (once_control->state==PTH_ONCE_INIT)
|
||||
{
|
||||
once_control->state=PTH_ONCE_STARTED;
|
||||
tx_event_flags_create(&(once_control->event),"once flags");
|
||||
|
||||
/* enable preemption */
|
||||
tx_thread_preemption_change( tx_thread_identify(),old_treshold, &temp);
|
||||
(*init_routine)();
|
||||
|
||||
tx_event_flags_set(&(once_control->event), PTH_ONCE_INIT, TX_AND);
|
||||
|
||||
once_control->state=PTH_ONCE_DONE;
|
||||
}
|
||||
|
||||
/* enable preemption */
|
||||
tx_thread_preemption_change( tx_thread_identify(),old_treshold, &temp);
|
||||
|
||||
if (once_control->state==PTH_ONCE_STARTED)
|
||||
{
|
||||
tx_event_flags_get(&(once_control->event), PTH_ONCE_INIT, TX_AND, &(once_control->flags) ,TX_WAIT_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
/* note: this routine will not handle the case where the init routine is a cancellation point */
|
||||
return (result);
|
||||
}
|
||||
94
utility/rtos_compatibility_layers/posix/px_pth_self.c
Normal file
94
utility/rtos_compatibility_layers/posix/px_pth_self.c
Normal file
@@ -0,0 +1,94 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_self PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* */
|
||||
/* This function returns thread ID of the calling pthread . */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* Nothing */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* thread_ID pthread handle of the calling thread */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
pthread_t pthread_self(VOID)
|
||||
{
|
||||
|
||||
TX_THREAD *thread_ptr;
|
||||
pthread_t thread_ID;
|
||||
|
||||
/* Get the thread identifier of the currently running thread */
|
||||
thread_ptr = tx_thread_identify();
|
||||
|
||||
/* Convert thread identifier to posix thread ID */
|
||||
|
||||
thread_ID = posix_thread2tid(thread_ptr);
|
||||
|
||||
/* Determine if this thread is actually the signal thread helper. */
|
||||
if (((POSIX_TCB *) thread_ptr) -> signals.signal_handler)
|
||||
{
|
||||
|
||||
/* Yes, override the thread_ID with the non-signal thread ID. */
|
||||
thread_ID = (pthread_t) ((POSIX_TCB *) thread_ptr) -> signals.base_thread_ptr;
|
||||
}
|
||||
|
||||
|
||||
/* All done. */
|
||||
return(thread_ID);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* set_default_pthread_attr PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function sets default pthread attr w/ default information. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* attr pthread attr object pointer */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Start-up code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID set_default_pthread_attr(pthread_attr_t *attr)
|
||||
{
|
||||
attr->detach_state =PTHREAD_CREATE_JOINABLE;
|
||||
attr->inherit_sched =0;
|
||||
attr->inuse =TX_TRUE;
|
||||
attr->pthread_flags =0;
|
||||
attr->sched_attr.sched_priority =31;
|
||||
attr->sched_policy =0;
|
||||
attr->stack_address =0;
|
||||
attr->stack_size = TX_DEFAULT_THREAD_STACK_SIZE;
|
||||
}
|
||||
103
utility/rtos_compatibility_layers/posix/px_pth_setcancelstate.c
Normal file
103
utility/rtos_compatibility_layers/posix/px_pth_setcancelstate.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_setcancelstate PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* The pthread_setcancelstate()function shall atomically both set the */
|
||||
/* calling thread<61>s cancelability state to the indicated state and */
|
||||
/* return the previous cancelability state at the location referenced */
|
||||
/* by oldstate.Legal values for state are PTHREAD_CANCEL_ENABLE and */
|
||||
/* PTHREAD_CANCEL_DISABLE. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* state New cancelability state to be set */
|
||||
/* oldstate Pointer to old cancelability state */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_setcancelstate (INT state, INT *oldstate)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
TX_THREAD *thread_ptr;
|
||||
POSIX_TCB *pthread_ptr;
|
||||
|
||||
/* First check for validity of the new cancel state to be set */
|
||||
if ( (state == PTHREAD_CANCEL_ENABLE) || (state == PTHREAD_CANCEL_DISABLE) )
|
||||
{
|
||||
TX_DISABLE
|
||||
|
||||
/* Get the thread identifier of the currently running thread */
|
||||
thread_ptr = tx_thread_identify();
|
||||
/* get posix TCB for this pthread */
|
||||
pthread_ptr = (POSIX_TCB *)thread_ptr;
|
||||
*oldstate = pthread_ptr->cancel_state;
|
||||
pthread_ptr->cancel_state = state;
|
||||
|
||||
TX_RESTORE
|
||||
|
||||
return(OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return (EINVAL);
|
||||
}
|
||||
}
|
||||
102
utility/rtos_compatibility_layers/posix/px_pth_setcanceltype.c
Normal file
102
utility/rtos_compatibility_layers/posix/px_pth_setcanceltype.c
Normal file
@@ -0,0 +1,102 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_setcanceltype PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* The pthread_setcancelstate()function shall atomically both get the */
|
||||
/* calling thread's cancelability type to the indicated type and */
|
||||
/* return the previous cancelability type at the location referenced */
|
||||
/* by oldtype. Legal values for type are PTHREAD_CANCEL_DEFERRED and */
|
||||
/* PTHREAD_CANCEL_ASYNCHRONOUS. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* type New cancelability type to be set */
|
||||
/* oldtype Pointer to old cancelability type */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_setcanceltype (INT type, INT *oldtype)
|
||||
{
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
TX_THREAD *thread_ptr;
|
||||
POSIX_TCB *pthread_ptr;
|
||||
|
||||
/* First check for validity of the new cancel type to be set */
|
||||
if ( ( type == PTHREAD_CANCEL_DEFERRED ) || ( type == PTHREAD_CANCEL_ASYNCHRONOUS ) )
|
||||
{
|
||||
TX_DISABLE
|
||||
|
||||
/* Get the thread identifier of the currently running thread */
|
||||
thread_ptr = tx_thread_identify();
|
||||
/* get posix TCB for this pthread */
|
||||
pthread_ptr = (POSIX_TCB *)thread_ptr;
|
||||
*oldtype = pthread_ptr->cancel_type;
|
||||
pthread_ptr->cancel_type = type;
|
||||
|
||||
TX_RESTORE
|
||||
|
||||
return(OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
posix_errno = EINVAL;
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
}
|
||||
120
utility/rtos_compatibility_layers/posix/px_pth_setschedparam.c
Normal file
120
utility/rtos_compatibility_layers/posix/px_pth_setschedparam.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_setschedparam PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function changes the scheduling parameters of a pthread. */
|
||||
/* */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread POSIX thread ID */
|
||||
/* policy Address of the thread attributes */
|
||||
/* sched_param Address of structure to contain the */
|
||||
/* returned scheduling parameters */
|
||||
/* */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* 0 if successful */
|
||||
/* Value in case of any error */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_tid2tcb */
|
||||
/* posix_tcb2thread */
|
||||
/* tx_thread_priority_change */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
INT pthread_setschedparam(pthread_t thread, INT policy, const struct sched_param *param)
|
||||
{
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
POSIX_TCB *thread_tcb;
|
||||
TX_THREAD *TheThread;
|
||||
UINT Tmp;
|
||||
ULONG UTmp;
|
||||
|
||||
|
||||
|
||||
thread_tcb=posix_tid2tcb(thread);
|
||||
|
||||
if(thread_tcb==NULL)
|
||||
{
|
||||
return(ESRCH);
|
||||
}
|
||||
if (!(( policy == SCHED_FIFO )||(policy== SCHED_RR)))
|
||||
{
|
||||
return(ENOTSUP);
|
||||
}
|
||||
|
||||
|
||||
TX_DISABLE
|
||||
thread_tcb->sched_policy=policy;
|
||||
thread_tcb->sched_attr.sched_priority=param->sched_priority;
|
||||
thread_tcb->current_priority= param->sched_priority;
|
||||
|
||||
TheThread=posix_tcb2thread(thread_tcb);
|
||||
|
||||
tx_thread_priority_change(TheThread, (TX_LOWEST_PRIORITY - thread_tcb->current_priority + 1),&Tmp);
|
||||
thread_tcb->orig_priority=(ULONG) Tmp;
|
||||
|
||||
if(policy==SCHED_RR) thread_tcb->time_slice=SCHED_RR_TIME_SLICE;
|
||||
else thread_tcb->time_slice=0;
|
||||
tx_thread_time_slice_change(TheThread, thread_tcb->time_slice, &UTmp);
|
||||
|
||||
TX_RESTORE
|
||||
|
||||
return(NO_ERROR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
228
utility/rtos_compatibility_layers/posix/px_pth_sigmask.c
Normal file
228
utility/rtos_compatibility_layers/posix/px_pth_sigmask.c
Normal file
@@ -0,0 +1,228 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
#include "tx_thread.h" /* Internal ThreadX thread management. */
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_sigmask PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function shall examine or change (or both) the calling */
|
||||
/* thread's signal mask. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* how how the set will be changed */
|
||||
/* newmask pointer to new set of signals */
|
||||
/* oldmask pointer to store previous signals */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* OK If successful */
|
||||
/* EINVAL If error occurs */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_set_pthread_errno */
|
||||
/* tx_thread_identify */
|
||||
/* pthread_kill */
|
||||
/* _tx_thread_system_preempt_check */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
int pthread_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask)
|
||||
{
|
||||
|
||||
TX_INTERRUPT_SAVE_AREA
|
||||
|
||||
ULONG blocked_signals;
|
||||
ULONG released_signals;
|
||||
ULONG signal_number;
|
||||
ULONG previous_mask;
|
||||
POSIX_TCB *base_thread;
|
||||
ULONG reissue_flag;
|
||||
|
||||
|
||||
/* Check for a valid how parameter. */
|
||||
if ((how != SIG_BLOCK) && (how != SIG_SETMASK) & (how != SIG_UNBLOCK))
|
||||
{
|
||||
|
||||
/* Return an error. */
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
/* Check for valid signal masks. */
|
||||
if ((newmask == NULL) || (oldmask == NULL))
|
||||
{
|
||||
|
||||
/* Return an error. */
|
||||
posix_set_pthread_errno(EINVAL);
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
/* Pickup base thread, since the base thread and all signal threads will pend off the same
|
||||
event flag group. */
|
||||
base_thread = (POSIX_TCB *) tx_thread_identify();
|
||||
|
||||
/* Is it non-NULL? */
|
||||
if (!base_thread)
|
||||
{
|
||||
|
||||
/* System error! */
|
||||
posix_set_pthread_errno(ESRCH);
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
/* Determine if the current thread is a signal handler thread. */
|
||||
if (base_thread -> signals.signal_handler)
|
||||
{
|
||||
|
||||
/* Pickup target thread. */
|
||||
base_thread = base_thread -> signals.base_thread_ptr;
|
||||
}
|
||||
|
||||
/* Save the current signal mask for return. */
|
||||
previous_mask = base_thread -> signals.signal_mask.signal_set;
|
||||
|
||||
/* Now process based on how the mask is to be changed. */
|
||||
if (how == SIG_BLOCK)
|
||||
{
|
||||
|
||||
/* Simply set the mask to block the signal(s). */
|
||||
base_thread -> signals.signal_mask.signal_set = base_thread -> signals.signal_mask.signal_set | newmask -> signal_set;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Now calculate the set of currently pending signals there are waiting based on the current mask. */
|
||||
blocked_signals = base_thread -> signals.signal_mask.signal_set & base_thread -> signals.signal_pending.signal_set;
|
||||
|
||||
/* Now modify the singal mask correspondingly. */
|
||||
if (how == SIG_UNBLOCK)
|
||||
{
|
||||
|
||||
/* Clear only the signals specified in the new signal mask. */
|
||||
base_thread -> signals.signal_mask.signal_set = base_thread -> signals.signal_mask.signal_set & ~(newmask -> signal_set);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Simply set the signal mask to the new signal mask value. */
|
||||
base_thread -> signals.signal_mask.signal_set = newmask -> signal_set;
|
||||
}
|
||||
|
||||
/* Now determine if there are any signals that need to be activated. */
|
||||
released_signals = blocked_signals & ~(base_thread -> signals.signal_mask.signal_set);
|
||||
|
||||
/* Are there any signals that need to be activated? */
|
||||
if (released_signals)
|
||||
{
|
||||
|
||||
/* Temporarily disable interrupts. */
|
||||
TX_DISABLE
|
||||
|
||||
/* Temporarily disable preemption. */
|
||||
_tx_thread_preempt_disable++;
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Set the reissue flag to false. */
|
||||
reissue_flag = TX_FALSE;
|
||||
|
||||
/* Loop to process all the blocked signals. */
|
||||
signal_number = 0;
|
||||
while ((released_signals) && (signal_number < 32))
|
||||
{
|
||||
|
||||
/* Determine if this signal was released. */
|
||||
if (released_signals & 1)
|
||||
{
|
||||
|
||||
/* Yes, this signal was released. We need to make it active again. */
|
||||
|
||||
/* Clear the pending bit so the pthread_kill call will not discard the signal (signals are not queued in this implementation). */
|
||||
base_thread -> signals.signal_pending.signal_set = base_thread -> signals.signal_pending.signal_set & ~(((unsigned long) 1) << signal_number);
|
||||
|
||||
/* Call pthread_kill to reissue the signal. */
|
||||
pthread_kill((ULONG) base_thread, signal_number);
|
||||
|
||||
/* Set the reissue flag. */
|
||||
reissue_flag = TX_TRUE;
|
||||
}
|
||||
|
||||
/* Look for next signal. */
|
||||
released_signals = released_signals >> 1;
|
||||
signal_number++;
|
||||
}
|
||||
|
||||
/* Temporarily disable interrupts. */
|
||||
TX_DISABLE
|
||||
|
||||
/* Release preemption. */
|
||||
_tx_thread_preempt_disable--;
|
||||
|
||||
/* Restore interrupts. */
|
||||
TX_RESTORE
|
||||
|
||||
/* Check for a preemption condition. */
|
||||
_tx_thread_system_preempt_check();
|
||||
|
||||
/* Determine if the reissue flag is set. */
|
||||
if (reissue_flag == TX_TRUE)
|
||||
{
|
||||
|
||||
/* Relinquish to allow signal thread at same priority to run before we return. */
|
||||
_tx_thread_relinquish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Setup return mask. */
|
||||
oldmask -> signal_set = previous_mask;
|
||||
|
||||
return(OK);
|
||||
}
|
||||
92
utility/rtos_compatibility_layers/posix/px_pth_testcancel.c
Normal file
92
utility/rtos_compatibility_layers/posix/px_pth_testcancel.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_testcancel PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* The pthread_testcancel function shall request that thread be */
|
||||
/* canceled if the cancel state is enabled and cancel type is */
|
||||
/* deferred, and a cancellation request has happened in the past. */
|
||||
/* The target thread's cancelability state and type determines when */
|
||||
/* the cancellation takes effect. When the cancellation is acted on, */
|
||||
/* the cancelation cleanup handlers for thread shall be called. When */
|
||||
/* the last cancelation cleanup handler returns, the thread-specific */
|
||||
/* data destructor functions shall be called for thread. When the last */
|
||||
/* destructor function returns, thread shall be terminated. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread pthread handle to thread to be canceled */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* posix_destroy_thread */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID pthread_testcancel(VOID)
|
||||
{
|
||||
|
||||
POSIX_TCB *pthread_ptr;
|
||||
|
||||
|
||||
/* Get the thread identifier of the calling pthread */
|
||||
pthread_ptr = posix_tid2tcb(pthread_self());
|
||||
|
||||
/* Check if thread was created with cancel enable */
|
||||
if ( (pthread_ptr->cancel_state == PTHREAD_CANCEL_ENABLE) &&
|
||||
(pthread_ptr->cancel_type==PTHREAD_CANCEL_DEFERRED) &&
|
||||
(pthread_ptr->cancel_request==TRUE) )
|
||||
{
|
||||
|
||||
/* Signal the housekeeping ThreadX thread to cancel (delete) this pthread */
|
||||
posix_destroy_pthread(pthread_ptr,(VOID *)0);
|
||||
}
|
||||
}
|
||||
|
||||
82
utility/rtos_compatibility_layers/posix/px_pth_yield.c
Normal file
82
utility/rtos_compatibility_layers/posix/px_pth_yield.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
/* */
|
||||
/* This software is licensed under the Microsoft Software License */
|
||||
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
/* and in the root directory of this software. */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** POSIX wrapper for THREADX */
|
||||
/** */
|
||||
/** */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
/* Include necessary system files. */
|
||||
|
||||
#include "tx_api.h" /* Threadx API */
|
||||
#include "pthread.h" /* Posix API */
|
||||
#include "px_int.h" /* Posix helper functions */
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* pthread_yield PORTABLE C */
|
||||
/* 6.x */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* William E. Lamie, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This subroutine forces the calling thread to relinquish use of its */
|
||||
/* processor,and to wait in the run queue before it is scheduled again.*/
|
||||
/* If the run queue is empty when this subroutine is called, the */
|
||||
/* calling thread is immediately rescheduled. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* Nothing */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* posix_internal_error posix internal error function */
|
||||
/* tx_thread_relinquish ThreadX function */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* xx-xx-xxxx William E. Lamie Initial Version 6.x */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID pthread_yield(VOID)
|
||||
{
|
||||
/* Make sure we're calling this routine from a thread context. */
|
||||
if (!posix_in_thread_context())
|
||||
{
|
||||
/* return POSIX error. */
|
||||
posix_internal_error(444);
|
||||
}
|
||||
|
||||
/* This relinquishes the CPU. */
|
||||
tx_thread_relinquish();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user