From 9e737f24abb04b550c8ac67c7344decd2c34aad1 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 23 Jun 2021 10:16:48 +0200 Subject: [PATCH] test and arrows --- include/arrows.h | 49 +++++++++++++++++++++++++++++++++++++++ src/tests/test_realloc | Bin 0 -> 16720 bytes src/tests/test_realloc.c | 13 +++++++++++ 3 files changed, 62 insertions(+) create mode 100644 include/arrows.h create mode 100755 src/tests/test_realloc create mode 100644 src/tests/test_realloc.c diff --git a/include/arrows.h b/include/arrows.h new file mode 100644 index 0000000..9689ffe --- /dev/null +++ b/include/arrows.h @@ -0,0 +1,49 @@ +//=-------------------------------------------------------------------------=// +// Local workers definition // +// // +// Copyright © 2021 The Gem-graph Project // +// // +// This file is part of gem-graph. // +// // +// This program is free software: you can redistribute it and/or modify // +// it under the terms of the GNU Affero General Public License as // +// published by the Free Software Foundation, either version 3 of the // +// License, or (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU Affero General Public License for more details. // +// // +// You should have received a copy of the GNU Affero General Public License // +// along with this program. If not, see . // +//=-------------------------------------------------------------------------=// + +#ifndef BASE_H + #include "../include/base.h" +#endif + +static inline int createArrowLock(ArrowArray_t *arrowArray) +{ + return pthread_spin_init(&arrowArray->lock, PTHREAD_PROCESS_SHARED); +} + +static inline int destroyArrowLock(ArrowArray_t *arrowArray) +{ + return pthread_spin_destroy(&arrowArray->lock); +} + +static inline int acquireArrowLock(ArrowArray_t *arrowArray) +{ + return pthread_spin_lock(&arrowArray->lock); +} + +static inline int acquireNonBlockinArrowgLock(ArrowArray_t *arrowArray) +{ + return pthread_spin_trylock(&arrowArray->lock); +} + +static inline int releaseArrowLock(ArrowArray_t *arrowArray) +{ + return pthread_spin_unlock(&arrowArray->lock); +} diff --git a/src/tests/test_realloc b/src/tests/test_realloc new file mode 100755 index 0000000000000000000000000000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y7Uf)T&(yzwbx+w literal 0 HcmV?d00001 diff --git a/src/tests/test_realloc.c b/src/tests/test_realloc.c new file mode 100644 index 0000000..1ddeab6 --- /dev/null +++ b/src/tests/test_realloc.c @@ -0,0 +1,13 @@ +#include +#include + +int main(void) +{ + int *a = (int*) malloc(7 * sizeof(int)); + + printf("Salut! Tableau d'entiers à l'adresse %p\n", a); + + int *b = (int*) realloc(a, 8*sizeof(int)); + + printf("Salut! Tableau d'entiers à l'adresse %p\n", b); +}