Пример #1
0
/*
** Initialize the mutex system.
*/
        static int sqlite3MutexInit()
        {
            int rc = SQLITE_OK;

            if (sqlite3GlobalConfig.bCoreMutex)
            {
                if (sqlite3GlobalConfig.mutex.xMutexAlloc != null)
                {
/* If the xMutexAlloc method has not been set, then the user did not
** install a mutex implementation via sqlite3_config() prior to
** sqlite3_initialize() being called. This block copies pointers to
** the default implementation into the sqlite3Config structure.
**
*/
                    sqlite3_mutex_methods p   = sqlite3DefaultMutex();
                    sqlite3_mutex_methods pTo = sqlite3GlobalConfig.mutex;

                    memcpy(pTo, pFrom, offsetof(sqlite3_mutex_methods, xMutexAlloc));
                    memcpy(&pTo->xMutexFree, &pFrom->xMutexFree,
                           sizeof(*pTo) - offsetof(sqlite3_mutex_methods, xMutexFree));
                    pTo->xMutexAlloc = pFrom->xMutexAlloc;
                }
                rc = sqlite3GlobalConfig.mutex.xMutexInit();
            }
#if SQLITE_DEBUG
            GLOBAL(int, mutexIsInit) = 1;
#endif

            return(rc);
        }
Пример #2
0
/*
** Initialize the mutex system.
*/
        static int sqlite3MutexInit()
        {
            int rc = SQLITE_OK;

            if (null == sqlite3GlobalConfig.mutex.xMutexAlloc)
            {
                /* If the xMutexAlloc method has not been set, then the user did not
                ** install a mutex implementation via sqlite3_config() prior to
                ** sqlite3_initialize() being called. This block copies pointers to
                ** the default implementation into the sqlite3GlobalConfig structure.
                */
                sqlite3_mutex_methods pFrom;
                sqlite3_mutex_methods pTo = sqlite3GlobalConfig.mutex;

                if (sqlite3GlobalConfig.bCoreMutex)
                {
                    pFrom = sqlite3DefaultMutex();
                }
                else
                {
                    pFrom = sqlite3NoopMutex();
                }
                //memcpy(pTo, pFrom, offsetof(sqlite3_mutex_methods, xMutexAlloc));
                //memcpy(pTo.xMutexFree, pFrom.xMutexFree,
                //	   sizeof(*pTo) - offsetof(sqlite3_mutex_methods, xMutexFree));
                pTo.Copy(pFrom);
            }
            rc = sqlite3GlobalConfig.mutex.xMutexInit();

#if SQLITE_DEBUG
            mutexIsInit = 1; //GLOBAL(int, mutexIsInit) = 1;
#endif

            return(rc);
        }
Пример #3
0
        private static sqlite3_mutex_methods sqlite3NoopMutex()
        {
            sqlite3_mutex_methods sMutex = new sqlite3_mutex_methods(
                (dxMutexInit)debugMutexInit,
                (dxMutexEnd)debugMutexEnd,
                (dxMutexAlloc)debugMutexAlloc,
                (dxMutexFree)debugMutexFree,
                (dxMutexEnter)debugMutexEnter,
                (dxMutexTry)debugMutexTry,
                (dxMutexLeave)debugMutexLeave,

                (dxMutexHeld)debugMutexHeld,
                (dxMutexNotheld)debugMutexNotheld
                );

            return(sMutex);
        }
Пример #4
0
 static sqlite3_mutex_methods va_arg(object[] ap, sqlite3_mutex_methods sysType)
 {
     return((sqlite3_mutex_methods)ap[vaNEXT++]);
 }
Пример #5
0
//Copy sqlite3_mutex_methods from existing 
      public void Copy( sqlite3_mutex_methods cp )
      {
        Debug.Assert( cp != null );
        this.xMutexInit = cp.xMutexInit;
        this.xMutexEnd = cp.xMutexEnd;
        this.xMutexAlloc = cp.xMutexAlloc;
        this.xMutexFree = cp.xMutexFree;
        this.xMutexEnter = cp.xMutexEnter;
        this.xMutexTry = cp.xMutexTry;
        this.xMutexLeave = cp.xMutexLeave;
        this.xMutexHeld = cp.xMutexHeld;
        this.xMutexNotheld = cp.xMutexNotheld;
      }
Пример #6
0
 static int sqlite3_config( int op, ref sqlite3_mutex_methods ap )
 {
   //  va_list ap;
   int rc = SQLITE_OK;
   switch ( op )
   {
     case SQLITE_CONFIG_GETMUTEX:
       {
         /* Retrieve the current mutex implementation */
         ap = sqlite3GlobalConfig.mutex;// *va_arg(ap, sqlite3_mutex_methods) =  sqlite3GlobalConfig.mutex;
         break;
       }
   }
   return rc;
 }
Пример #7
0
 static int sqlite3_config( int op, sqlite3_mutex_methods ap )
 {
   //  va_list ap;
   int rc = SQLITE_OK;
   switch ( op )
   {
     case SQLITE_CONFIG_MUTEX:
       {
         /* Specify an alternative mutex implementation */
         sqlite3GlobalConfig.mutex = ap;// (sqlite3_mutex_methods)va_arg( ap, "sqlite3_mutex_methods" );
         break;
       }
   }
   return rc;
 }
