~codership/galera/2.x

« back to all changes in this revision

Viewing changes to galera/src/monitor.hpp

  • Committer: Alexey Yurchenko
  • Date: 2014-01-29 14:43:26 UTC
  • mto: This revision was merged to the branch mainline in revision 167.
  • Revision ID: alexey.yurchenko@codership.com-20140129144326-aa70nhzofl0smkm8
Fixes:
* provider pause() is fixed to avoid potential deadlock with replicating threads.
* lp:1099478 - handle own address in the address list properly (do not throw exception)
* lp:1259952 - fixed allocation of multiple of pages when posix_fallocate() is unavailable
* lp:1261996 - fixed compilation on Solaris 11
* lp:1232747 - fixed group remerge after partitioning event

Synced with SVN r3450

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
            entered_(0),
57
57
            oooe_(0),
58
58
            oool_(0),
59
 
            win_size_(0),
60
 
            locked_(false)
 
59
            win_size_(0)
61
60
        { }
62
61
 
63
62
        ~Monitor()
255
254
            cond_.broadcast();
256
255
        }
257
256
 
258
 
        /*! Locks the monitor and/or increments lock counter;
259
 
         *  throws EALREADY if the monitor is already locked */
260
 
        void lock()
261
 
        {
262
 
            gu::Lock lock(mutex_);
263
 
 
264
 
            assert(locked_ >= 0);
265
 
 
266
 
            if (locked_ > 0)
267
 
            {
268
 
                log_warn << "Attempt to lock an already locked monitor.";
269
 
                locked_++;
270
 
                if (locked_ > 0)
271
 
                {
272
 
                    gu_throw_error(EALREADY);
273
 
                }
274
 
                else
275
 
                {
276
 
                    gu_throw_fatal << "More than " << (locked_ - 1)
277
 
                                   << " concurrent locks.";
278
 
                }
279
 
            }
280
 
 
281
 
            if (last_entered_ != -1)
282
 
            {
283
 
                while (drain_seqno_ != LLONG_MAX) lock.wait(cond_);
284
 
                /*! @note: last_entered_ probably changed since last check */
285
 
                drain_common(last_entered_, lock);
286
 
                /* would_block() should return true when drain_seqno_ is set
287
 
                 * so the monitor should be totally empty at this point. */
288
 
            }
289
 
 
290
 
            locked_ = 1;
291
 
 
292
 
            log_debug << "Locked local monitor at " << (last_left_ + 1);
293
 
        }
294
 
 
295
 
        /*! Decrements lock counter and unlocks monitor if counter is 0;
296
 
         *  throws EBUSY if lock counter is not 0 */
297
 
        void unlock()
298
 
        {
299
 
            gu::Lock lock(mutex_);
300
 
 
301
 
            assert (locked_ >= 0);
302
 
 
303
 
            if (0 == locked_)
304
 
            {
305
 
                assert (locked_ != 0);
306
 
                gu_throw_error(EALREADY)
307
 
                    << "Attempt to unlock an already unlocked monitor";
308
 
            }
309
 
 
310
 
            locked_--;
311
 
 
312
 
            if (0 == locked_)
313
 
            {
314
 
                update_last_left();
315
 
 
316
 
                drain_seqno_ = LLONG_MAX;
317
 
                cond_.broadcast();
318
 
 
319
 
                log_debug << "Unlocked local monitor at " << last_left_;
320
 
            }
321
 
            else
322
 
            {
323
 
                gu_throw_error(EBUSY);
324
 
            }
325
 
        }
326
 
 
327
257
        void wait(wsrep_seqno_t seqno)
328
258
        {
329
259
            gu::Lock lock(mutex_);
503
433
        long oooe_;     // out of order entered
504
434
        long oool_;     // out of order left
505
435
        long win_size_; // window between last_left_ and last_entered_
506
 
        int  locked_;
507
436
    };
508
437
}
509
438