00001 /* Copyright (C) 2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 00018 #include <ndb_global.h> 00019 00020 #include <NdbThread.h> 00021 #include <NdbMutex.h> 00022 #include <NdbMem.h> 00023 00024 NdbMutex* NdbMutex_Create(void) 00025 { 00026 NdbMutex* pNdbMutex; 00027 int result; 00028 DBUG_ENTER("NdbMutex_Create"); 00029 00030 pNdbMutex = (NdbMutex*)NdbMem_Allocate(sizeof(NdbMutex)); 00031 DBUG_PRINT("info",("NdbMem_Allocate 0x%lx",pNdbMutex)); 00032 00033 if (pNdbMutex == NULL) 00034 DBUG_RETURN(NULL); 00035 00036 result = pthread_mutex_init(pNdbMutex, NULL); 00037 assert(result == 0); 00038 00039 DBUG_RETURN(pNdbMutex); 00040 } 00041 00042 00043 int NdbMutex_Destroy(NdbMutex* p_mutex) 00044 { 00045 int result; 00046 DBUG_ENTER("NdbMutex_Destroy"); 00047 00048 if (p_mutex == NULL) 00049 DBUG_RETURN(-1); 00050 00051 result = pthread_mutex_destroy(p_mutex); 00052 00053 DBUG_PRINT("info",("NdbMem_Free 0x%lx",p_mutex)); 00054 NdbMem_Free(p_mutex); 00055 00056 DBUG_RETURN(result); 00057 00058 } 00059 00060 00061 int NdbMutex_Lock(NdbMutex* p_mutex) 00062 { 00063 int result; 00064 00065 if (p_mutex == NULL) 00066 return -1; 00067 00068 result = pthread_mutex_lock(p_mutex); 00069 00070 return result; 00071 } 00072 00073 00074 int NdbMutex_Unlock(NdbMutex* p_mutex) 00075 { 00076 int result; 00077 00078 if (p_mutex == NULL) 00079 return -1; 00080 00081 result = pthread_mutex_unlock(p_mutex); 00082 00083 return result; 00084 } 00085 00086 00087 int NdbMutex_Trylock(NdbMutex* p_mutex) 00088 { 00089 int result = -1; 00090 00091 if (p_mutex != NULL) { 00092 result = pthread_mutex_trylock(p_mutex); 00093 } 00094 00095 return result; 00096 } 00097
1.4.7

