Commit f67ee680669fdade639d540df326f48176a3d0f3

Authored by Georg Hopp
1 parent bec6f387

add implementation of euclidean algorithm and compile with REENTRANT and pthread…

… as this code is ment to be used within threads ... also there is no other thread awareness in it
@@ -56,6 +56,9 @@ AM_CFLAGS="${AM_CFLAGS} ${MEM_OPT_FLAGS}" @@ -56,6 +56,9 @@ AM_CFLAGS="${AM_CFLAGS} ${MEM_OPT_FLAGS}"
56 AM_CFLAGS="${AM_CFLAGS} ${CFLAGS}" 56 AM_CFLAGS="${AM_CFLAGS} ${CFLAGS}"
57 AC_SUBST(AM_CFLAGS) 57 AC_SUBST(AM_CFLAGS)
58 58
  59 +AM_LDFLAGS=""
  60 +AC_SUBST(AM_LDFLAGS)
  61 +
59 AC_CONFIG_FILES([Makefile 62 AC_CONFIG_FILES([Makefile
60 docs/Makefile 63 docs/Makefile
61 tests/Makefile 64 tests/Makefile
@@ -8,6 +8,7 @@ nobase_include_HEADERS = trbase.h \ @@ -8,6 +8,7 @@ nobase_include_HEADERS = trbase.h \
8 tr/print_trace.h \ 8 tr/print_trace.h \
9 tr/sized_data.h \ 9 tr/sized_data.h \
10 tr/tree_macros.h \ 10 tr/tree_macros.h \
  11 + tr/math.h \
11 tr/interface/class.h \ 12 tr/interface/class.h \
12 tr/interface/indexable.h \ 13 tr/interface/indexable.h \
13 tr/interface/observer.h \ 14 tr/interface/observer.h \
  1 +/**
  2 + * \file
  3 + * Common reusable definitions.
  4 + *
  5 + * \todo All public symbols need to be prefixed to make name clashes
  6 + * more unlikely.
  7 + *
  8 + * \author Georg Hopp
  9 + *
  10 + * \copyright
  11 + * Copyright © 2014 Georg Hopp
  12 + *
  13 + * This program is free software: you can redistribute it and/or modify
  14 + * it under the terms of the GNU General Public License as published by
  15 + * the Free Software Foundation, either version 3 of the License, or
  16 + * (at your option) any later version.
  17 + *
  18 + * This program is distributed in the hope that it will be useful,
  19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21 + * GNU General Public License for more details.
  22 + *
  23 + * You should have received a copy of the GNU General Public License
  24 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25 + */
  26 +
  27 +#ifndef __TR_MATH_H__
  28 +#define __TR_MATH_H__
  29 +
  30 +#include "tr/commons.h"
  31 +
  32 +inline
  33 +long
  34 +TR_euklidGcd(register long val1, register long val2)
  35 +{
  36 + register long mod;
  37 +
  38 + if(val2 > val1) SWAP_XOR(val1, val2);
  39 +
  40 + mod = val1 % val2;
  41 + while (mod != 0) {
  42 + val1 = val2;
  43 + val2 = mod;
  44 + mod = val1 % val2;
  45 + }
  46 +
  47 + return val2;
  48 +}
  49 +
  50 +inline
  51 +long
  52 +TR_lcm(register long val1, register long val2)
  53 +{
  54 + return val1 * val2 / TR_euklidGcd(val1, val2);
  55 +}
  56 +
  57 +#endif // __TR_MATH_H__
  58 +
  59 +// vim: set ts=4 sw=4:
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 #include "tr/timer.h" 8 #include "tr/timer.h"
9 #include "tr/print_trace.h" 9 #include "tr/print_trace.h"
10 #include "tr/sized_data.h" 10 #include "tr/sized_data.h"
  11 +#include "tr/math.h"
11 #include "tr/interface.h" 12 #include "tr/interface.h"
12 #include "tr/interface/class.h" 13 #include "tr/interface/class.h"
13 #include "tr/interface/subject.h" 14 #include "tr/interface/subject.h"
1 ACLOCAL_AMFLAGS = -I m4 1 ACLOCAL_AMFLAGS = -I m4
2 AUTOMAKE_OPTIONS = subdir-objects 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
4 -AM_CFLAGS += -I../include/ 4 +AM_CFLAGS += -I../include/ -std=c99 -DREENTRANT -lpthread
  5 +AM_LDFLAGS += -lpthread
5 6
6 TR_CLASS = memory.c \ 7 TR_CLASS = memory.c \
7 interface.c \ 8 interface.c \
@@ -12,6 +13,7 @@ TR_CLASS = memory.c \ @@ -12,6 +13,7 @@ TR_CLASS = memory.c \
12 print_trace.c \ 13 print_trace.c \
13 stderr.c \ 14 stderr.c \
14 syslog.c \ 15 syslog.c \
  16 + math.c \
15 sized_data.c \ 17 sized_data.c \
16 sized_data_set_data.c \ 18 sized_data_set_data.c \
17 i_class.c \ 19 i_class.c \
@@ -24,6 +26,6 @@ TR_CLASS = memory.c \ @@ -24,6 +26,6 @@ TR_CLASS = memory.c \
24 lib_LTLIBRARIES = libtrbase.la 26 lib_LTLIBRARIES = libtrbase.la
25 27
26 libtrbase_la_SOURCES = $(TR_CLASS) 28 libtrbase_la_SOURCES = $(TR_CLASS)
27 -libtrbase_la_CFLAGS = $(AM_CFLAGS) -lpthread  
28 -libtrbase_la_LIBADD = 29 +libtrbase_la_CFLAGS = $(AM_CFLAGS)
  30 +libtrbase_la_LIBADD = $(AM_LDFLAGS)
29 libtrbase_la_LDFLAGS = -version-info 1:0:1 31 libtrbase_la_LDFLAGS = -version-info 1:0:1
  1 +/**
  2 + * \file
  3 + * Common reusable definitions.
  4 + *
  5 + * \todo All public symbols need to be prefixed to make name clashes
  6 + * more unlikely.
  7 + *
  8 + * \author Georg Hopp
  9 + *
  10 + * \copyright
  11 + * Copyright © 2014 Georg Hopp
  12 + *
  13 + * This program is free software: you can redistribute it and/or modify
  14 + * it under the terms of the GNU General Public License as published by
  15 + * the Free Software Foundation, either version 3 of the License, or
  16 + * (at your option) any later version.
  17 + *
  18 + * This program is distributed in the hope that it will be useful,
  19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21 + * GNU General Public License for more details.
  22 + *
  23 + * You should have received a copy of the GNU General Public License
  24 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25 + */
  26 +
  27 +#include "tr/math.h"
  28 +
  29 +extern inline long TR_euklidGcd(register long, register long);
  30 +extern inline long TR_lcm(register long, register long);
@@ -20,6 +20,8 @@ @@ -20,6 +20,8 @@
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */ 21 */
22 22
  23 +#define _POSIX_C_SOURCE 199309L
  24 +
23 #include <time.h> 25 #include <time.h>
24 #include <limits.h> 26 #include <limits.h>
25 27
@@ -20,6 +20,8 @@ @@ -20,6 +20,8 @@
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */ 21 */
22 22
  23 +#define _POSIX_C_SOURCE 199309L
  24 +
23 #include <time.h> 25 #include <time.h>
24 26
25 #include "trbase.h" 27 #include "trbase.h"
Please register or login to post a comment