~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/concurrency_test.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

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 <drizzle.h>
6
 
#include <my_getopt.h>
7
 
#include <drizzle_version.h>
 
5
#include <libdrizzle/libdrizzle.h>
 
6
#include <mysys/my_getopt.h>
8
7
#include <stdio.h>
9
8
#include <stdlib.h>
10
9
#include <sys/types.h>
14
13
#include <fcntl.h>
15
14
#include <sys/time.h>
16
15
#include <pthread.h>
17
 
#include <strings.h>
 
16
#include <string.h>                             /* Pull in memset() */
18
17
#ifndef __WIN__
19
18
#include <sys/wait.h>
20
19
#endif
41
40
unsigned int master_wakeup;
42
41
pthread_mutex_t sleeper_mutex;
43
42
pthread_cond_t sleep_threshhold;
44
 
static my_bool timer_alarm= false;
 
43
static bool timer_alarm= false;
45
44
pthread_mutex_t timer_alarm_mutex;
46
45
pthread_cond_t timer_alarm_threshold;
47
46
 
51
50
void *run_task(void *p);
52
51
void *timer_thread(void *p);
53
52
void scheduler(az_method use_aio);
54
 
void create_data_file(azio_stream *write_handler, unsigned long long rows);
 
53
void create_data_file(azio_stream *write_handler, uint64_t rows);
55
54
unsigned int write_row(azio_stream *s);
56
55
 
57
56
typedef struct thread_context_st thread_context_st;
58
57
struct thread_context_st {
59
58
  unsigned int how_often_to_write;
60
 
  unsigned long long counter;
 
59
  uint64_t counter;
61
60
  az_method use_aio;
62
61
  azio_stream *writer;
63
62
};
88
87
  if (argc > 1)
89
88
    exit(1);
90
89
 
91
 
  if (!(mysql_thread_safe()))
92
 
      fprintf(stderr, "This application was compiled incorrectly. Please recompile with thread support.\n");
93
 
 
94
90
  srandom(time(NULL));
95
91
 
96
92
  pthread_mutex_init(&counter_mutex, NULL);
97
93
  pthread_cond_init(&count_threshhold, NULL);
98
94
  pthread_mutex_init(&sleeper_mutex, NULL);
99
95
  pthread_cond_init(&sleep_threshhold, NULL);
100
 
  VOID(pthread_mutex_init(&timer_alarm_mutex, NULL));
101
 
  VOID(pthread_cond_init(&timer_alarm_threshold, NULL));
102
 
  VOID(pthread_mutex_init(&row_lock, NULL));
 
96
  pthread_mutex_init(&timer_alarm_mutex, NULL);
 
97
  pthread_cond_init(&timer_alarm_threshold, NULL);
 
98
  pthread_mutex_init(&row_lock, NULL);
103
99
 
104
100
  for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
105
101
    scheduler(method);
108
104
  (void)pthread_cond_destroy(&count_threshhold);
109
105
  (void)pthread_mutex_destroy(&sleeper_mutex);
110
106
  (void)pthread_cond_destroy(&sleep_threshhold);
111
 
  VOID(pthread_mutex_destroy(&timer_alarm_mutex));
112
 
  VOID(pthread_cond_destroy(&timer_alarm_threshold));
113
 
  VOID(pthread_mutex_destroy(&row_lock));
 
107
  pthread_mutex_destroy(&timer_alarm_mutex);
 
108
  pthread_cond_destroy(&timer_alarm_threshold);
 
109
  pthread_mutex_destroy(&row_lock);
114
110
 
115
111
  return 0;
116
112
}
118
114
void scheduler(az_method use_aio)
119
115
{
120
116
  unsigned int x;
121
 
  unsigned long long total;
 
117
  uint64_t total;
122
118
  azio_stream writer_handle;
123
119
  thread_context_st *context;
124
120
  pthread_t mainthread;            /* Thread descriptor */
138
134
  pthread_mutex_unlock(&sleeper_mutex);
139
135
 
140
136
  context= (thread_context_st *)malloc(sizeof(thread_context_st) * DEFAULT_CONCURRENCY);
141
 
  bzero(context, sizeof(thread_context_st) * DEFAULT_CONCURRENCY);
 
137
  memset(context, 0, sizeof(thread_context_st) * DEFAULT_CONCURRENCY);
142
138
 
143
139
  if (!context)
144
140
  {
195
191
  {
196
192
    struct timespec abstime;
197
193
 
198
 
    bzero(&abstime, sizeof(struct timespec));
 
194
    memset(&abstime, 0, sizeof(struct timespec));
199
195
    abstime.tv_sec= 1;
200
196
 
201
197
    pthread_cond_timedwait(&count_threshhold, &counter_mutex, &abstime);
208
204
  free(context);
209
205
  azclose(&writer_handle);
210
206
 
211
 
  printf("Read %llu rows\n", total);
 
207
  printf("Read %"PRIu64" rows\n", total);
212
208
}
213
209
 
214
210
void *timer_thread(void *p)
216
212
  time_t *timer_length= (time_t *)p;
217
213
  struct timespec abstime;
218
214
 
219
 
  if (mysql_thread_init())
220
 
  {
221
 
    fprintf(stderr,"%s: mysql_thread_init() failed.\n",
222
 
            my_progname);
223
 
    exit(1);
224
 
  }
225
 
 
226
215
  /* 
227
216
    We lock around the initial call in case were we in a loop. This 
228
217
    also keeps the value properly syncronized across call threads.
244
233
  timer_alarm= false;
245
234
  pthread_mutex_unlock(&timer_alarm_mutex);
246
235
 
247
 
  mysql_thread_end();
248
 
 
249
236
  return 0;
250
237
}
251
238
 
252
239
void *run_task(void *p)
253
240
{
254
241
  thread_context_st *context= (thread_context_st *)p;
255
 
  unsigned long long count;
 
242
  uint64_t count;
256
243
  int ret;
257
244
  int error;
258
245
  azio_stream reader_handle;
259
246
 
260
 
  if (mysql_thread_init())
261
 
  {
262
 
    fprintf(stderr,"%s: mysql_thread_init() failed.\n", my_progname);
263
 
    exit(1);
264
 
  }
265
 
 
266
 
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
 
247
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY,
267
248
                    context->use_aio)))
268
249
  {
269
250
    printf("Could not open test file\n");
301
282
  pthread_mutex_unlock(&counter_mutex);
302
283
  azclose(&reader_handle);
303
284
 
304
 
  mysql_thread_end();
305
 
 
306
285
  return NULL;
307
286
}
308
287
 
309
 
void create_data_file(azio_stream *write_handler, unsigned long long rows)
 
288
void create_data_file(azio_stream *write_handler, uint64_t rows)
310
289
{
311
290
  int ret;
312
 
  unsigned long long x;
 
291
  uint64_t x;
313
292
 
314
 
  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,
315
294
                    AZ_METHOD_BLOCK)))
316
295
  {
317
296
    printf("Could not create test file\n");