~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/concurrency_test.c

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

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>
 
5
#include <libdrizzle/drizzle.h>
6
6
#include <mysys/my_getopt.h>
7
7
#include <stdio.h>
8
8
#include <stdlib.h>
50
50
void *run_task(void *p);
51
51
void *timer_thread(void *p);
52
52
void scheduler(az_method use_aio);
53
 
void create_data_file(azio_stream *write_handler, uint64_t rows);
 
53
void create_data_file(azio_stream *write_handler, unsigned long long 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
 
  uint64_t counter;
 
59
  unsigned long long counter;
60
60
  az_method use_aio;
61
61
  azio_stream *writer;
62
62
};
87
87
  if (argc > 1)
88
88
    exit(1);
89
89
 
 
90
  if (!(drizzle_thread_safe()))
 
91
      fprintf(stderr, "This application was compiled incorrectly. Please recompile with thread support.\n");
 
92
 
90
93
  srandom(time(NULL));
91
94
 
92
95
  pthread_mutex_init(&counter_mutex, NULL);
93
96
  pthread_cond_init(&count_threshhold, NULL);
94
97
  pthread_mutex_init(&sleeper_mutex, NULL);
95
98
  pthread_cond_init(&sleep_threshhold, NULL);
96
 
  pthread_mutex_init(&timer_alarm_mutex, NULL);
97
 
  pthread_cond_init(&timer_alarm_threshold, NULL);
98
 
  pthread_mutex_init(&row_lock, NULL);
 
99
  VOID(pthread_mutex_init(&timer_alarm_mutex, NULL));
 
100
  VOID(pthread_cond_init(&timer_alarm_threshold, NULL));
 
101
  VOID(pthread_mutex_init(&row_lock, NULL));
99
102
 
100
103
  for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
101
104
    scheduler(method);
104
107
  (void)pthread_cond_destroy(&count_threshhold);
105
108
  (void)pthread_mutex_destroy(&sleeper_mutex);
106
109
  (void)pthread_cond_destroy(&sleep_threshhold);
107
 
  pthread_mutex_destroy(&timer_alarm_mutex);
108
 
  pthread_cond_destroy(&timer_alarm_threshold);
109
 
  pthread_mutex_destroy(&row_lock);
 
110
  VOID(pthread_mutex_destroy(&timer_alarm_mutex));
 
111
  VOID(pthread_cond_destroy(&timer_alarm_threshold));
 
112
  VOID(pthread_mutex_destroy(&row_lock));
110
113
 
111
114
  return 0;
112
115
}
114
117
void scheduler(az_method use_aio)
115
118
{
116
119
  unsigned int x;
117
 
  uint64_t total;
 
120
  unsigned long long total;
118
121
  azio_stream writer_handle;
119
122
  thread_context_st *context;
120
123
  pthread_t mainthread;            /* Thread descriptor */
204
207
  free(context);
205
208
  azclose(&writer_handle);
206
209
 
207
 
  printf("Read %"PRIu64" rows\n", total);
 
210
  printf("Read %llu rows\n", total);
208
211
}
209
212
 
210
213
void *timer_thread(void *p)
212
215
  time_t *timer_length= (time_t *)p;
213
216
  struct timespec abstime;
214
217
 
 
218
  if (drizzle_thread_init())
 
219
  {
 
220
    fprintf(stderr,"%s: drizzle_thread_init() failed.\n",
 
221
            my_progname);
 
222
    exit(1);
 
223
  }
 
224
 
215
225
  /* 
216
226
    We lock around the initial call in case were we in a loop. This 
217
227
    also keeps the value properly syncronized across call threads.
233
243
  timer_alarm= false;
234
244
  pthread_mutex_unlock(&timer_alarm_mutex);
235
245
 
 
246
  drizzle_thread_end();
 
247
 
236
248
  return 0;
237
249
}
238
250
 
239
251
void *run_task(void *p)
240
252
{
241
253
  thread_context_st *context= (thread_context_st *)p;
242
 
  uint64_t count;
 
254
  unsigned long long count;
243
255
  int ret;
244
256
  int error;
245
257
  azio_stream reader_handle;
246
258
 
247
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
 
259
  if (drizzle_thread_init())
 
260
  {
 
261
    fprintf(stderr,"%s: drizzle_thread_init() failed.\n", my_progname);
 
262
    exit(1);
 
263
  }
 
264
 
 
265
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
248
266
                    context->use_aio)))
249
267
  {
250
268
    printf("Could not open test file\n");
282
300
  pthread_mutex_unlock(&counter_mutex);
283
301
  azclose(&reader_handle);
284
302
 
 
303
  drizzle_thread_end();
 
304
 
285
305
  return NULL;
286
306
}
287
307
 
288
 
void create_data_file(azio_stream *write_handler, uint64_t rows)
 
308
void create_data_file(azio_stream *write_handler, unsigned long long rows)
289
309
{
290
310
  int ret;
291
 
  uint64_t x;
 
311
  unsigned long long x;
292
312
 
293
 
  if (!(ret= azopen(write_handler, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC,
 
313
  if (!(ret= azopen(write_handler, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC|O_BINARY,
294
314
                    AZ_METHOD_BLOCK)))
295
315
  {
296
316
    printf("Could not create test file\n");