summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/my_chsize.c13
-rw-r--r--mysys/queues.c45
-rw-r--r--mysys/thr_alarm.c14
3 files changed, 59 insertions, 13 deletions
diff --git a/mysys/my_chsize.c b/mysys/my_chsize.c
index 8e46b0808c0..653ea569172 100644
--- a/mysys/my_chsize.c
+++ b/mysys/my_chsize.c
@@ -51,16 +51,17 @@ int my_chsize(File fd, my_off_t newlength, int filler, myf MyFlags)
#if defined(HAVE_SETFILEPOINTER)
/* This is for the moment only true on windows */
{
+ long is_success;
HANDLE win_file= (HANDLE) _get_osfhandle(fd);
long length_low, length_high;
length_low= (long) (ulong) newlength;
length_high= (long) ((ulonglong) newlength >> 32);
- if (SetFilePointer(win_file, length_low, &length_high, FILE_BEGIN))
- {
- if (SetEndOfFile(win_file))
- DBUG_RETURN(0);
- }
- my_errno= errno;
+ is_success= SetFilePointer(win_file, length_low, &length_high, FILE_BEGIN);
+ if (is_success == -1 && (my_errno= GetLastError()) != NO_ERROR)
+ goto err;
+ if (SetEndOfFile(win_file))
+ DBUG_RETURN(0);
+ my_errno= GetLastError();
goto err;
}
#elif defined(HAVE_FTRUNCATE)
diff --git a/mysys/queues.c b/mysys/queues.c
index f077b38ca0b..ecf1058af41 100644
--- a/mysys/queues.c
+++ b/mysys/queues.c
@@ -64,7 +64,7 @@ int init_queue(QUEUE *queue, uint max_elements, uint offset_to_key,
/*
- Reinitialize queue for other usage (deletes all elements)
+ Reinitialize queue for other usage
SYNOPSIS
reinit_queue()
@@ -77,8 +77,8 @@ int init_queue(QUEUE *queue, uint max_elements, uint offset_to_key,
first_cmp_arg First argument to compare function
NOTES
- You can't currently resize the number of elements! If you need this,
- fix it :)
+ This will delete all elements from the queue. If you don't want this,
+ use resize_queue() instead.
RETURN
0 ok
@@ -90,15 +90,46 @@ int reinit_queue(QUEUE *queue, uint max_elements, uint offset_to_key,
void *first_cmp_arg)
{
DBUG_ENTER("reinit_queue");
- if (queue->max_elements < max_elements)
- /* It's real easy to do realloc here, just don't want to bother */
- DBUG_RETURN(my_errno=EE_OUTOFMEMORY);
-
queue->elements=0;
queue->compare=compare;
queue->first_cmp_arg=first_cmp_arg;
queue->offset_to_key=offset_to_key;
queue->max_at_top= max_at_top ? (-1 ^ 1) : 0;
+ resize_queue(queue, max_elements);
+ DBUG_RETURN(0);
+}
+
+
+/*
+ Resize queue
+
+ SYNOPSIS
+ resize_queue()
+ queue Queue
+ max_elements New max size for queue
+
+ NOTES
+ If you resize queue to be less than the elements you have in it,
+ the extra elements will be deleted
+
+ RETURN
+ 0 ok
+ 1 Error. In this case the queue is unchanged
+*/
+
+int resize_queue(QUEUE *queue, uint max_elements)
+{
+ byte **new_root;
+ DBUG_ENTER("resize_queue");
+ if (queue->max_elements == max_elements)
+ DBUG_RETURN(0);
+ if ((new_root= (byte **) my_realloc((void *)queue->root,
+ (max_elements+1)*sizeof(void*),
+ MYF(MY_WME))) == 0)
+ DBUG_RETURN(1);
+ set_if_smaller(queue->elements, max_elements);
+ queue->max_elements= max_elements;
+ queue->root= new_root;
DBUG_RETURN(0);
}
diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c
index 2289f8208bc..36bbac16fef 100644
--- a/mysys/thr_alarm.c
+++ b/mysys/thr_alarm.c
@@ -120,6 +120,20 @@ void init_thr_alarm(uint max_alarms)
DBUG_VOID_RETURN;
}
+
+void resize_thr_alarm(uint max_alarms)
+{
+ pthread_mutex_lock(&LOCK_alarm);
+ /*
+ It's ok not to shrink the queue as there may be more pending alarms than
+ than max_alarms
+ */
+ if (alarm_queue.elements < max_alarms)
+ resize_queue(&alarm_queue,max_alarms+1);
+ pthread_mutex_unlock(&LOCK_alarm);
+}
+
+
/*
Request alarm after sec seconds.