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
This commit is contained in:
unknown 2002-06-20 15:25:02 +03:00
commit 950df73713
15 changed files with 189 additions and 47 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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);

View file

@ -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 \

View file

@ -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

View file

@ -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;
}

View file

@ -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);
}