~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSMutex.cc

  • Committer: lbieber
  • Date: 2010-10-06 16:34:16 UTC
  • mfrom: (1816.1.3 build)
  • Revision ID: lbieber@orisndriz08-20101006163416-ea0sl59qgpglk21y
Merge Monty - Change the requirement from either libinnodb to libhaildb. Also, tied it to version 2.2
Merge Andrew - fix bug 650935: remove --compress from all clients
Merge Andrew - fix bug 653471: Add -A to drizzle client
Merge Travis - 621861 = To change C structs to C++ classes in Drizzle

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
2
2
 *
3
3
 * PrimeBase Media Stream for MySQL
4
4
 *
28
28
#include "CSConfig.h"
29
29
 
30
30
#include <assert.h>
31
 
#ifdef OS_WINDOWS
32
 
extern int gettimeofday(struct timeval *tv, struct timezone *tz);
33
 
#else
34
31
#include <sys/time.h>
35
 
#endif
36
 
 
37
32
 
38
33
#include "CSException.h"
39
34
#include "CSMutex.h"
40
35
#include "CSGlobal.h"
41
 
#include "CSLog.h"
42
36
 
43
37
/*
44
38
 * ---------------------------------------------------------------
46
40
 */
47
41
 
48
42
CSMutex::CSMutex()
49
 
#ifdef DEBUG
50
 
:
51
 
iLocker(NULL),
52
 
trace(false)
53
 
#endif
54
43
{
55
44
        int err;
56
45
 
69
58
 
70
59
        if ((err = pthread_mutex_lock(&iMutex)))
71
60
                CSException::throwOSError(CS_CONTEXT, err);
72
 
#ifdef DEBUG
73
 
        iLocker = CSThread::getSelf();
74
 
        if (trace)
75
 
                CSL.logf(iLocker, CSLog::Protocol, "Mutex locked\n");
76
 
#endif
77
61
}
78
62
 
79
63
void CSMutex::unlock()
80
64
{
81
 
#ifdef DEBUG
82
 
        if (trace)
83
 
                CSL.logf(iLocker, CSLog::Protocol, "Mutex unlocked\n");
84
 
        iLocker = NULL;
85
 
#endif
86
65
        pthread_mutex_unlock(&iMutex);
87
66
}
88
67
 
175
154
        struct timespec abstime;
176
155
        int                             lock_count;
177
156
        int                             err;
178
 
        uint64_t                micro_sec;
179
157
 
180
158
        enter_();
 
159
#ifdef XT_WIN
 
160
        union ft64              now;
 
161
  
 
162
        GetSystemTimeAsFileTime(&now.ft);
 
163
 
 
164
        /* System time is measured in 100ns units.
 
165
         * This calculation will be reversed by the Windows implementation
 
166
         * of pthread_cond_timedwait(), in order to extract the
 
167
         * milli-second timeout!
 
168
         */
 
169
        abstime.tv.i64 = now.i64 + (milli_sec * 10000);
 
170
  
 
171
        abstime.max_timeout_msec = milli_sec;
 
172
#else
181
173
        struct timeval  now;
 
174
        uint64_t                        micro_sec;
182
175
 
183
176
        /* Get the current time in microseconds: */
184
177
        gettimeofday(&now, NULL);
190
183
        /* Setup the end time, which is in nano-seconds. */
191
184
        abstime.tv_sec = (long) (micro_sec / 1000000);                          /* seconds */
192
185
        abstime.tv_nsec = (long) ((micro_sec % 1000000) * 1000);        /* and nanoseconds */
193
 
 
 
186
#endif
194
187
        ASSERT(iLockingThread == self);
195
188
        lock_count = iLockCount;
196
189
        iLockCount = 0;