1 /*
2 * Thread attributes functions
3 *
4 * Copyright (C) 2012-2020, Joachim Metz <joachim.metz@gmail.com>
5 *
6 * Refer to AUTHORS for acknowledgements.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <common.h>
23 #include <memory.h>
24 #include <types.h>
25
26 #if defined( HAVE_PTHREAD_H ) && !defined( WINAPI )
27 #include <pthread.h>
28 #endif
29
30 #include "libcthreads_libcerror.h"
31 #include "libcthreads_thread_attributes.h"
32 #include "libcthreads_types.h"
33
34 #if !defined( HAVE_LOCAL_LIBCTHREADS ) || defined( HAVE_MULTI_THREAD_SUPPORT )
35
36 /* Creates thread attributes
37 * Make sure the value thread_attributes is referencing, is set to NULL
38 * Returns 1 if successful or -1 on error
39 */
libcthreads_thread_attributes_initialize(libcthreads_thread_attributes_t ** thread_attributes,libcerror_error_t ** error)40 int libcthreads_thread_attributes_initialize(
41 libcthreads_thread_attributes_t **thread_attributes,
42 libcerror_error_t **error )
43 {
44 libcthreads_internal_thread_attributes_t *internal_thread_attributes = NULL;
45 static char *function = "libcthreads_thread_attributes_initialize";
46
47 if( thread_attributes == NULL )
48 {
49 libcerror_error_set(
50 error,
51 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
52 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
53 "%s: invalid thread attributes.",
54 function );
55
56 return( -1 );
57 }
58 if( *thread_attributes != NULL )
59 {
60 libcerror_error_set(
61 error,
62 LIBCERROR_ERROR_DOMAIN_RUNTIME,
63 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
64 "%s: invalid thread attributes value already set.",
65 function );
66
67 return( -1 );
68 }
69 internal_thread_attributes = memory_allocate_structure(
70 libcthreads_internal_thread_attributes_t );
71
72 if( internal_thread_attributes == NULL )
73 {
74 libcerror_error_set(
75 error,
76 LIBCERROR_ERROR_DOMAIN_MEMORY,
77 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
78 "%s: unable to create thread attributes.",
79 function );
80
81 goto on_error;
82 }
83 if( memory_set(
84 internal_thread_attributes,
85 0,
86 sizeof( libcthreads_internal_thread_attributes_t ) ) == NULL )
87 {
88 libcerror_error_set(
89 error,
90 LIBCERROR_ERROR_DOMAIN_MEMORY,
91 LIBCERROR_MEMORY_ERROR_SET_FAILED,
92 "%s: unable to clear thread attributes.",
93 function );
94
95 memory_free(
96 internal_thread_attributes );
97
98 return( -1 );
99 }
100 /* TODO */
101 *thread_attributes = (libcthreads_thread_attributes_t *) internal_thread_attributes;
102
103 return( 1 );
104
105 on_error:
106 if( internal_thread_attributes != NULL )
107 {
108 memory_free(
109 internal_thread_attributes );
110 }
111 return( -1 );
112 }
113
114 /* Frees thread attributes
115 * Returns 1 if successful or -1 on error
116 */
libcthreads_thread_attributes_free(libcthreads_thread_attributes_t ** thread_attributes,libcerror_error_t ** error)117 int libcthreads_thread_attributes_free(
118 libcthreads_thread_attributes_t **thread_attributes,
119 libcerror_error_t **error )
120 {
121 libcthreads_internal_thread_attributes_t *internal_thread_attributes = NULL;
122 static char *function = "libcthreads_thread_attributes_free";
123 int result = 1;
124
125 if( thread_attributes == NULL )
126 {
127 libcerror_error_set(
128 error,
129 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
130 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
131 "%s: invalid thread attributes.",
132 function );
133
134 return( -1 );
135 }
136 if( *thread_attributes != NULL )
137 {
138 internal_thread_attributes = (libcthreads_internal_thread_attributes_t *) *thread_attributes;
139 *thread_attributes = NULL;
140
141 /* TODO */
142 memory_free(
143 internal_thread_attributes );
144 }
145 return( result );
146 }
147
148 #endif /* !defined( HAVE_LOCAL_LIBCTHREADS ) || defined( HAVE_MULTI_THREAD_SUPPORT ) */
149
150