00001 /*************************************************************************** 00002 * Copyright (C) 2007 by www.databasecache.com * 00003 * Contact: praba_tuty@databasecache.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 ***************************************************************************/ 00016 #ifndef MUTEX_H 00017 #define MUTEX_H 00018 #include<os.h> 00019 #if defined(sparc) 00020 typedef unsigned char Lock; 00021 #elif defined (i686) 00022 typedef unsigned int Lock; 00023 #endif 00024 class Mutex 00025 { 00026 00027 #if defined(sparc) || defined(i686) 00028 Lock lock; 00029 #else 00030 pthread_mutex_t mutex_; 00031 #endif 00032 public: 00033 char name[20]; 00034 Mutex(); 00035 int init(); 00036 int init(char *name); 00037 int tryLock(int tries=0, int waitmsecs=0); 00038 int getLock(int procSlot, bool procAccount=true); 00039 int releaseLock(int procSlot, bool procAccount=true); 00040 int destroy(); 00041 }; 00042 00043 #endif