mirror of
https://github.com/MariaDB/server.git
synced 2025-02-02 12:01:42 +01:00
efe5a75d7d
ndb/include/newtonapi/defs/pcn_types.h: portability/autoconf fixes ndb/include/portlib/NdbMutex.h: portability/autoconf fixes ndb/src/common/editline/editline.c: portability/autoconf fixes ndb/src/common/mgmcommon/ConfigRetriever.cpp: portability/autoconf fixes ndb/src/common/portlib/memtest/munmaptest/munmaptest.cpp: portability/autoconf fixes ndb/src/common/portlib/unix/NdbCondition.c: portability/autoconf fixes ndb/src/common/portlib/unix/NdbDaemon.c: portability/autoconf fixes ndb/src/common/portlib/unix/NdbHost.c: portability/autoconf fixes ndb/src/common/util/File.cpp: portability/autoconf fixes ndb/src/common/util/getarg.c: portability/autoconf fixes ndb/src/common/util/strlcat.c: portability/autoconf fixes ndb/src/common/util/strlcpy.c: portability/autoconf fixes ndb/src/cw/cpcd/Process.cpp: portability/autoconf fixes ndb/src/cw/cpcd/common.cpp: portability/autoconf fixes ndb/src/cw/cpcd/main.cpp: portability/autoconf fixes ndb/src/kernel/blocks/dbdict/printSchemafile/printSchemafile.cpp: portability/autoconf fixes ndb/src/kernel/blocks/dbdih/printSysfile/printSysfile.cpp: portability/autoconf fixes ndb/src/kernel/blocks/ndbfs/AsyncFileTest/AsyncFileTest.cpp: portability/autoconf fixes ndb/src/kernel/error/TimeModule.cpp: portability/autoconf fixes ndb/src/kernel/ndb-main/Main.cpp: portability/autoconf fixes ndb/src/mgmsrv/MgmtSrvr.cpp: portability/autoconf fixes ndb/src/mgmsrv/main.cpp: portability/autoconf fixes ndb/test/ndbapi/flexBench/flexBench.cpp: removed warnings ndb/test/src/HugoCalculator.cpp: removed warnings ndb/test/src/HugoOperations.cpp: removed warnings ndb/test/src/HugoTransactions.cpp: removed warnings ndb/test/src/NDBT_ResultRow.cpp: removed warnings ndb/test/src/NdbBackup.cpp: removed warnings ndb/test/src/NdbConfig.cpp: removed warnings ndb/test/src/NdbRestarter.cpp: removed warnings ndb/tools/cpcc/cpcc.cpp: removed warnings
116 lines
2.7 KiB
C++
116 lines
2.7 KiB
C++
/* Copyright (C) 2003 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
#ifndef NDB_MUTEX_H
|
|
#define NDB_MUTEX_H
|
|
|
|
#include <ndb_global.h>
|
|
|
|
#ifdef NDB_WIN32
|
|
#include <winsock2.h>
|
|
#include <ws2tcpip.h>
|
|
#include <windows.h>
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#if defined NDB_OSE || defined NDB_SOFTOSE
|
|
#include <ose.h>
|
|
typedef SEMAPHORE NdbMutex;
|
|
#define NDB_MUTEX_INITIALIZER { 1, 0, 0 }
|
|
#elif defined NDB_WIN32
|
|
typedef CRITICAL_SECTION NdbMutex;
|
|
#else
|
|
#include <my_pthread.h>
|
|
typedef pthread_mutex_t NdbMutex;
|
|
#define NDB_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
|
#endif
|
|
|
|
/**
|
|
* Create a mutex
|
|
*
|
|
* p_mutex: pointer to the mutex structure
|
|
* returnvalue: pointer to the mutex structure
|
|
*/
|
|
NdbMutex* NdbMutex_Create(void);
|
|
|
|
/**
|
|
* Destroy a mutex
|
|
*
|
|
* * p_mutex: pointer to the mutex structure
|
|
* * returnvalue: 0 = succeeded, -1 = failed
|
|
*/
|
|
int NdbMutex_Destroy(NdbMutex* p_mutex);
|
|
|
|
/**
|
|
* Lock a mutex
|
|
*
|
|
* * p_mutex: pointer to the mutex structure
|
|
* * returnvalue: 0 = succeeded, -1 = failed
|
|
*/
|
|
int NdbMutex_Lock(NdbMutex* p_mutex);
|
|
|
|
/**
|
|
* Unlock a mutex
|
|
*
|
|
* * p_mutex: pointer to the mutex structure
|
|
* * returnvalue: 0 = succeeded, -1 = failed
|
|
*/
|
|
int NdbMutex_Unlock(NdbMutex* p_mutex);
|
|
|
|
/**
|
|
* Try to lock a mutex
|
|
*
|
|
* * p_mutex: pointer to the mutex structure
|
|
* * returnvalue: 0 = succeeded, -1 = failed
|
|
*/
|
|
int NdbMutex_Trylock(NdbMutex* p_mutex);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
class NdbLockable {
|
|
friend class Guard;
|
|
public:
|
|
NdbLockable() { m_mutex = NdbMutex_Create(); }
|
|
~NdbLockable() { NdbMutex_Destroy(m_mutex); }
|
|
|
|
void lock() { NdbMutex_Lock(m_mutex); }
|
|
void unlock(){ NdbMutex_Unlock(m_mutex);}
|
|
bool tryLock(){ return NdbMutex_Trylock(m_mutex) == 0;}
|
|
|
|
NdbMutex* getMutex() {return m_mutex;};
|
|
|
|
protected:
|
|
NdbMutex * m_mutex;
|
|
};
|
|
|
|
class Guard {
|
|
public:
|
|
Guard(NdbMutex *mtx) : m_mtx(mtx) { NdbMutex_Lock(m_mtx); };
|
|
Guard(NdbLockable & l) : m_mtx(l.m_mutex) { NdbMutex_Lock(m_mtx); };
|
|
~Guard() { NdbMutex_Unlock(m_mtx); };
|
|
private:
|
|
NdbMutex *m_mtx;
|
|
};
|
|
|
|
#endif
|
|
|
|
#endif
|