summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authormonty@donna.mysql.com <>2000-09-12 03:02:33 +0300
committermonty@donna.mysql.com <>2000-09-12 03:02:33 +0300
commit2776500c220c92bb78df03513cc3dd33588f40e5 (patch)
tree051686baf31e5363765879f2437ada3abea6b71b /mysys
parent497007e2bd9cb127d54a4fdb02253301f404ce7f (diff)
downloadmariadb-git-2776500c220c92bb78df03513cc3dd33588f40e5.tar.gz
Update to new root alloc, OPTIMIZE TABLE and some other changes
Diffstat (limited to 'mysys')
-rw-r--r--mysys/default.c4
-rw-r--r--mysys/errors.c2
-rw-r--r--mysys/my_alloc.c35
-rw-r--r--mysys/my_create.c13
-rw-r--r--mysys/my_fopen.c6
-rw-r--r--mysys/my_open.c22
-rw-r--r--mysys/my_pread.c55
-rw-r--r--mysys/tree.c4
8 files changed, 106 insertions, 35 deletions
diff --git a/mysys/default.c b/mysys/default.c
index ae4ba5044be..10b0d6c7f5c 100644
--- a/mysys/default.c
+++ b/mysys/default.c
@@ -78,7 +78,7 @@ void load_defaults(const char *conf_file, const char **groups,
char *ptr,**res;
DBUG_ENTER("load_defaults");
- init_alloc_root(&alloc,128);
+ init_alloc_root(&alloc,128,0);
if (*argc >= 2 && !strcmp(argv[0][1],"--no-defaults"))
{
/* remove the --no-defaults argument and return only the other arguments */
@@ -188,7 +188,7 @@ void free_defaults(char **argv)
{
MEM_ROOT ptr;
memcpy_fixed((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr));
- free_root(&ptr);
+ free_root(&ptr,MYF(0));
}
diff --git a/mysys/errors.c b/mysys/errors.c
index 03b0b9d7f46..f74a56ed5e5 100644
--- a/mysys/errors.c
+++ b/mysys/errors.c
@@ -45,6 +45,7 @@ const char * NEAR globerrs[GLOBERRS]=
"Disk is full writing '%s'. Waiting for someone to free space...",
"Can't create directory '%s' (Errcode: %d)",
"Character set '%s' is not a compiled character set and is not specified in the '%s' file"
+ "Out of resources when opening file '%s' (Errcode: %d)",
};
void init_glob_errs(void)
@@ -80,5 +81,6 @@ void init_glob_errs()
EE(EE_DISK_FULL) = "Disk is full writing '%s'. Waiting for someone to free space...";
EE(EE_CANT_MKDIR) ="Can't create directory '%s' (Errcode: %d)";
EE(EE_UNKNOWN_CHARSET)= "Character set is not a compiled character set and is not specified in the %s file";
+ EE(EE_OUT_OF_FILERESOURCES)="Out of resources when opening file '%s' (Errcode: %d)",
}
#endif
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
index 45fd2516683..7bcf92621c5 100644
--- a/mysys/my_alloc.c
+++ b/mysys/my_alloc.c
@@ -21,12 +21,25 @@
#include <my_sys.h>
#include <m_string.h>
-void init_alloc_root(MEM_ROOT *mem_root,uint block_size)
+void init_alloc_root(MEM_ROOT *mem_root, uint block_size, uint pre_alloc_size)
{
mem_root->free=mem_root->used=0;
mem_root->min_malloc=16;
mem_root->block_size=block_size-MALLOC_OVERHEAD-sizeof(USED_MEM)-8;
mem_root->error_handler=0;
+#if !(defined(HAVE_purify) && defined(EXTRA_DEBUG))
+ if (pre_alloc_size)
+ {
+ if ((mem_root->free = mem_root->pre_alloc=
+ (USED_MEM*) my_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)),
+ MYF(0))))
+ {
+ mem_root->free->size=pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM));
+ mem_root->free->left=pre_alloc_size;
+ mem_root->free->next=0;
+ }
+ }
+#endif
}
gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size)
@@ -89,27 +102,39 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size)
/* deallocate everything used by alloc_root */
-void free_root(MEM_ROOT *root)
+void free_root(MEM_ROOT *root, myf MyFlags)
{
reg1 USED_MEM *next,*old;
DBUG_ENTER("free_root");
if (!root)
DBUG_VOID_RETURN; /* purecov: inspected */
- for (next= root->used ; next ; )
+ if (!(MyFlags & MY_KEEP_PREALLOC))
+ root->pre_alloc=0;
+
+ for ( next=root->used; next ;)
{
old=next; next= next->next ;
- my_free((gptr) old,MYF(0));
+ if (old != root->pre_alloc)
+ my_free((gptr) old,MYF(0));
}
for (next= root->free ; next ; )
{
old=next; next= next->next ;
- my_free((gptr) old,MYF(0));
+ if (old != root->pre_alloc)
+ my_free((gptr) old,MYF(0));
}
root->used=root->free=0;
+ if (root->pre_alloc)
+ {
+ root->free=root->pre_alloc;
+ root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(USED_MEM));
+ root->free->next=0;
+ }
DBUG_VOID_RETURN;
}
+
char *strdup_root(MEM_ROOT *root,const char *str)
{
uint len= (uint) strlen(str)+1;
diff --git a/mysys/my_create.c b/mysys/my_create.c
index 866c0dfd465..068fd7109f6 100644
--- a/mysys/my_create.c
+++ b/mysys/my_create.c
@@ -63,13 +63,26 @@ File my_create(const char *FileName, int CreateFlags, int access_flags,
{
if ((int) fd >= MY_NFILE)
{
+#if defined(THREAD) && !defined(HAVE_PREAD)
+ (void) my_close(fd,MyFlags);
+ my_errno=EMFILE;
+ if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
+ my_error(EE_OUT_OF_FILERESOURCES, MYF(ME_BELL+ME_WAITTANG),
+ FileName, my_errno);
+ DBUG_RETURN(-1);
+#else
+ thread_safe_increment(my_file_opened,&THR_LOCK_open);
DBUG_PRINT("exit",("fd: %d",fd));
DBUG_RETURN(fd); /* safeguard */
+#endif
}
if ((my_file_info[fd].name = (char*) my_strdup(FileName,MyFlags)))
{
my_file_opened++;
my_file_info[fd].type = FILE_BY_CREATE;
+#if defined(THREAD) && !defined(HAVE_PREAD)
+ pthread_mutex_init(&my_file_info[fd].mutex,NULL);
+#endif
DBUG_PRINT("exit",("fd: %d",fd));
DBUG_RETURN(fd);
}
diff --git a/mysys/my_fopen.c b/mysys/my_fopen.c
index b2e99518792..30424874aa0 100644
--- a/mysys/my_fopen.c
+++ b/mysys/my_fopen.c
@@ -44,7 +44,10 @@ FILE *my_fopen(const char *FileName, int Flags, myf MyFlags)
so we can ignore if this doesn't work.
*/
if ((uint) fileno(fd) >= MY_NFILE)
+ {
+ thread_safe_increment(my_stream_opened,&THR_LOCK_open);
DBUG_RETURN(fd); /* safeguard */
+ }
pthread_mutex_lock(&THR_LOCK_open);
if ((my_file_info[fileno(fd)].name = (char*)
my_strdup(FileName,MyFlags)))
@@ -87,11 +90,12 @@ int my_fclose(FILE *fd, myf MyFlags)
my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),
my_filename(file),errno);
}
+ else
+ my_stream_opened--;
if ((uint) file < MY_NFILE && my_file_info[file].type != UNOPEN)
{
my_file_info[file].type = UNOPEN;
my_free(my_file_info[file].name, MYF(0));
- my_stream_opened--;
}
pthread_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(err);
diff --git a/mysys/my_open.c b/mysys/my_open.c
index ef1db41e3f5..1f9d5cc3bae 100644
--- a/mysys/my_open.c
+++ b/mysys/my_open.c
@@ -48,12 +48,27 @@ File my_open(const char *FileName, int Flags, myf MyFlags)
if ((int) fd >= 0)
{
if ((int) fd >= MY_NFILE)
+ {
+#if defined(THREAD) && !defined(HAVE_PREAD)
+ (void) my_close(fd,MyFlags);
+ my_errno=EMFILE;
+ if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
+ my_error(EE_OUT_OF_FILERESOURCES, MYF(ME_BELL+ME_WAITTANG),
+ FileName, my_errno);
+ DBUG_RETURN(-1);
+#else
+ thread_safe_increment(my_file_opened,&THR_LOCK_open);
+#endif
DBUG_RETURN(fd); /* safeguard */
+ }
pthread_mutex_lock(&THR_LOCK_open);
if ((my_file_info[fd].name = (char*) my_strdup(FileName,MyFlags)))
{
my_file_opened++;
my_file_info[fd].type = FILE_BY_OPEN;
+#if defined(THREAD) && !defined(HAVE_PREAD)
+ pthread_mutex_init(&my_file_info[fd].mutex,NULL);
+#endif
pthread_mutex_unlock(&THR_LOCK_open);
DBUG_PRINT("exit",("fd: %d",fd));
DBUG_RETURN(fd);
@@ -80,7 +95,7 @@ int my_close(File fd, myf MyFlags)
DBUG_PRINT("my",("fd: %d MyFlags: %d",fd, MyFlags));
pthread_mutex_lock(&THR_LOCK_open);
- if ((err = close(fd)) != 0)
+ if ((err = close(fd)))
{
my_errno=errno;
if (MyFlags & (MY_FAE | MY_WME))
@@ -88,9 +103,12 @@ int my_close(File fd, myf MyFlags)
}
if ((uint) fd < MY_NFILE && my_file_info[fd].type != UNOPEN)
{
- my_file_opened--;
my_free(my_file_info[fd].name, MYF(0));
+#if defined(THREAD) && !defined(HAVE_PREAD)
+ pthread_mutex_destroy(&my_file_info[fd].mutex);
+#endif
my_file_info[fd].type = UNOPEN;
+ my_file_opened--;
}
pthread_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(err);
diff --git a/mysys/my_pread.c b/mysys/my_pread.c
index 1190f2cc81b..74bb7783af5 100644
--- a/mysys/my_pread.c
+++ b/mysys/my_pread.c
@@ -28,6 +28,7 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
myf MyFlags)
{
uint readbytes;
+ int error;
DBUG_ENTER("my_pread");
DBUG_PRINT("my",("Fd: %d Seek: %lu Buffer: %lx Count: %u MyFlags: %d",
Filedes, (ulong) offset, Buffer, Count, MyFlags));
@@ -38,32 +39,35 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
errno=0; /* Linux doesn't reset this */
#endif
#ifndef HAVE_PREAD
+ pthread_mutex_lock(&my_file_info[Filedes].mutex);
readbytes= (uint) -1;
- if (lseek(Filedes, offset, MY_SEEK_SET) == -1L ||
- (readbytes = (uint) read(Filedes, Buffer, Count)) != Count)
+ error= (lseek(Filedes, offset, MY_SEEK_SET) == -1L ||
+ (readbytes = (uint) read(Filedes, Buffer, Count)) != Count);
+ pthread_mutex_unlock(&my_file_info[Filedes].mutex);
#else
- if ((readbytes = (uint) pread(Filedes, Buffer, Count, offset)) != Count)
+ error=((readbytes = (uint) pread(Filedes, Buffer, Count, offset)) != Count);
#endif
- {
- my_errno=errno;
- DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d",
- readbytes,Count,Filedes,my_errno));
+ if (error)
+ {
+ my_errno=errno;
+ DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d",
+ readbytes,Count,Filedes,my_errno));
#ifdef THREAD
- if (readbytes == 0 && errno == EINTR)
- continue; /* Interrupted */
+ if (readbytes == 0 && errno == EINTR)
+ continue; /* Interrupted */
#endif
- if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
- {
- if ((int) readbytes == -1)
- my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG),
- my_filename(Filedes),my_errno);
- else if (MyFlags & (MY_NABP | MY_FNABP))
- my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG),
- my_filename(Filedes),my_errno);
- }
- if ((int) readbytes == -1 || (MyFlags & (MY_FNABP | MY_NABP)))
- DBUG_RETURN(MY_FILE_ERROR); /* Return with error */
+ if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
+ {
+ if ((int) readbytes == -1)
+ my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG),
+ my_filename(Filedes),my_errno);
+ else if (MyFlags & (MY_NABP | MY_FNABP))
+ my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG),
+ my_filename(Filedes),my_errno);
}
+ if ((int) readbytes == -1 || (MyFlags & (MY_FNABP | MY_NABP)))
+ DBUG_RETURN(MY_FILE_ERROR); /* Return with error */
+ }
if (MyFlags & (MY_NABP | MY_FNABP))
DBUG_RETURN(0); /* Ok vid l{sning */
DBUG_RETURN(readbytes); /* purecov: inspected */
@@ -76,6 +80,7 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset,
myf MyFlags)
{
+ int error;
uint writenbytes,errors;
ulong written;
DBUG_ENTER("my_pwrite");
@@ -87,12 +92,16 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset,
{
#ifndef HAVE_PREAD
writenbytes= (uint) -1;
- if (lseek(Filedes, offset, MY_SEEK_SET) != -1L &&
- (writenbytes = (uint) write(Filedes, Buffer, Count)) == Count)
+ pthread_mutex_lock(&my_file_info[Filedes].mutex);
+ error=(lseek(Filedes, offset, MY_SEEK_SET) != -1L &&
+ (writenbytes = (uint) write(Filedes, Buffer, Count)) == Count);
+ pthread_mutex_unlock(&my_file_info[Filedes].mutex);
+ if (error)
+ break;
#else
if ((writenbytes = (uint) pwrite(Filedes, Buffer, Count,offset)) == Count)
-#endif
break;
+#endif
if ((int) writenbytes != -1)
{ /* Safegueard */
written+=writenbytes;
diff --git a/mysys/tree.c b/mysys/tree.c
index 259fc5fb9d0..a36fd06f3f1 100644
--- a/mysys/tree.c
+++ b/mysys/tree.c
@@ -96,7 +96,7 @@ void init_tree(TREE *tree, uint default_alloc_size, int size,
}
if (!(tree->with_delete=with_delete))
{
- init_alloc_root(&tree->mem_root, default_alloc_size);
+ init_alloc_root(&tree->mem_root, default_alloc_size,0);
tree->mem_root.min_malloc=(sizeof(TREE_ELEMENT)+tree->size_of_element);
}
DBUG_VOID_RETURN;
@@ -115,7 +115,7 @@ void delete_tree(TREE *tree)
{
if (tree->free)
delete_tree_element(tree,tree->root);
- free_root(&tree->mem_root);
+ free_root(&tree->mem_root,MYF(0));
}
}
tree->root= &tree->null_element;