~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/concurrency_test.c

  • Committer: Toru Maesaka
  • Date: 2008-07-17 05:59:20 UTC
  • mto: (202.1.1 toru)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: dev@torum.net-20080717055920-10okif50x6nh7b1d
forgot to bzr-add new files in the previous push

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
 
#include <mysys/my_getopt.h>
 
5
#include <drizzle.h>
 
6
#include <my_getopt.h>
 
7
#include <drizzle_version.h>
7
8
#include <stdio.h>
8
9
#include <stdlib.h>
9
10
#include <sys/types.h>
13
14
#include <fcntl.h>
14
15
#include <sys/time.h>
15
16
#include <pthread.h>
16
 
#include <string.h>                             /* Pull in memset() */
 
17
#include <strings.h>
17
18
#ifndef __WIN__
18
19
#include <sys/wait.h>
19
20
#endif
40
41
unsigned int master_wakeup;
41
42
pthread_mutex_t sleeper_mutex;
42
43
pthread_cond_t sleep_threshhold;
43
 
static bool timer_alarm= false;
 
44
static my_bool timer_alarm= false;
44
45
pthread_mutex_t timer_alarm_mutex;
45
46
pthread_cond_t timer_alarm_threshold;
46
47
 
87
88
  if (argc > 1)
88
89
    exit(1);
89
90
 
 
91
  if (!(mysql_thread_safe()))
 
92
      fprintf(stderr, "This application was compiled incorrectly. Please recompile with thread support.\n");
 
93
 
90
94
  srandom(time(NULL));
91
95
 
92
96
  pthread_mutex_init(&counter_mutex, NULL);
93
97
  pthread_cond_init(&count_threshhold, NULL);
94
98
  pthread_mutex_init(&sleeper_mutex, NULL);
95
99
  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);
 
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));
99
103
 
100
104
  for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
101
105
    scheduler(method);
104
108
  (void)pthread_cond_destroy(&count_threshhold);
105
109
  (void)pthread_mutex_destroy(&sleeper_mutex);
106
110
  (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);
 
111
  VOID(pthread_mutex_destroy(&timer_alarm_mutex));
 
112
  VOID(pthread_cond_destroy(&timer_alarm_threshold));
 
113
  VOID(pthread_mutex_destroy(&row_lock));
110
114
 
111
115
  return 0;
112
116
}
134
138
  pthread_mutex_unlock(&sleeper_mutex);
135
139
 
136
140
  context= (thread_context_st *)malloc(sizeof(thread_context_st) * DEFAULT_CONCURRENCY);
137
 
  memset(context, 0, sizeof(thread_context_st) * DEFAULT_CONCURRENCY);
 
141
  bzero(context, sizeof(thread_context_st) * DEFAULT_CONCURRENCY);
138
142
 
139
143
  if (!context)
140
144
  {
191
195
  {
192
196
    struct timespec abstime;
193
197
 
194
 
    memset(&abstime, 0, sizeof(struct timespec));
 
198
    bzero(&abstime, sizeof(struct timespec));
195
199
    abstime.tv_sec= 1;
196
200
 
197
201
    pthread_cond_timedwait(&count_threshhold, &counter_mutex, &abstime);
212
216
  time_t *timer_length= (time_t *)p;
213
217
  struct timespec abstime;
214
218
 
 
219
  if (mysql_thread_init())
 
220
  {
 
221
    fprintf(stderr,"%s: mysql_thread_init() failed.\n",
 
222
            my_progname);
 
223
    exit(1);
 
224
  }
 
225
 
215
226
  /* 
216
227
    We lock around the initial call in case were we in a loop. This 
217
228
    also keeps the value properly syncronized across call threads.
233
244
  timer_alarm= false;
234
245
  pthread_mutex_unlock(&timer_alarm_mutex);
235
246
 
 
247
  mysql_thread_end();
 
248
 
236
249
  return 0;
237
250
}
238
251
 
244
257
  int error;
245
258
  azio_stream reader_handle;
246
259
 
 
260
  if (mysql_thread_init())
 
261
  {
 
262
    fprintf(stderr,"%s: mysql_thread_init() failed.\n", my_progname);
 
263
    exit(1);
 
264
  }
 
265
 
247
266
  if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
248
267
                    context->use_aio)))
249
268
  {
282
301
  pthread_mutex_unlock(&counter_mutex);
283
302
  azclose(&reader_handle);
284
303
 
 
304
  mysql_thread_end();
 
305
 
285
306
  return NULL;
286
307
}
287
308