blob: db4269d78617c215b098a3dfb2e29f617df7d4cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** 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.1.7 */
/* 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 */
/* */
/**************************************************************************/
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);
}
|