~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/my_lock.c

  • Committer: Brian Aker
  • Date: 2008-07-05 19:32:59 UTC
  • mfrom: (53.2.28 codestyle)
  • Revision ID: brian@tangent.org-20080705193259-opqzfb0oprfcg8dm
Merge from Monty's tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "mysys_priv.h"
17
 
#include "mysys_err.h"
 
16
#include <my_global.h>
 
17
#include <my_sys.h>
 
18
#include <mysys_err.h>
 
19
 
18
20
#include <errno.h>
19
21
#undef MY_HOW_OFTEN_TO_ALARM
20
22
#define MY_HOW_OFTEN_TO_ALARM ((int) my_time_to_wait_for_lock)
21
23
#ifdef NO_ALARM_LOOP
22
24
#undef NO_ALARM_LOOP
23
25
#endif
24
 
#include <my_alarm.h>
25
 
 
26
 
/* 
27
 
  Lock a part of a file 
 
26
 
 
27
 
 
28
/*
 
29
  Lock a part of a file
28
30
 
29
31
  RETURN VALUE
30
32
    0   Success
33
35
*/
34
36
 
35
37
int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
36
 
            myf MyFlags)
 
38
            myf MyFlags)
37
39
{
38
 
#ifdef HAVE_FCNTL
39
40
  int value;
40
 
  ALARM_VARIABLES;
41
 
#endif
 
41
  long alarm_pos=0,alarm_end_pos=MY_HOW_OFTEN_TO_WRITE-1;
 
42
 
42
43
  DBUG_ENTER("my_lock");
43
44
  DBUG_PRINT("my",("Fd: %d  Op: %d  start: %ld  Length: %ld  MyFlags: %d",
44
45
                   fd,locktype,(long) start,(long) length,MyFlags));
59
60
      if (fcntl(fd,F_SETLK,&lock) != -1)        /* Check if we can lock */
60
61
        DBUG_RETURN(0);                 /* Ok, file locked */
61
62
      DBUG_PRINT("info",("Was locked, trying with alarm"));
62
 
      ALARM_INIT;
63
 
      while ((value=fcntl(fd,F_SETLKW,&lock)) && ! ALARM_TEST &&
 
63
      while ((value=fcntl(fd,F_SETLKW,&lock)) && !  (alarm_pos++ >= alarm_end_pos) &&
64
64
             errno == EINTR)
65
65
      {                 /* Setup again so we don`t miss it */
66
 
        ALARM_REINIT;
 
66
        alarm_end_pos+=MY_HOW_OFTEN_TO_WRITE;
67
67
      }
68
 
      ALARM_END;
69
68
      if (value != -1)
70
69
        DBUG_RETURN(0);
71
70
      if (errno == EINTR)