AMD64 build fixes and parallelism tweaks
TODO: figure out how to autodetect lib vs lib64. These changes were made some time ago (can't remember when) but didn't get committed until now. (Yes, naughty me, but perhaps I was in a rush.)
This commit is contained in:
parent
1acd1307c0
commit
9e2ab341ba
9
Makefile
9
Makefile
@ -1,16 +1,17 @@
|
|||||||
.PHONY: clean install
|
.PHONY: clean install
|
||||||
|
|
||||||
CS_PATH=/usr
|
CS_PATH ?= /usr
|
||||||
MY_CFLAGS+=-I$(CS_PATH)/include/ClearSilver $(CFLAGS)
|
MY_CFLAGS+=-I$(CS_PATH)/include/ClearSilver $(CFLAGS)
|
||||||
MY_CFLAGS+=$(shell Wand-config --cflags --cppflags)
|
MY_CFLAGS+=$(shell Wand-config --cflags --cppflags)
|
||||||
MY_LDFLAGS+=$(shell Wand-config --ldflags --libs) $(LDFLAGS)
|
MY_LDFLAGS+=$(shell Wand-config --ldflags --libs) $(LDFLAGS)
|
||||||
|
|
||||||
MY_CFLAGS+=$(shell pkg-config --cflags json)
|
MY_CFLAGS+=$(shell pkg-config --cflags json)
|
||||||
MY_LDFLAGS+=$(shell pkg-config --libs json)
|
MY_LDFLAGS+=$(shell pkg-config --libs json)
|
||||||
|
MY_LDFLAGS+=-ljpeg
|
||||||
OBJS=obj/main.o obj/util.o obj/galleries.o obj/gallery.o obj/varray.o \
|
OBJS=obj/main.o obj/util.o obj/galleries.o obj/gallery.o obj/varray.o \
|
||||||
obj/photo.o obj/hdf-json.o obj/jpeg.o \
|
obj/photo.o obj/hdf-json.o obj/jpeg.o \
|
||||||
$(CS_PATH)/lib/libneo_cgi.a $(CS_PATH)/lib/libneo_cs.a \
|
$(CS_PATH)/lib64/libneo_cgi.a $(CS_PATH)/lib64/libneo_cs.a \
|
||||||
$(CS_PATH)/lib/libneo_utl.a
|
$(CS_PATH)/lib64/libneo_utl.a
|
||||||
|
|
||||||
VERSIONSTAMP=$(shell if [ -d .git ]; then git describe; else cat version; fi)
|
VERSIONSTAMP=$(shell if [ -d .git ]; then git describe; else cat version; fi)
|
||||||
COMPILESTAMP=$(shell date "+%Y-%m-%d %H:%M:%S %z" )
|
COMPILESTAMP=$(shell date "+%Y-%m-%d %H:%M:%S %z" )
|
||||||
@ -23,7 +24,7 @@ obj:
|
|||||||
obj/%.o: src/%.c include/%.h obj
|
obj/%.o: src/%.c include/%.h obj
|
||||||
$(CC) -DCOMPILESTAMP='"$(COMPILESTAMP)"' \
|
$(CC) -DCOMPILESTAMP='"$(COMPILESTAMP)"' \
|
||||||
-DVERSIONSTAMP='"$(VERSIONSTAMP)"' \
|
-DVERSIONSTAMP='"$(VERSIONSTAMP)"' \
|
||||||
$(MY_CFLAGS) -I include -o $@ -c $<
|
$(MY_CFLAGS) -I include $(CPPFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -fr obj gallery.cgi
|
rm -fr obj gallery.cgi
|
||||||
|
@ -179,4 +179,14 @@ void sort_str_array( char** array, size_t length, int case_insensitive );
|
|||||||
void sort_array( void** array, size_t length,
|
void sort_array( void** array, size_t length,
|
||||||
int (*compare)( const void*, const void* ) );
|
int (*compare)( const void*, const void* ) );
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Pause if the server load is too high.
|
||||||
|
* This causes the CGI script to sleep for a second if the load average is
|
||||||
|
* above MAX_CPU_LOAD.
|
||||||
|
*/
|
||||||
|
void wait_cpu_load();
|
||||||
|
#ifndef MAX_CPU_LOAD
|
||||||
|
#define MAX_CPU_LOAD (2.0)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
17
src/photo.c
17
src/photo.c
@ -463,21 +463,25 @@ char* resize_photo( struct photo_meta* dest,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NO_SEMAPHORE
|
||||||
/*
|
/*
|
||||||
* Check for semaphore... if it exists, wait for it to disappear.
|
* Check for semaphore... if it exists, wait for it to disappear.
|
||||||
* For this, we use the open() syscall with O_CREAT|O_EXCL, which
|
* For this, we use the open() syscall with O_CREAT|O_EXCL, which
|
||||||
* will fail if the file already exists.
|
* will fail if the file already exists.
|
||||||
*/
|
*/
|
||||||
char* sem_file = construct_path( "s/s/s", get_cgidir(),
|
char* sem_file = construct_path( "s/ss", get_cgidir(),
|
||||||
CACHEDIR, "semaphore" );
|
cache_file, ".sem" );
|
||||||
int fd = open( sem_file, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR );
|
int fd = open( sem_file, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR );
|
||||||
while( fd == -1 ) {
|
while( fd == -1 ) {
|
||||||
sleep(1);
|
sleep(1);
|
||||||
fd = open( sem_file, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR );
|
fd = open( sem_file, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR );
|
||||||
|
fprintf( stderr, "resize_photo: waiting for semaphore %s (fd: %d)\n",
|
||||||
|
sem_file, fd );
|
||||||
dprintf( "resize_photo: waiting for semaphore %s (fd: %d)\n",
|
dprintf( "resize_photo: waiting for semaphore %s (fd: %d)\n",
|
||||||
sem_file, fd );
|
sem_file, fd );
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
#endif
|
||||||
|
|
||||||
MagickWand* wand = NewMagickWand();
|
MagickWand* wand = NewMagickWand();
|
||||||
dprintf( "resize_photo: wand created at %p\n", wand);
|
dprintf( "resize_photo: wand created at %p\n", wand);
|
||||||
@ -486,11 +490,12 @@ char* resize_photo( struct photo_meta* dest,
|
|||||||
char* description=MagickGetException(wand,&severity);
|
char* description=MagickGetException(wand,&severity);
|
||||||
dprintf("%s %s %ld %s\n",GetMagickModule(),description);
|
dprintf("%s %s %ld %s\n",GetMagickModule(),description);
|
||||||
gcfree( cache_file );
|
gcfree( cache_file );
|
||||||
|
|
||||||
|
#ifndef NO_SEMAPHORE
|
||||||
/* Get rid of the semaphore */
|
/* Get rid of the semaphore */
|
||||||
unlink( sem_file );
|
unlink( sem_file );
|
||||||
gcfree( sem_file );
|
gcfree( sem_file );
|
||||||
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,9 +526,11 @@ char* resize_photo( struct photo_meta* dest,
|
|||||||
char* description=MagickGetException(wand,&severity);
|
char* description=MagickGetException(wand,&severity);
|
||||||
dprintf("%s %s %ld %s\n",GetMagickModule(),description);
|
dprintf("%s %s %ld %s\n",GetMagickModule(),description);
|
||||||
|
|
||||||
|
#ifndef NO_SEMAPHORE
|
||||||
/* Get rid of the semaphore */
|
/* Get rid of the semaphore */
|
||||||
unlink( sem_file );
|
unlink( sem_file );
|
||||||
gcfree( sem_file );
|
gcfree( sem_file );
|
||||||
|
#endif
|
||||||
|
|
||||||
gcfree( cache_file );
|
gcfree( cache_file );
|
||||||
cache_file = NULL;
|
cache_file = NULL;
|
||||||
@ -531,9 +538,11 @@ char* resize_photo( struct photo_meta* dest,
|
|||||||
|
|
||||||
DestroyMagickWand( wand );
|
DestroyMagickWand( wand );
|
||||||
|
|
||||||
|
#ifndef NO_SEMAPHORE
|
||||||
/* Get rid of the semaphore */
|
/* Get rid of the semaphore */
|
||||||
unlink( sem_file );
|
unlink( sem_file );
|
||||||
gcfree( sem_file );
|
gcfree( sem_file );
|
||||||
|
#endif
|
||||||
|
|
||||||
gcfree( cache_path );
|
gcfree( cache_path );
|
||||||
dprintf( "resize_photo: resized photo at %s (%p)\n", cache_file, cache_file );
|
dprintf( "resize_photo: resized photo at %s (%p)\n", cache_file, cache_file );
|
||||||
|
18
src/util.c
18
src/util.c
@ -6,6 +6,8 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <dprintf.h>
|
#include <dprintf.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
/* Memory management -- helpers */
|
/* Memory management -- helpers */
|
||||||
#ifdef MEMALLOC_TRACK
|
#ifdef MEMALLOC_TRACK
|
||||||
struct mem_chunk* gc_find_chunk( void* ptr ) {
|
struct mem_chunk* gc_find_chunk( void* ptr ) {
|
||||||
@ -678,3 +680,19 @@ void sort_str_array( char** array, size_t length, int case_insensitive ) {
|
|||||||
else
|
else
|
||||||
quicksort_main( (void**)array, 0, length-1, &void_strcmp );
|
quicksort_main( (void**)array, 0, length-1, &void_strcmp );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wait_load() {
|
||||||
|
#ifndef NO_MAX_LOAD
|
||||||
|
double avg;
|
||||||
|
if (getloadavg(&avg,1) < 0)
|
||||||
|
return;
|
||||||
|
while(avg >= MAX_CPU_LOAD) {
|
||||||
|
dprintf("Waiting for CPU load %f to drop below %f\n",
|
||||||
|
avg, MAX_CPU_LOAD);
|
||||||
|
sleep(1);
|
||||||
|
if (getloadavg(&avg,1) < 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user