Пример #8
0
        static sqlite3_mutex_methods sqlite3NoopMutex()
        {
            sqlite3_mutex_methods sMutex = new sqlite3_mutex_methods(
              (dxMutexInit)debugMutexInit,
              (dxMutexEnd)debugMutexEnd,
              (dxMutexAlloc)debugMutexAlloc,
              (dxMutexFree)debugMutexFree,
              (dxMutexEnter)debugMutexEnter,
              (dxMutexTry)debugMutexTry,
              (dxMutexLeave)debugMutexLeave,

              (dxMutexHeld)debugMutexHeld,
              (dxMutexNotheld)debugMutexNotheld
              );

              return sMutex;
        }
Пример #9
0
        /*
        ** install_mutex_counters BOOLEAN
        */
        static int test_install_mutex_counters(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            int  rc        = SQLITE_OK;
            bool isInstall = false;

            sqlite3_mutex_methods counter_methods = new sqlite3_mutex_methods(
                (dxMutexInit)counterMutexInit,
                (dxMutexEnd)counterMutexEnd,
                (dxMutexAlloc)counterMutexAlloc,
                (dxMutexFree)counterMutexFree,
                (dxMutexEnter)counterMutexEnter,
                (dxMutexTry)counterMutexTry,
                (dxMutexLeave)counterMutexLeave,
                (dxMutexHeld)counterMutexHeld,
                (dxMutexNotheld)counterMutexNotheld
                );

            if (objc != 2)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN");
                return(TCL.TCL_ERROR);
            }
            if (TCL.Tcl_GetBoolean(interp, objv[1], out isInstall))
            {
                return(TCL.TCL_ERROR);
            }

            Debug.Assert(isInstall == false || isInstall == true);
            Debug.Assert(g.isInstalled == false || g.isInstalled == true);
            if (isInstall == g.isInstalled)
            {
                TCL.Tcl_AppendResult(interp, "mutex counters are ");
                TCL.Tcl_AppendResult(interp, isInstall ? "already installed" : "not installed");
                return(TCL.TCL_ERROR);
            }

            if (isInstall)
            {
                Debug.Assert(g.m.xMutexAlloc == null);
                rc = sqlite3_config(SQLITE_CONFIG_GETMUTEX, ref g.m);
                if (rc == SQLITE_OK)
                {
                    sqlite3_config(SQLITE_CONFIG_MUTEX, counter_methods);
                }
                g.disableTry = false;
            }
            else
            {
                Debug.Assert(g.m.xMutexAlloc != null);
                rc  = sqlite3_config(SQLITE_CONFIG_MUTEX, g.m);
                g.m = new sqlite3_mutex_methods();//        memset( &g.m, 0, sizeof( sqlite3_mutex_methods ) );
            }

            if (rc == SQLITE_OK)
            {
                g.isInstalled = isInstall;
            }

            TCL.Tcl_SetResult(interp, sqlite3TestErrorName(rc), TCL.TCL_VOLATILE);
            return(TCL.TCL_OK);
        }
Пример #10
0
    /*
    ** install_mutex_counters BOOLEAN
    */
    static int test_install_mutex_counters(
    object clientdata,
    Tcl_Interp interp,
    int objc,
    Tcl_Obj[] objv
    )
    {
      int rc = SQLITE_OK;
      bool isInstall = false;

      sqlite3_mutex_methods counter_methods = new sqlite3_mutex_methods(
      (dxMutexInit)counterMutexInit,
      (dxMutexEnd)counterMutexEnd,
      (dxMutexAlloc)counterMutexAlloc,
      (dxMutexFree)counterMutexFree,
      (dxMutexEnter)counterMutexEnter,
      (dxMutexTry)counterMutexTry,
      (dxMutexLeave)counterMutexLeave,
      (dxMutexHeld)counterMutexHeld,
      (dxMutexNotheld)counterMutexNotheld
      );

      if ( objc != 2 )
      {
        TCL.Tcl_WrongNumArgs( interp, 1, objv, "BOOLEAN" );
        return TCL.TCL_ERROR;
      }
      if ( TCL.Tcl_GetBoolean( interp, objv[1], out isInstall ))
      {
        return TCL.TCL_ERROR;
      }

      Debug.Assert( isInstall == false || isInstall == true );
      Debug.Assert( g.isInstalled == false || g.isInstalled == true );
      if ( isInstall == g.isInstalled )
      {
        TCL.Tcl_AppendResult( interp, "mutex counters are " );
        TCL.Tcl_AppendResult( interp, isInstall ? "already installed" : "not installed" );
        return TCL.TCL_ERROR;
      }

      if ( isInstall )
      {
        Debug.Assert( g.m.xMutexAlloc == null );
        rc = sqlite3_config( SQLITE_CONFIG_GETMUTEX, ref g.m );
        if ( rc == SQLITE_OK )
        {
          sqlite3_config( SQLITE_CONFIG_MUTEX, counter_methods );
        }
        g.disableTry = false;
      }
      else
      {
        Debug.Assert( g.m.xMutexAlloc != null );
        rc = sqlite3_config( SQLITE_CONFIG_MUTEX, g.m );
        g.m = new sqlite3_mutex_methods();//        memset( &g.m, 0, sizeof( sqlite3_mutex_methods ) );
      }

      if ( rc == SQLITE_OK )
      {
        g.isInstalled = isInstall;
      }

      TCL.Tcl_SetResult( interp, sqlite3TestErrorName( rc ), TCL.TCL_VOLATILE );
      return TCL.TCL_OK;
    }