/[svn]/linuxsampler/trunk/src/common/Mutex.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/common/Mutex.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2499 by persson, Sat Mar 2 07:03:04 2013 UTC revision 2500 by schoenebeck, Fri Jan 10 12:20:05 2014 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2013 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2014 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 101  class Mutex { Line 101  class Mutex {
101  // Lock guard for exception safe locking  // Lock guard for exception safe locking
102  class LockGuard {  class LockGuard {
103  public:  public:
104      LockGuard(Mutex& m) : pm(m) {      LockGuard(Mutex& m) : pm(&m) {
105          m.Lock();          m.Lock();
106      }      }
107    
108        /**
109         * Empty LockGuard. This constructor can be used to implement conditional
110         * mutex protection like:
111         * @code
112         * Mutex m;
113         * LockGuard g;
114         * if (requiresMutexProtection()) g = LockGuard(m);
115         * @endcode
116         */
117        LockGuard() : pm(NULL) {
118        }
119    
120        LockGuard(LockGuard& g) : pm(g.pm) {
121            if (pm) pm->Lock();
122        }
123    
124      ~LockGuard() {      ~LockGuard() {
125          pm.Unlock();          if (pm) pm->Unlock();
126      }      }
127  private:  private:
128      Mutex& pm;      Mutex* pm;
129  };  };
130    
131  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2499  
changed lines
  Added in v.2500

  ViewVC Help
Powered by ViewVC