~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Andrew Hutchings
  • Date: 2011-02-01 10:23:22 UTC
  • mto: (2136.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2137.
  • Revision ID: andrew@linuxjedi.co.uk-20110201102322-oxztcyrjzg3c7yta
Fix counters cleanup

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>
38
37
 
39
38
#include "CSException.h"
40
39
#include "CSMutex.h"
66
65
 
67
66
void CSMutex::lock()
68
67
{
69
 
        int err = 0;
 
68
        int err;
70
69
 
 
70
        if ((err = pthread_mutex_lock(&iMutex)))
 
71
                CSException::throwOSError(CS_CONTEXT, err);
71
72
#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
 
 
86
73
        iLocker = CSThread::getSelf();
87
74
        if (trace)
88
75
                CSL.logf(iLocker, CSLog::Protocol, "Mutex locked\n");
89
 
#else
90
 
        if ((err = pthread_mutex_lock(&iMutex)))
91
 
                CSException::throwOSError(CS_CONTEXT, err);
92
76
#endif
93
77
}
94
78