api_lib.cc

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB 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 GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021   Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 #include <eyedbconfig.h>
00025 
00026 #include <assert.h>
00027 #include <string.h>
00028 #include "eyedbsm_p.h"
00029 
00030 #include <eyedblib/rpc_lib.h>
00031 #include <lib/m_mem_p.h>
00032 
00033 #include "transaction.h"
00034 
00035 namespace eyedbsm {
00036 
00037   int pgsize, pgsize_pow2;
00038 
00039 #ifdef  _SC_PAGESIZE
00040 #define getpagesize()   sysconf(_SC_PAGESIZE)
00041 #endif
00042 
00043   int
00044   power2(int x)
00045   {
00046     int n, p;
00047 
00048     for (n = 0, p = 0; x; p++)
00049       {
00050         if ((x & 1) && ++n > 1)
00051           return -1;
00052 
00053         x >>= 1;
00054       }
00055 
00056     return p-1;
00057   }
00058 
00059 #define OFFSET(T, X) (unsigned long)(&((T *)0)->X)
00060 
00061 #define CHECK_ALIGN(X) if (!(X)) {fprintf(stderr, "\nInternal error: invalid structure alignment: " #X ".\n\nCannot run eyedb on this architecture.\n\n"); exit(1);}
00062 
00063   static void check_alignments()
00064   {
00065 #if 0
00066     CHECK_ALIGN(OFFSET(MapStat, u) == 8);
00067     CHECK_ALIGN(OFFSET(MapHeader, sizeslot) == 4);
00068     CHECK_ALIGN(OFFSET(MapHeader, mstat) == 24);
00069     CHECK_ALIGN(OFFSET(MapHeader, u) == 56);
00070     CHECK_ALIGN(OFFSET(DatafileDesc, mp.mtype) == 296);
00071     CHECK_ALIGN(OFFSET(DatafileDesc, mp.sizeslot) == 300);
00072     CHECK_ALIGN(OFFSET(DatafileDesc, __lastslot) == 368);
00073     CHECK_ALIGN(OFFSET(DatafileDesc, __dspid) == 372);
00074     CHECK_ALIGN(OFFSET(DbHeader, __magic) == 0);
00075     CHECK_ALIGN(OFFSET(DbHeader, __dbid) == 4);
00076     CHECK_ALIGN(OFFSET(DbHeader, state) == 8);
00077     CHECK_ALIGN(OFFSET(DbHeader, __guest_uid) == 12);
00078     CHECK_ALIGN(OFFSET(DbHeader, __prot_uid_oid) == 16);
00079     CHECK_ALIGN(OFFSET(DbHeader, __prot_list_oid) == 24);
00080     CHECK_ALIGN(OFFSET(DbHeader, __prot_lock_oid) == 32);
00081     CHECK_ALIGN(OFFSET(DbHeader, shmfile) == 40);
00082     CHECK_ALIGN(OFFSET(DbHeader, __nbobjs) == 296);
00083     CHECK_ALIGN(OFFSET(DbHeader, __ndat) == 300);
00084     CHECK_ALIGN(OFFSET(DbHeader, dat) == 304);
00085     CHECK_ALIGN(OFFSET(DbHeader, __ndsp) == 192816);
00086     CHECK_ALIGN(OFFSET(DbHeader, dsp) == 192820);
00087     CHECK_ALIGN(OFFSET(DbHeader, __def_dspid) == 246068);
00088     CHECK_ALIGN(OFFSET(DbHeader, vre) == 246070);
00089     CHECK_ALIGN(OFFSET(DbHeader, __lastidxbusy) == 248632);
00090     CHECK_ALIGN(OFFSET(DbHeader, __curidxbusy) == 248636);
00091     CHECK_ALIGN(OFFSET(DbHeader, __lastidxblkalloc) == 248640);
00092     CHECK_ALIGN(OFFSET(DbHeader, __lastnsblkalloc) == 248644);
00093     CHECK_ALIGN(OFFSET(HIdx::_Idx, key_count) == 12);
00094     CHECK_ALIGN(OFFSET(HIdx::_Idx, dspid) == 16);
00095     CHECK_ALIGN(OFFSET(HIdx::_Idx, keytype) == 20);
00096     CHECK_ALIGN(OFFSET(HIdx::_Idx, keysz) == 24);
00097     CHECK_ALIGN(OFFSET(HIdx::_Idx, datasz) == 28);
00098 #endif
00099   }
00100 
00101   Status init()
00102   {
00103     check_alignments();
00104 
00105     const char *logmask = getenv("IDB_LOG_MASK");
00106     if (logmask) {
00107       utlogInit("", "stderr");
00108       sscanf(logmask, "%llx", &eyedblib::log_mask);
00109     }
00110 
00111     trs_init();
00112     mutexes_init();
00113     pgsize = getpagesize();
00114     pgsize_pow2 = power2(pgsize);
00115     m_init();
00116 
00117     return Success;
00118   }
00119 
00120   Status release()
00121   {
00122     mutexes_release();
00123     return Success;
00124   }
00125 }

Generated on Mon Dec 22 18:15:47 2008 for eyedb by  doxygen 1.5.3