~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Lee Bieber
  • Date: 2010-10-22 16:47:38 UTC
  • mfrom: (1841.1.7 drizzle_pbms)
  • Revision ID: kalebral@gmail.com-20101022164738-vv8w22b8towpb307
Merge Barry - fix bug 657830: PBMS build failure in GCC 4.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
31
34
#include <sys/time.h>
 
35
#endif
 
36
 
32
37
 
33
38
#include "CSException.h"
34
39
#include "CSMutex.h"
35
40
#include "CSGlobal.h"
 
41
#include "CSLog.h"
36
42
 
37
43
/*
38
44
 * ---------------------------------------------------------------
40
46
 */
41
47
 
42
48
CSMutex::CSMutex()
 
49
#ifdef DEBUG
 
50
:
 
51
iLocker(NULL),
 
52
trace(false)
 
53
#endif
43
54
{
44
55
        int err;
45
56
 
58
69
 
59
70
        if ((err = pthread_mutex_lock(&iMutex)))
60
71
                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
61
77
}
62
78
 
63
79
void CSMutex::unlock()
64
80
{
 
81
#ifdef DEBUG
 
82
        if (trace)
 
83
                CSL.logf(iLocker, CSLog::Protocol, "Mutex unlocked\n");
 
84
        iLocker = NULL;
 
85
#endif
65
86
        pthread_mutex_unlock(&iMutex);
66
87
}
67
88
 
154
175
        struct timespec abstime;
155
176
        int                             lock_count;
156
177
        int                             err;
 
178
        uint64_t                micro_sec;
157
179
 
158
180
        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
173
181
        struct timeval  now;
174
 
        uint64_t                        micro_sec;
175
182
 
176
183
        /* Get the current time in microseconds: */
177
184
        gettimeofday(&now, NULL);
183
190
        /* Setup the end time, which is in nano-seconds. */
184
191
        abstime.tv_sec = (long) (micro_sec / 1000000);                          /* seconds */
185
192
        abstime.tv_nsec = (long) ((micro_sec % 1000000) * 1000);        /* and nanoseconds */
186
 
#endif
 
193
 
187
194
        ASSERT(iLockingThread == self);
188
195
        lock_count = iLockCount;
189
196
        iLockCount = 0;