~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/concurrency_test.cc

Removing global errbuff and cleaning up two remaining instances that referenced it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
  Just a test application for threads.
3
3
  */
4
4
#include "azio.h"
5
 
#include <libdrizzle/libdrizzle.h>
6
5
#include <mysys/my_getopt.h>
7
6
#include <stdio.h>
8
7
#include <stdlib.h>
28
27
 
29
28
#define DEFAULT_INITIAL_LOAD 10000
30
29
#define DEFAULT_EXECUTE_SECONDS 120
31
 
#define DEFAULT_CONCURRENCY 8
32
30
#define TEST_FILENAME "concurrency_test.az"
33
31
 
34
32
#define HUGE_STRING_LENGTH 8192
47
45
pthread_mutex_t row_lock;
48
46
 
49
47
/* Prototypes */
50
 
void *run_task(void *p);
51
 
void *timer_thread(void *p);
 
48
extern "C" {
 
49
  void *run_concurrent_task(void *p);
 
50
  void *timer_thread(void *p);
 
51
}
52
52
void scheduler(az_method use_aio);
53
 
void create_data_file(azio_stream *write_handler, unsigned long long rows);
 
53
void create_data_file(azio_stream *write_handler, uint64_t rows);
54
54
unsigned int write_row(azio_stream *s);
55
55
 
56
56
typedef struct thread_context_st thread_context_st;
57
57
struct thread_context_st {
58
58
  unsigned int how_often_to_write;
59
 
  unsigned long long counter;
 
59
  uint64_t counter;
60
60
  az_method use_aio;
61
61
  azio_stream *writer;
62
62
};
79
79
int main(int argc, char *argv[])
80
80
{
81
81
 
82
 
  az_method method;
 
82
  unsigned int method;
83
83
  my_init();
84
84
 
85
85
  MY_INIT(argv[0]);
98
98
  pthread_mutex_init(&row_lock, NULL);
99
99
 
100
100
  for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
101
 
    scheduler(method);
 
101
    scheduler((az_method)method);
102
102
 
103
103
  (void)pthread_mutex_destroy(&counter_mutex);
104
104
  (void)pthread_cond_destroy(&count_threshhold);
114
114
void scheduler(az_method use_aio)
115
115
{
116
116
  unsigned int x;
117
 
  unsigned long long total;
 
117
  uint64_t total;
118
118
  azio_stream writer_handle;
119
119
  thread_context_st *context;
120
120
  pthread_t mainthread;            /* Thread descriptor */
151
151
    context[x].use_aio= use_aio;
152
152
 
153
153
    /* now you create the thread */
154
 
    if (pthread_create(&mainthread, &attr, run_task,
 
154
    if (pthread_create(&mainthread, &attr, run_concurrent_task,
155
155
                       (void *)context) != 0)
156
156
    {
157
157
      fprintf(stderr,"Could not create thread\n");
167
167
    timer_alarm= true;
168
168
    pthread_mutex_unlock(&timer_alarm_mutex);
169
169
 
170
 
    if (pthread_create(&mainthread, &attr, timer_thread, 
 
170
    if (pthread_create(&mainthread, &attr, timer_thread,
171
171
                       (void *)&opt_timer_length) != 0)
172
172
    {
173
173
      fprintf(stderr,"%s: Could not create timer thread\n", my_progname);
204
204
  free(context);
205
205
  azclose(&writer_handle);
206
206
 
207
 
  printf("Read %llu rows\n", total);
 
207
  printf("Read %"PRIu64" rows\n", total);
208
208
}
209
209
 
210
210
void *timer_thread(void *p)
212
212
  time_t *timer_length= (time_t *)p;
213
213
  struct timespec abstime;
214
214
 
215
 
  /* 
216
 
    We lock around the initial call in case were we in a loop. This 
 
215
  /*
 
216
    We lock around the initial call in case were we in a loop. This
217
217
    also keeps the value properly syncronized across call threads.
218
218
  */
219
219
  pthread_mutex_lock(&sleeper_mutex);
236
236
  return 0;
237
237
}
238
238
 
239
 
void *run_task(void *p)
 
239
void *run_concurrent_task(void *p)
240
240
{
241
241
  thread_context_st *context= (thread_context_st *)p;
242
 
  unsigned long long count;
 
242
  uint64_t count;
243
243
  int ret;
244
244
  int error;
245
245
  azio_stream reader_handle;
246
246
 
247
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
 
247
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
248
248
                    context->use_aio)))
249
249
  {
250
250
    printf("Could not open test file\n");
255
255
  while (master_wakeup)
256
256
  {
257
257
    pthread_cond_wait(&sleep_threshhold, &sleeper_mutex);
258
 
  } 
 
258
  }
259
259
  pthread_mutex_unlock(&sleeper_mutex);
260
260
 
261
261
  /* Do Stuff */
285
285
  return NULL;
286
286
}
287
287
 
288
 
void create_data_file(azio_stream *write_handler, unsigned long long rows)
 
288
void create_data_file(azio_stream *write_handler, uint64_t rows)
289
289
{
290
290
  int ret;
291
 
  unsigned long long x;
 
291
  uint64_t x;
292
292
 
293
 
  if (!(ret= azopen(write_handler, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC|O_BINARY,
 
293
  if (!(ret= azopen(write_handler, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC,
294
294
                    AZ_METHOD_BLOCK)))
295
295
  {
296
296
    printf("Could not create test file\n");
313
313
  /* Avoid zero length strings */
314
314
  length++;
315
315
 
316
 
  get_random_string(buffer, length); 
 
316
  get_random_string(buffer, length);
317
317
  pthread_mutex_lock(&row_lock);
318
318
  azwrite_row(s, buffer, length);
319
319
  pthread_mutex_unlock(&row_lock);