1
/* Copyright (C) 2000-2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#undef MAP_TO_USE_RAID /* Avoid RAID mappings */
17
#include <my_global.h>
19
#include <mysys_err.h>
20
#include <my_pthread.h>
21
#include <thr_alarm.h>
24
/* Lock a part of a file */
26
int my_lock(File fd,int locktype,my_off_t start,my_off_t length,myf MyFlags)
32
DBUG_ENTER("my_lock");
33
DBUG_PRINT("my",("Fd: %d Op: %d start: %ld Length: %ld MyFlags: %d",
34
fd,locktype,(ulong) start,(ulong) length,MyFlags));
35
if (my_disable_locking)
36
DBUG_RETURN(0); /* purecov: inspected */
37
m_lock.l_type=(short) locktype;
39
m_lock.l_start=(long) start;
40
m_lock.l_len=(long) length;
41
wait_for_alarm=(MyFlags & MY_DONT_WAIT ? MY_HOW_OFTEN_TO_ALARM :
43
if (fcntl(fd,F_SETLK,&m_lock) != -1) /* Check if we can lock */
44
DBUG_RETURN(0); /* Ok, file locked */
45
DBUG_PRINT("info",("Was locked, trying with alarm"));
46
if (!thr_alarm(&alarmed,wait_for_alarm,&alarm_buff))
49
while ((value=fcntl(fd,F_SETLKW,&m_lock)) && !thr_got_alarm(&alarmed) &&
51
thr_end_alarm(&alarmed);
59
if (errno == EINTR || errno == EACCES)
60
my_errno=EAGAIN; /* Easier to check for this */
66
if (locktype == F_UNLCK)
67
my_error(EE_CANTUNLOCK,MYF(ME_BELL+ME_WAITTANG),errno);
69
my_error(EE_CANTLOCK,MYF(ME_BELL+ME_WAITTANG),errno);
71
DBUG_PRINT("error",("errno: %d",errno));