~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Mark Atwood
  • Date: 2011-08-12 04:08:33 UTC
  • mfrom: (2385.2.17 refactor5)
  • Revision ID: me@mark.atwood.name-20110812040833-u6j85nc6ahuc0dtz
mergeĀ lp:~olafvdspek/drizzle/refactor5

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include <sys/time.h>
35
35
#endif
36
36
 
 
37
#include <unistd.h>
37
38
 
38
39
#include "CSException.h"
39
40
#include "CSMutex.h"
65
66
 
66
67
void CSMutex::lock()
67
68
{
68
 
        int err;
 
69
        int err = 0;
69
70
 
70
 
        if ((err = pthread_mutex_lock(&iMutex)))
71
 
                CSException::throwOSError(CS_CONTEXT, err);
72
71
#ifdef DEBUG
 
72
        int waiting = 2000;
 
73
        while (((err = pthread_mutex_trylock(&iMutex)) == EBUSY) && (waiting > 0)) {
 
74
                usleep(500);
 
75
                waiting--;
 
76
        }
 
77
        if (err) {
 
78
                if (err == EBUSY) {
 
79
                        CSL.logf(iLocker, CSLog::Protocol, "Thread holding lock.\n");
 
80
                }
 
81
                
 
82
                if ((err) || (err = pthread_mutex_lock(&iMutex)))
 
83
                        CSException::throwOSError(CS_CONTEXT, err);
 
84
        }
 
85
 
73
86
        iLocker = CSThread::getSelf();
74
87
        if (trace)
75
88
                CSL.logf(iLocker, CSLog::Protocol, "Mutex locked\n");
 
89
#else
 
90
        if ((err = pthread_mutex_lock(&iMutex)))
 
91
                CSException::throwOSError(CS_CONTEXT, err);
76
92
#endif
77
93
}
78
94