annotate libtests/0005/prog1.c @ 400:8c7453fb5bd9 api-inversion

Invert audioDB::power_flag / audiodb_power() Here the exciting discovery is that the mmap(), memcpy(), munmap() sequence is in fact not safe. In principle an msync() call should be inserted before unmapping for in-core changes to mmap()ed files to be flushed to disk. In this case we work around the problem entirely, by not mmap()ing anything and doing everything with file descriptors. Amusingly, that's probably not desperately safe either, this time because we have to move the file descriptor position (which is also a shared resource). dup() doesn't save us, as the duplicate file descriptor shares a file position. This applies also to the filling of data_buffer in the query loop, and in fact basically any call to lseek(), which is why I'm not fixing it now. Solution: if you have multiple threads all acting at once on a single database, do one audiodb_open() per thread, for now at least.
author mas01cr
date Thu, 27 Nov 2008 16:22:52 +0000
parents 94c18f128ce8
children e072aa1611f5 342822c2d49a
rev   line source
mas01ik@355 1 #include <stdio.h>
mas01ik@355 2 #include <stdlib.h>
mas01ik@355 3 #include <string.h>
mas01ik@355 4 #include <sysexits.h>
mas01ik@355 5 #include <fcntl.h>
mas01ik@355 6 #include <dirent.h>
mas01ik@355 7 #include <unistd.h>
mas01ik@355 8 #include <sys/stat.h>
mas01ik@355 9 /*
mas01ik@355 10 * * #define NDEBUG
mas01ik@355 11 * * */
mas01ik@355 12 #include <assert.h>
mas01ik@355 13
mas01ik@355 14 #include "../../audioDB_API.h"
mas01ik@355 15 #include "../test_utils_lib.h"
mas01ik@355 16
mas01ik@355 17
mas01ik@355 18 int main(int argc, char **argv){
mas01ik@355 19
mas01ik@355 20 int returnval=0;
mas01ik@355 21 adb_ptr mydbp={0};
mas01ik@355 22 int ivals[10];
mas01ik@355 23 double dvals[10];
mas01ik@355 24 adb_insert_t myinsert={0};
mas01ik@355 25 unsigned int myerr=0;
mas01ik@355 26 char * databasename="testdb";
mas01ik@355 27 int myerror=0;
mas01ik@355 28
mas01ik@355 29
mas01ik@355 30 /* remove old directory */
mas01ik@355 31 //if [ -f testdb ]; then rm -f testdb; fi
mas01ik@355 32 clean_remove_db(databasename);
mas01ik@355 33
mas01ik@355 34 /* create new db */
mas01ik@355 35 //${AUDIODB} -d testdb -N
mas01ik@355 36 mydbp=audiodb_create(databasename,0,0,0);
mas01ik@355 37
mas01ik@355 38
mas01ik@355 39 /* make a test file */
mas01ik@355 40 //intstring 2 > testfeature
mas01ik@355 41 //floatstring 0 1 >> testfeature
mas01ik@355 42 //floatstring 1 0 >> testfeature
mas01ik@355 43 ivals[0]=2;
mas01ik@355 44 dvals[0]=0; dvals[1]=1; dvals[2]=1; dvals[3]=0;
mas01ik@355 45 maketestfile("testfeature",ivals,dvals,4);
mas01ik@355 46
mas01ik@355 47
mas01ik@355 48 /* insert */
mas01ik@355 49 //${AUDIODB} -d testdb -I -f testfeature
mas01ik@355 50 myinsert.features="testfeature";
mas01ik@355 51 myerr=audiodb_insert(mydbp,&myinsert);
mas01ik@355 52
mas01ik@355 53 /* turn on l2norm */
mas01ik@355 54 //echo running L2Norm
mas01ik@355 55 //${AUDIODB} -d testdb -L
mas01ik@355 56 myerror=audiodb_l2norm(mydbp);
mas01ik@355 57 if (myerror){
mas01ik@355 58 returnval=-1;
mas01ik@355 59 }
mas01ik@355 60
mas01ik@355 61
mas01ik@355 62 /* close */
mas01ik@355 63 audiodb_close(mydbp);
mas01ik@355 64
mas01ik@355 65
mas01ik@355 66
mas01ik@355 67 return(returnval);
mas01ik@355 68 }
mas01ik@355 69