diff options
author | unknown <monty@hundin.mysql.fi> | 2002-06-20 15:25:02 +0300 |
---|---|---|
committer | unknown <monty@hundin.mysql.fi> | 2002-06-20 15:25:02 +0300 |
commit | 950df73713d6eca34de8be1f9771d40a8abeadc4 (patch) | |
tree | 7eee86ca5c680d305ade1203f3945cee038dbd46 /mit-pthreads | |
parent | ccf18acc242f33fffca016c1e28c99e6e4e443b7 (diff) | |
download | mariadb-git-950df73713d6eca34de8be1f9771d40a8abeadc4.tar.gz |
Fixed some bugs after last merge
Added semaphore support to MIT-pthreads.
Docs/manual.texi:
Updated benchmark data
configure.in:
Portability fix for compiling MIT-pthreads with gcc 3.0.x
(Still not perfect)
include/my_semaphore.h:
Cleanup
mit-pthreads/Changes-mysql:
Added semaphore support
mit-pthreads/include/Makefile.inc:
Added semaphore support
mit-pthreads/include/pthread/ac-types.h:
Added semaphore support
mit-pthreads/pthreads/GNUmakefile.inc:
Added semaphore support
mit-pthreads/pthreads/Makefile.inc:
Added semaphore support
mit-pthreads/stdio/xprintf.c:
Added semaphore support
mysql-test/r/rpl_alter.result:
Fixed test results after merge with 3.23
sql/ha_isam.cc:
Fixed core dump after merge
sql/ha_isam.h:
Fixed core dump after merge
sql/mini_client.cc:
P
Diffstat (limited to 'mit-pthreads')
-rw-r--r-- | mit-pthreads/Changes-mysql | 6 | ||||
-rw-r--r-- | mit-pthreads/include/Makefile.inc | 2 | ||||
-rw-r--r-- | mit-pthreads/include/pthread/ac-types.h | 4 | ||||
-rw-r--r-- | mit-pthreads/include/semaphore.h | 20 | ||||
-rw-r--r-- | mit-pthreads/pthreads/GNUmakefile.inc | 2 | ||||
-rw-r--r-- | mit-pthreads/pthreads/Makefile.inc | 3 | ||||
-rw-r--r-- | mit-pthreads/pthreads/semaphore.c | 84 | ||||
-rw-r--r-- | mit-pthreads/stdio/xprintf.c | 24 |
8 files changed, 128 insertions, 17 deletions
diff --git a/mit-pthreads/Changes-mysql b/mit-pthreads/Changes-mysql index da30f66fdec..06336abaecb 100644 --- a/mit-pthreads/Changes-mysql +++ b/mit-pthreads/Changes-mysql @@ -1,4 +1,8 @@ -Changes done to this distrubtion (pthreads-1_60_beta6) by Monty (monty@mysql.com) +Changes done to this distrubtion (pthreads-1_60_beta6) by Monty +(monty@mysql.com) + +02.06.20 +- Added support for semaphores. 02.05.07 - Hacked some files to get it to compile (not work) with glibc 2.2 diff --git a/mit-pthreads/include/Makefile.inc b/mit-pthreads/include/Makefile.inc index b7fe59d5f0d..72554b638d2 100644 --- a/mit-pthreads/include/Makefile.inc +++ b/mit-pthreads/include/Makefile.inc @@ -7,7 +7,7 @@ FILES= cond.h copyright.h fd.h fd_pipe.h kernel.h mutex.h posix.h \ - pthread.h pthread_attr.h queue.h util.h + pthread.h pthread_attr.h queue.h util.h semaphore.h # Machine dependent header file MFILE= ${.CURDIR}/arch/${MACHINE}/machdep.h diff --git a/mit-pthreads/include/pthread/ac-types.h b/mit-pthreads/include/pthread/ac-types.h index 7fa4568817f..4dd20a6f748 100644 --- a/mit-pthreads/include/pthread/ac-types.h +++ b/mit-pthreads/include/pthread/ac-types.h @@ -6,5 +6,7 @@ #define pthread_ssize_t int #define pthread_time_t long #define pthread_off_t long -#define pthread_va_list void * +#ifdef NOT_USED /* Removed by monty becasue of conflicts on Linux */ +#define pthread_va_list char * +#endif #endif diff --git a/mit-pthreads/include/semaphore.h b/mit-pthreads/include/semaphore.h new file mode 100644 index 00000000000..7a593287bc4 --- /dev/null +++ b/mit-pthreads/include/semaphore.h @@ -0,0 +1,20 @@ +/* + This is written by Sergei Golubchik for MySQL AB and is in public domain. + + Simple implementation of semaphores, needed to compile MySQL with + MIT-pthreads. +*/ + +typedef struct { + pthread_mutex_t mutex; + pthread_cond_t cond; + uint count; +} sem_t; + +int sem_init(sem_t * sem, int pshared, uint value); +int sem_destroy(sem_t * sem); +int sem_wait(sem_t * sem); +int sem_trywait(sem_t * sem); +int sem_post (sem_t * sem); +int sem_post_multiple(sem_t * sem, uint count); +int sem_getvalue (sem_t * sem, uint *sval); diff --git a/mit-pthreads/pthreads/GNUmakefile.inc b/mit-pthreads/pthreads/GNUmakefile.inc index c8621495bac..b3019364a1d 100644 --- a/mit-pthreads/pthreads/GNUmakefile.inc +++ b/mit-pthreads/pthreads/GNUmakefile.inc @@ -9,7 +9,7 @@ SRCS:= cleanup.c cond.c fd.c fd_kern.c fd_pipe.c fd_sysv.c file.c globals.c \ specific.c process.c wait.c errno.c schedparam.c _exit.c prio_queue.c \ pthread_init.c init.cc sig.c info.c mutexattr.c select.c wrapper.c \ dump_state.c pthread_kill.c stat.c readv.c writev.c condattr.c \ - pthread_cancel.c panic.c $(SRCS) + pthread_cancel.c panic.c semaphore.c $(SRCS) ifeq ($(HAVE_SYSCALL_TEMPLATE),yes) SYSCALL_FILTER_RULE= for s in $(AVAILABLE_SYSCALLS) ; do \ diff --git a/mit-pthreads/pthreads/Makefile.inc b/mit-pthreads/pthreads/Makefile.inc index 3939d57de6e..68d970f17d8 100644 --- a/mit-pthreads/pthreads/Makefile.inc +++ b/mit-pthreads/pthreads/Makefile.inc @@ -8,7 +8,8 @@ SRCS+= cleanup.c cond.c fd.c fd_kern.c fd_pipe.c file.c globals.c malloc.c \ pthread_join.c pthread_detach.c pthread_once.c sleep.c specific.c \ process.c wait.c errno.c schedparam.c _exit.c prio_queue.c \ pthread_init.c init.cc sig.c info.c mutexattr.c select.c wrapper.c \ - dump_state.c pthread_kill.c condattr.c pthread_cancel.c panic.c + dump_state.c pthread_kill.c condattr.c pthread_cancel.c panic.c \ + semaphore.c .if $(HAVE_SYSCALL_TEMPLATE) == yes OBJS+= syscalls.o diff --git a/mit-pthreads/pthreads/semaphore.c b/mit-pthreads/pthreads/semaphore.c new file mode 100644 index 00000000000..5516af1f4e3 --- /dev/null +++ b/mit-pthreads/pthreads/semaphore.c @@ -0,0 +1,84 @@ +/* + This is written by Sergei Golubchik for MySQL AB and is in public domain. + + Simple implementation of semaphores, needed to compile MySQL with + MIT-pthreads. +*/ + +#include <pthread.h> +#include <errno.h> +#include <semaphore.h> + +int sem_init(sem_t * sem, int pshared, uint value) +{ + sem->count=value; + pthread_cond_init(&sem->cond, 0); + pthread_mutex_init(&sem->mutex, 0); + return 0; +} + +int sem_destroy(sem_t * sem) +{ + int err1,err2; + err1=pthread_cond_destroy(&sem->cond); + err2=pthread_mutex_destroy(&sem->mutex); + if (err1 || err2) + { + errno=err1 ? err1 : err2; + return -1; + } + return 0; +} + +int sem_wait(sem_t * sem) +{ + while ((errno=pthread_mutex_lock(&sem->mutex)) || !sem->count) + pthread_cond_wait(&sem->cond, &sem->mutex); + if (errno) + return -1; + sem->count--; /* mutex is locked here */ + pthread_mutex_unlock(&sem->mutex); + return 0; +} + +int sem_trywait(sem_t * sem) +{ + if ((errno=pthread_mutex_lock(&sem->mutex))) + return -1; + if (sem->count) + sem->count--; + else + errno=EAGAIN; + pthread_mutex_unlock(&sem->mutex); + return errno ? -1 : 0; +} + + +int sem_post(sem_t * sem) +{ + if ((errno=pthread_mutex_lock(&sem->mutex))) + return -1; + sem->count++; + pthread_mutex_unlock(&sem->mutex); /* does it really matter what to do */ + pthread_cond_signal(&sem->cond); /* first: x_unlock or x_signal ? */ + return 0; +} + +int sem_post_multiple(sem_t * sem, uint count) +{ + if ((errno=pthread_mutex_lock(&sem->mutex))) + return -1; + sem->count+=count; + pthread_mutex_unlock(&sem->mutex); /* does it really matter what to do */ + pthread_cond_broadcast(&sem->cond); /* first: x_unlock or x_broadcast ? */ + return 0; +} + +int sem_getvalue(sem_t * sem, uint *sval) +{ + if ((errno=pthread_mutex_lock(&sem->mutex))) + return -1; + *sval=sem->count; + pthread_mutex_unlock(&sem->mutex); + return 0; +} diff --git a/mit-pthreads/stdio/xprintf.c b/mit-pthreads/stdio/xprintf.c index 668e8bc0605..d2cec36c835 100644 --- a/mit-pthreads/stdio/xprintf.c +++ b/mit-pthreads/stdio/xprintf.c @@ -217,7 +217,7 @@ static int vxprintf(func,arg,format,ap) void (*func)(char*,int,void*); void *arg; const char *format; - va_list ap; + pthread_va_list ap; { register const char *fmt; /* The format string. */ register int c; /* Next character in the format string */ @@ -673,7 +673,7 @@ int xprintf( const char *format, ... ){ - va_list ap; + pthread_va_list ap; va_start(ap,format); return vxprintf(func,arg,format,ap); } @@ -715,7 +715,7 @@ static void sout(txt,amt,arg) int sprintf(char *buf, const char *fmt, ...){ int rc; - va_list ap; + pthread_va_list ap; struct s_strargument arg; va_start(ap,fmt); @@ -725,7 +725,7 @@ int sprintf(char *buf, const char *fmt, ...){ rc = vxprintf(sout,&arg,fmt,ap); va_end(ap); } -int vsprintf(char *buf,const char *fmt,va_list ap){ +int vsprintf(char *buf,const char *fmt, pthread_va_list ap){ struct s_strargument arg; arg.next = buf; arg.last = 0; @@ -734,7 +734,7 @@ int vsprintf(char *buf,const char *fmt,va_list ap){ } int snprintf(char *buf, size_t n, const char *fmt, ...){ int rc; - va_list ap; + pthread_va_list ap; struct s_strargument arg; va_start(ap,fmt); @@ -744,7 +744,7 @@ int snprintf(char *buf, size_t n, const char *fmt, ...){ rc = vxprintf(sout,&arg,fmt,ap); va_end(ap); } -int vsnprintf(char *buf, size_t n, const char *fmt, va_list ap){ +int vsnprintf(char *buf, size_t n, const char *fmt, pthread_va_list ap){ struct s_strargument arg; arg.next = buf; arg.last = &buf[n-1]; @@ -798,7 +798,7 @@ static void mout(zNewText,nNewChar,arg) ** routine naming conventions. */ char *mprintf(const char *zFormat, ...){ - va_list ap; + pthread_va_list ap; struct sgMprintf sMprintf; char *zNew; char zBuf[200]; @@ -825,7 +825,7 @@ char *mprintf(const char *zFormat, ...){ ** The name is changed to TclVMPrintf() to conform with Tcl naming ** conventions. */ -char *vmprintf(const char *zFormat,va_list ap){ +char *vmprintf(const char *zFormat,pthread_va_list ap){ struct sgMprintf sMprintf; char zBuf[200]; sMprintf.nChar = 0; @@ -858,7 +858,7 @@ static void fout(zNewText,nNewChar,arg) /* The public interface routines */ int fprintf(FILE *pOut, const char *zFormat, ...){ - va_list ap; + pthread_va_list ap; int retc; va_start(ap,zFormat); @@ -866,11 +866,11 @@ int fprintf(FILE *pOut, const char *zFormat, ...){ va_end(ap); return retc; } -int vfprintf(FILE *pOut, const char *zFormat, va_list ap){ +int vfprintf(FILE *pOut, const char *zFormat, pthread_va_list ap){ return vxprintf(fout,pOut,zFormat,ap); } int printf(const char *zFormat, ...){ - va_list ap; + pthread_va_list ap; int retc; va_start(ap,zFormat); @@ -878,6 +878,6 @@ int printf(const char *zFormat, ...){ va_end(ap); return retc; } -int vprintf(const char *zFormat, va_list ap){ +int vprintf(const char *zFormat, pthread_va_list ap){ return vxprintf(fout,stdout,zFormat,ap); } |