summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.in2
-rw-r--r--include/my_semaphore.h17
-rw-r--r--mysys/Makefile.am2
-rw-r--r--mysys/my_getopt.c4
-rw-r--r--mysys/my_semaphore.c103
-rw-r--r--mysys/my_winsem.c4
-rw-r--r--mysys/thr_rwlock.c26
-rw-r--r--sql/gen_lex_hash.cc5
-rw-r--r--sql/slave.cc2
9 files changed, 143 insertions, 22 deletions
diff --git a/configure.in b/configure.in
index 58ce6331209..923d6e18800 100644
--- a/configure.in
+++ b/configure.in
@@ -1530,7 +1530,7 @@ AC_SUBST(MAKE_SHELL)
AC_CHECK_HEADERS(varargs.h stdarg.h dirent.h locale.h ndir.h sys/dir.h \
sys/file.h sys/ndir.h sys/ptem.h sys/pte.h sys/select.h sys/stream.h \
sys/mman.h curses.h termcap.h termio.h termbits.h asm/termbits.h grp.h \
-paths.h)
+paths.h semaphore.h)
# Already-done: strcasecmp
AC_CHECK_FUNCS(lstat putenv select setenv setlocale strcoll tcgetattr)
diff --git a/include/my_semaphore.h b/include/my_semaphore.h
index 36c4b1a4740..aecbde09511 100644
--- a/include/my_semaphore.h
+++ b/include/my_semaphore.h
@@ -33,20 +33,29 @@
C_MODE_START
-#ifndef __WIN__
+#ifdef HAVE_SEMAPHORE_H
#include <semaphore.h>
#else
+#ifdef __WIN__
typedef HANDLE sem_t;
+#else
+typedef struct {
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+ uint count;
+} sem_t;
+#endif
+
int sem_init(sem_t * sem, int pshared, unsigned int value);
int sem_destroy(sem_t * sem);
int sem_trywait(sem_t * sem);
int sem_wait(sem_t * sem);
int sem_post(sem_t * sem);
-int sem_post_multiple(sem_t * sem,int count);
-int sem_getvalue(sem_t * sem, int * sval);
+int sem_post_multiple(sem_t * sem, unsigned int count);
+int sem_getvalue(sem_t * sem, unsigned int * sval);
-#endif /* __WIN__ */
+#endif
C_MODE_END
#endif /* !_my_semaphore_h_ */
diff --git a/mysys/Makefile.am b/mysys/Makefile.am
index afaa82a8777..3ca07b7b80b 100644
--- a/mysys/Makefile.am
+++ b/mysys/Makefile.am
@@ -46,7 +46,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\
my_quick.c my_lockmem.c my_static.c \
my_getopt.c my_mkdir.c \
default.c my_compress.c checksum.c raid.cc \
- my_net.c \
+ my_net.c my_semaphore.c \
my_vsnprintf.c charset.c my_bitmap.c my_bit.c md5.c \
my_gethostbyname.c rijndael.c my_aes.c sha1.c
EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index ce9006e03c0..9583b5a72c3 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -75,7 +75,7 @@ int handle_options(int *argc, char ***argv,
uint opt_found, argvpos= 0, length, i;
my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used,
option_is_loose;
- char *progname= *(*argv), **pos, *optend, *prev_found;
+ char *progname= *(*argv), **pos, **pos_end, *optend, *prev_found;
const struct my_option *optp;
int error;
@@ -84,7 +84,7 @@ int handle_options(int *argc, char ***argv,
(*argv)++; /* --- || ---- */
init_variables(longopts);
- for (pos= *argv; *pos; pos++)
+ for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++)
{
char *cur_arg= *pos;
if (cur_arg[0] == '-' && cur_arg[1] && !end_of_options) /* must be opt */
diff --git a/mysys/my_semaphore.c b/mysys/my_semaphore.c
new file mode 100644
index 00000000000..de4aac1cdbd
--- /dev/null
+++ b/mysys/my_semaphore.c
@@ -0,0 +1,103 @@
+/* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/*
+ Simple implementation of semaphores, needed to compile MySQL on systems
+ that doesn't support semaphores.
+*/
+
+#include <my_global.h>
+#include <my_semaphore.h>
+
+#if !defined(__WIN__) && !defined(HAVE_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)
+{
+ if ((errno=pthread_mutex_lock(&sem->mutex)))
+ return -1;
+ while (!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;
+}
+
+#endif /* !defined(__WIN__) && !defined(HAVE_SEMAPHORE_H) */
diff --git a/mysys/my_winsem.c b/mysys/my_winsem.c
index 268a05a0b21..e2713d189b2 100644
--- a/mysys/my_winsem.c
+++ b/mysys/my_winsem.c
@@ -375,7 +375,7 @@ sem_post (sem_t * sem)
*/
int
-sem_post_multiple (sem_t * sem, int count )
+sem_post_multiple (sem_t * sem, unsigned int count)
{
#ifdef EXTRA_DEBUG
if (sem == NULL || *sem == NULL || count <= 0)
@@ -397,7 +397,7 @@ sem_post_multiple (sem_t * sem, int count )
}
int
-sem_getvalue (sem_t *sem, int *sval)
+sem_getvalue (sem_t *sem, unsigned int *sval)
{
errno = ENOSYS;
return -1;
diff --git a/mysys/thr_rwlock.c b/mysys/thr_rwlock.c
index 4e2cf3554b7..5f561762a3a 100644
--- a/mysys/thr_rwlock.c
+++ b/mysys/thr_rwlock.c
@@ -58,7 +58,7 @@
* Mountain View, California 94043
*/
-int my_rwlock_init( rw_lock_t *rwp, void *arg __attribute__((unused)))
+int my_rwlock_init(rw_lock_t *rwp, void *arg __attribute__((unused)))
{
pthread_condattr_t cond_attr;
@@ -74,7 +74,9 @@ int my_rwlock_init( rw_lock_t *rwp, void *arg __attribute__((unused)))
return( 0 );
}
-int my_rwlock_destroy( rw_lock_t *rwp ) {
+
+int my_rwlock_destroy(rw_lock_t *rwp)
+{
pthread_mutex_destroy( &rwp->lock );
pthread_cond_destroy( &rwp->readers );
pthread_cond_destroy( &rwp->writers );
@@ -82,11 +84,13 @@ int my_rwlock_destroy( rw_lock_t *rwp ) {
return( 0 );
}
-int my_rw_rdlock( rw_lock_t *rwp ) {
+
+int my_rw_rdlock(rw_lock_t *rwp)
+{
pthread_mutex_lock(&rwp->lock);
/* active or queued writers */
- while ( ( rwp->state < 0 ) || rwp->waiters )
+ while (( rwp->state < 0 ) || rwp->waiters)
pthread_cond_wait( &rwp->readers, &rwp->lock);
rwp->state++;
@@ -95,8 +99,8 @@ int my_rw_rdlock( rw_lock_t *rwp ) {
return( 0 );
}
-int my_rw_wrlock( rw_lock_t *rwp ) {
-
+int my_rw_wrlock(rw_lock_t *rwp)
+{
pthread_mutex_lock(&rwp->lock);
rwp->waiters++; /* another writer queued */
@@ -106,10 +110,12 @@ int my_rw_wrlock( rw_lock_t *rwp ) {
--rwp->waiters;
pthread_mutex_unlock( &rwp->lock );
- return( 0 );
+ return(0);
}
-int my_rw_unlock( rw_lock_t *rwp ) {
+
+int my_rw_unlock(rw_lock_t *rwp)
+{
DBUG_PRINT("rw_unlock",
("state: %d waiters: %d", rwp->state, rwp->waiters));
pthread_mutex_lock(&rwp->lock);
@@ -121,7 +127,9 @@ int my_rw_unlock( rw_lock_t *rwp ) {
pthread_cond_signal( &rwp->writers );
else
pthread_cond_broadcast( &rwp->readers );
- } else {
+ }
+ else
+ {
if ( --rwp->state == 0 ) /* no more readers */
pthread_cond_signal( &rwp->writers );
}
diff --git a/sql/gen_lex_hash.cc b/sql/gen_lex_hash.cc
index a4f0791d105..776b6840b45 100644
--- a/sql/gen_lex_hash.cc
+++ b/sql/gen_lex_hash.cc
@@ -373,7 +373,7 @@ static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument __attribute__((unused)))
{
- switch(optid) {
+ switch (optid) {
case 'v':
opt_verbose++;
break;
@@ -398,8 +398,9 @@ static int get_options(int argc, char **argv)
if (argc >= 1)
{
+ fprintf(stderr,"%s: Too many arguments\n", my_progname);
usage(0);
- exit(1);
+ exit(1);
}
return(0);
}
diff --git a/sql/slave.cc b/sql/slave.cc
index 6f173ba5cd8..5ca78b6c7a2 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -881,7 +881,7 @@ static int create_table_from_dump(THD* thd, NET* net, const char* db,
/* we do not want to log create table statement */
save_options = thd->options;
- thd->options &= ~OPTION_BIN_LOG;
+ thd->options &= ~(ulong) OPTION_BIN_LOG;
thd->proc_info = "Creating table from master dump";
// save old db in case we are creating in a different database
char* save_db = thd->db;