mutex.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1999, 2000
00005  *      Sleepycat Software.  All rights reserved.
00006  */
00007 
00008 #include "config.h"
00009 
00010 #ifndef lint
00011 static const char revid[] = "$Id: mutex_8c-source.html,v 1.1 2008/06/08 10:20:56 sebdiaz Exp $";
00012 #endif /* not lint */
00013 
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 #endif
00017 
00018 #include "db_int.h"
00019 
00020 /*
00021  * CDB___db_mutex_alloc --
00022  *      Allocate and initialize a mutex.
00023  *
00024  * PUBLIC: int CDB___db_mutex_alloc __P((DB_ENV *, REGINFO *, MUTEX **));
00025  */
00026 int
00027 CDB___db_mutex_alloc(dbenv, infop, storep)
00028         DB_ENV *dbenv;
00029         REGINFO *infop;
00030         MUTEX **storep;
00031 {
00032         int ret;
00033 
00034         /*
00035          * If the architecture supports mutexes in heap memory, use that
00036          * memory.  If it doesn't, we have to allocate space in a region.
00037          */
00038 #ifdef MUTEX_NO_MALLOC_LOCKS
00039         R_LOCK(dbenv, infop);
00040         ret = CDB___db_shalloc(infop->addr, sizeof(MUTEX), MUTEX_ALIGN, storep);
00041         R_UNLOCK(dbenv, infop);
00042 #else
00043         COMPQUIET(dbenv, NULL);
00044         COMPQUIET(infop, NULL);
00045         ret = CDB___os_calloc(dbenv, 1, sizeof(MUTEX), storep);
00046 #endif
00047         if (ret != 0)
00048                 CDB___db_err(dbenv, "Unable to allocate memory for mutex");
00049         return (ret);
00050 }
00051 
00052 /*
00053  * CDB___db_mutex_free --
00054  *      Free a mutex.
00055  *
00056  * PUBLIC: void CDB___db_mutex_free __P((DB_ENV *, REGINFO *, MUTEX *));
00057  */
00058 void
00059 CDB___db_mutex_free(dbenv, infop, mutexp)
00060         DB_ENV *dbenv;
00061         REGINFO *infop;
00062         MUTEX *mutexp;
00063 {
00064 #ifdef MUTEX_NO_MALLOC_LOCKS
00065         R_LOCK(dbenv, infop);
00066         CDB___db_shalloc_free(infop->addr, mutexp);
00067         R_UNLOCK(dbenv, infop);
00068 #else
00069         COMPQUIET(dbenv, NULL);
00070         COMPQUIET(infop, NULL);
00071         CDB___os_free(mutexp, sizeof(*mutexp));
00072 #endif
00073 }

Generated on Sun Jun 8 10:56:38 2008 for GNUmifluz by  doxygen 1.5.5