~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_open.c

  • Committer: Monty Taylor
  • Date: 2008-08-02 00:06:32 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080802000632-jsse0zdd9r6ic5ku
Actually turn gettext on...

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* open a heap-database */
17
17
 
18
 
#include "heap_priv.h"
19
 
 
20
 
#include <string.h>
21
 
#include <cstdlib>
22
 
 
23
 
using namespace std;
 
18
#include "heapdef.h"
 
19
#ifdef VMS
 
20
#include "hp_static.c"                  /* Stupid vms-linker */
 
21
#endif
 
22
 
 
23
#include <mysys/my_sys.h>
24
24
 
25
25
/*
26
26
  Open heap table based on HP_SHARE structure
27
 
 
 
27
  
28
28
  NOTE
29
29
    This doesn't register the table in the open table list.
30
30
*/
31
31
 
32
32
HP_INFO *heap_open_from_share(HP_SHARE *share, int mode)
33
33
{
34
 
  HP_INFO *info= new HP_INFO;
 
34
  HP_INFO *info;
35
35
 
36
 
  share->open_count++;
37
 
  info->setShare(share);
38
 
  info->lastkey.resize(share->max_key_length);
 
36
  if (!(info= (HP_INFO*) my_malloc((uint) sizeof(HP_INFO) +
 
37
                                  2 * share->max_key_length,
 
38
                                  MYF(MY_ZEROFILL))))
 
39
  {
 
40
    return(0);
 
41
  }
 
42
  share->open_count++; 
 
43
  thr_lock_data_init(&share->lock,&info->lock,NULL);
 
44
  info->s= share;
 
45
  info->lastkey= (uchar*) (info + 1);
 
46
  info->recbuf= (uchar*) (info->lastkey + share->max_key_length);
39
47
  info->mode= mode;
40
 
  info->current_record= UINT32_MAX;             /* No current record */
 
48
  info->current_record= (ulong) ~0L;            /* No current record */
41
49
  info->lastinx= info->errkey= -1;
42
 
  return info;
 
50
  return(info);
43
51
}
44
52
 
45
53
 
51
59
{
52
60
  HP_INFO *info;
53
61
 
54
 
  THR_LOCK_heap.lock();
 
62
  pthread_mutex_lock(&THR_LOCK_heap);
55
63
  if ((info= heap_open_from_share(share, mode)))
56
64
  {
57
 
    heap_open_list.push_front(info);
 
65
    info->open_list.data= (void*) info;
 
66
    heap_open_list= list_add(heap_open_list,&info->open_list);
58
67
  }
59
 
  THR_LOCK_heap.unlock();
 
68
  pthread_mutex_unlock(&THR_LOCK_heap);
60
69
  return(info);
61
70
}
62
71
 
74
83
  HP_INFO *info;
75
84
  HP_SHARE *share;
76
85
 
77
 
  THR_LOCK_heap.lock();
 
86
  pthread_mutex_lock(&THR_LOCK_heap);
78
87
  if (!(share= hp_find_named_heap(name)))
79
88
  {
80
 
    errno= ENOENT;
81
 
    THR_LOCK_heap.unlock();
 
89
    my_errno= ENOENT;
 
90
    pthread_mutex_unlock(&THR_LOCK_heap);
82
91
    return(0);
83
92
  }
84
93
  if ((info= heap_open_from_share(share, mode)))
85
94
  {
86
 
    heap_open_list.push_front(info);
 
95
    info->open_list.data= (void*) info;
 
96
    heap_open_list= list_add(heap_open_list,&info->open_list);
87
97
  }
88
 
  THR_LOCK_heap.unlock();
 
98
  pthread_mutex_unlock(&THR_LOCK_heap);
89
99
  return(info);
90
100
}
91
101
 
94
104
 
95
105
HP_SHARE *hp_find_named_heap(const char *name)
96
106
{
97
 
  list<HP_SHARE *>::iterator it= heap_share_list.begin();
98
 
  while (it != heap_share_list.end())
 
107
  LIST *pos;
 
108
  HP_SHARE *info;
 
109
 
 
110
  for (pos= heap_share_list; pos; pos= pos->next)
99
111
  {
100
 
    if (not (*it)->name.compare(name))
 
112
    info= (HP_SHARE*) pos->data;
 
113
    if (!strcmp(name, info->name))
101
114
    {
102
 
      return (*it);
 
115
      return(info);
103
116
    }
104
 
    ++it;
105
117
  }
106
118
  return((HP_SHARE *) 0);
107
119
}