Remove threadsafety code & List_clear() and List_maxLength(()

main
Hammy 3 years ago
parent 18860e2371
commit 1b500a4dfd

@ -55,10 +55,6 @@ int List_append(List *list, int element) {
} }
} }
// Beginning of Critical Section
pthread_mutex_lock(&(list->simpleMutex));
printf("\nMutex Locked!");
if (list->_currentSize + 1 == list->_maxSize) { if (list->_currentSize + 1 == list->_maxSize) {
list->_maxSize *= 2; list->_maxSize *= 2;
int *temp = realloc(list->_array, list->_maxSize * sizeof(int)); int *temp = realloc(list->_array, list->_maxSize * sizeof(int));
@ -69,10 +65,6 @@ int List_append(List *list, int element) {
} }
list->_array[++list->_currentSize] = element; list->_array[++list->_currentSize] = element;
// End of Critical Section
pthread_mutex_unlock(&(list->simpleMutex));
printf("\nMutex Unlocked!");
return 0; return 0;
} }
@ -178,6 +170,19 @@ List *List_copy(List *list) {
return listCopy; return listCopy;
} }
int List_clear(List *list) {
if (!list) {
return 1;
}
for (int i = 0; i < list->_currentSize + 1; i++) {
list->_array[i] = 0;
}
list->_currentSize = -1;
return 0;
}
List *List_slice(List *list, int start_index, int end_index) { List *List_slice(List *list, int start_index, int end_index) {
if (start_index >= end_index) { if (start_index >= end_index) {
return NULL; return NULL;
@ -203,11 +208,11 @@ int List_length(List *list) {
return list->_currentSize + 1; return list->_currentSize + 1;
} }
void List_print(List *list) { int List_maxLength(List *list) {
return list->_maxSize;
// Beginning Of Critical Section }
pthread_mutex_lock(&(list->simpleMutex));
void List_print(List *list) {
printf("["); printf("[");
for (int i = 0; i < list->_currentSize + 1; i++) { for (int i = 0; i < list->_currentSize + 1; i++) {
if (i == list->_currentSize) { if (i == list->_currentSize) {
@ -217,9 +222,6 @@ void List_print(List *list) {
} }
} }
printf("]"); printf("]");
// End Of Critical Section
pthread_mutex_unlock(&(list->simpleMutex));
} }
void List_destroy(List **list) { void List_destroy(List **list) {

Loading…
Cancel
Save