| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 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 |
|
| 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 |
|
| 115 |
|
| 116 |
|
| 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 |
|
| 142 |
memory_free( |
| 143 |
internal_thread_attributes ); |
| 144 |
} |
| 145 |
return( result ); |
| 146 |
} |
| 147 |
|
| 148 |
#endif |
| 149 |
|