Browse Source

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

1.0.2
Georg Hopp 11 years ago
parent
commit
f67ee68066
  1. 3
      configure.ac
  2. 1
      include/Makefile.am
  3. 59
      include/tr/math.h
  4. 1
      include/trbase.h
  5. 8
      src/Makefile.am
  6. 30
      src/math.c
  7. 2
      src/timer_get.c
  8. 2
      src/timer_set.c

3
configure.ac

@ -56,6 +56,9 @@ AM_CFLAGS="${AM_CFLAGS} ${MEM_OPT_FLAGS}"
AM_CFLAGS="${AM_CFLAGS} ${CFLAGS}"
AC_SUBST(AM_CFLAGS)
AM_LDFLAGS=""
AC_SUBST(AM_LDFLAGS)
AC_CONFIG_FILES([Makefile
docs/Makefile
tests/Makefile

1
include/Makefile.am

@ -8,6 +8,7 @@ nobase_include_HEADERS = trbase.h \
tr/print_trace.h \
tr/sized_data.h \
tr/tree_macros.h \
tr/math.h \
tr/interface/class.h \
tr/interface/indexable.h \
tr/interface/observer.h \

59
include/tr/math.h

@ -0,0 +1,59 @@
/**
* \file
* Common reusable definitions.
*
* \todo All public symbols need to be prefixed to make name clashes
* more unlikely.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __TR_MATH_H__
#define __TR_MATH_H__
#include "tr/commons.h"
inline
long
TR_euklidGcd(register long val1, register long val2)
{
register long mod;
if(val2 > val1) SWAP_XOR(val1, val2);
mod = val1 % val2;
while (mod != 0) {
val1 = val2;
val2 = mod;
mod = val1 % val2;
}
return val2;
}
inline
long
TR_lcm(register long val1, register long val2)
{
return val1 * val2 / TR_euklidGcd(val1, val2);
}
#endif // __TR_MATH_H__
// vim: set ts=4 sw=4:

1
include/trbase.h

@ -8,6 +8,7 @@
#include "tr/timer.h"
#include "tr/print_trace.h"
#include "tr/sized_data.h"
#include "tr/math.h"
#include "tr/interface.h"
#include "tr/interface/class.h"
#include "tr/interface/subject.h"

8
src/Makefile.am

@ -1,7 +1,8 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../include/
AM_CFLAGS += -I../include/ -std=c99 -DREENTRANT -lpthread
AM_LDFLAGS += -lpthread
TR_CLASS = memory.c \
interface.c \
@ -12,6 +13,7 @@ TR_CLASS = memory.c \
print_trace.c \
stderr.c \
syslog.c \
math.c \
sized_data.c \
sized_data_set_data.c \
i_class.c \
@ -24,6 +26,6 @@ TR_CLASS = memory.c \
lib_LTLIBRARIES = libtrbase.la
libtrbase_la_SOURCES = $(TR_CLASS)
libtrbase_la_CFLAGS = $(AM_CFLAGS) -lpthread
libtrbase_la_LIBADD =
libtrbase_la_CFLAGS = $(AM_CFLAGS)
libtrbase_la_LIBADD = $(AM_LDFLAGS)
libtrbase_la_LDFLAGS = -version-info 1:0:1

30
src/math.c

@ -0,0 +1,30 @@
/**
* \file
* Common reusable definitions.
*
* \todo All public symbols need to be prefixed to make name clashes
* more unlikely.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tr/math.h"
extern inline long TR_euklidGcd(register long, register long);
extern inline long TR_lcm(register long, register long);

2
src/timer_get.c

@ -20,6 +20,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _POSIX_C_SOURCE 199309L
#include <time.h>
#include <limits.h>

2
src/timer_set.c

@ -20,6 +20,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _POSIX_C_SOURCE 199309L
#include <time.h>
#include "trbase.h"

Loading…
Cancel
Save