Skip to content

Commit

Permalink
Preparatory thread-related code.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobez committed Oct 26, 2011
1 parent aa16ec7 commit 569c7ce
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
OPTIMIZE=-O2 -g
CFLAGS=-Wall -Werror
CFLAGS=-Wall -Werror -pthread
INCPATH=-I/usr/local/include -I/opt/local/include
CC?=cc

Expand All @@ -8,14 +8,14 @@ validns: main.o carp.o mempool.o textparse.o base64.o base32hex.o \
rrsig.o nsec.o dnskey.o txt.o aaaa.o \
naptr.o srv.o nsec3param.o nsec3.o ds.o \
hinfo.o loc.o nsec3checks.o ptr.o \
sshfp.o
sshfp.o threads.o
$(CC) $(CFLAGS) $(OPTIMIZE) -o validns \
main.o carp.o mempool.o textparse.o base64.o base32hex.o \
rr.o soa.o a.o cname.o mx.o ns.o \
rrsig.o nsec.o dnskey.o txt.o aaaa.o \
naptr.o srv.o nsec3param.o nsec3.o ds.o \
hinfo.o loc.o nsec3checks.o ptr.o \
sshfp.o \
sshfp.o threads.o \
-L/usr/local/lib -L/opt/local/lib -lJudy -lcrypto

clean:
Expand All @@ -24,7 +24,7 @@ clean:
-rm -f rrsig.o nsec.o dnskey.o txt.o aaaa.o
-rm -f naptr.o srv.o nsec3param.o nsec3.o ds.o
-rm -f hinfo.o loc.o nsec3checks.o ptr.o
-rm -f sshfp.o base32hex.o base64.o
-rm -f sshfp.o base32hex.o base64.o threads.o
-rm -f validns.core core
@echo ':-)'

Expand Down Expand Up @@ -109,6 +109,9 @@ ptr.o: ptr.c common.h textparse.h mempool.h carp.h rr.h
sshfp.o: sshfp.c common.h textparse.h mempool.h carp.h rr.h
$(CC) $(CFLAGS) $(OPTIMIZE) -c -o sshfp.o sshfp.c $(INCPATH)

threads.o: threads.c
$(CC) $(CFLAGS) $(OPTIMIZE) -c -o threads.o threads.c $(INCPATH)

test: validns
perl -MTest::Harness -e 'runtests("t/test.pl")'

Expand Down
33 changes: 33 additions & 0 deletions threads.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdlib.h>
#include <stdio.h>
#ifdef __GLIBC__
#include <sys/sysinfo.h>
#elif defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/types.h>
#include <sys/sysctl.h>
#endif

/* supposedly,
#if defined(PTW32_VERSION) || defined(__hpux)
return pthread_num_processors_np();
but I cannot verify that at the moment
*/

#if defined(__GLIBC__)
int ncpus(void) { return get_nprocs(); }
#elif defined(__APPLE__) || defined(__FreeBSD__)
int ncpus(void)
{
int count;
size_t size=sizeof(count);
return sysctlbyname("hw.ncpu",&count,&size,NULL,0) ? 0 : count;
}
#else
int ncpus(void) { return 0; } /* "Don't know */
#endif

/* Supposedly, sysconf() can also be used in some cases:
#include <unistd.h>
int const count=sysconf(_SC_NPROCESSORS_ONLN);
return (count>0)?count:0;
*/

0 comments on commit 569c7ce

Please sign in to comment.