1 /* Copyright (c) 2003-2006 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
19 #include <ndb_global.h>
31 typedef CRITICAL_SECTION NdbMutex
;
34 typedef pthread_mutex_t NdbMutex
;
40 * p_mutex: pointer to the mutex structure
41 * returnvalue: pointer to the mutex structure
43 NdbMutex
* NdbMutex_Create(void);
48 * * p_mutex: pointer to the mutex structure
49 * * returnvalue: 0 = succeeded, -1 = failed
51 int NdbMutex_Destroy(NdbMutex
* p_mutex
);
56 * * p_mutex: pointer to the mutex structure
57 * * returnvalue: 0 = succeeded, -1 = failed
59 int NdbMutex_Lock(NdbMutex
* p_mutex
);
64 * * p_mutex: pointer to the mutex structure
65 * * returnvalue: 0 = succeeded, -1 = failed
67 int NdbMutex_Unlock(NdbMutex
* p_mutex
);
72 * * p_mutex: pointer to the mutex structure
73 * * returnvalue: 0 = succeeded, -1 = failed
75 int NdbMutex_Trylock(NdbMutex
* p_mutex
);
85 NdbLockable() { m_mutex
= NdbMutex_Create(); }
86 ~NdbLockable() { NdbMutex_Destroy(m_mutex
); }
88 void lock() { NdbMutex_Lock(m_mutex
); }
89 void unlock(){ NdbMutex_Unlock(m_mutex
);}
90 bool tryLock(){ return NdbMutex_Trylock(m_mutex
) == 0;}
92 NdbMutex
* getMutex() {return m_mutex
;};
100 Guard(NdbMutex
*mtx
) : m_mtx(mtx
) { NdbMutex_Lock(m_mtx
); };
101 Guard(NdbLockable
& l
) : m_mtx(l
.m_mutex
) { NdbMutex_Lock(m_mtx
); };
102 ~Guard() { NdbMutex_Unlock(m_mtx
); };