Exemple #1
0
/* Lock
 *  apply lock
 *
 *  if object is already locked, the operation is idempotent
 *  and returns an rc state of rcLocked
 *
 *  "type" [ IN ] - a KDBPathType
 *  valid values are kptDatabase, kptTable and kptIndex
 *
 *  "path" [ IN ] - NUL terminated path
 */
LIB_EXPORT rc_t CC KDatabaseVLock ( KDatabase *self, uint32_t type, const char *name, va_list args )
{
    rc_t rc = 0;
    char path [ 256 ];

    rc = KDatabaseLockInt (self, path, sizeof path, type, name, args);
    if (rc == 0)
        rc = KDBLockDir (self->dir, path);
    return rc;
}
Exemple #2
0
/* Lock
 *  apply lock
 *
 *  if object is already locked, the operation is idempotent
 *  and returns an rc state of rcLocked
 *
 *  "path" [ IN ] - NUL terminated path
 */
LIB_EXPORT rc_t CC KDBManagerVLock ( KDBManager *self, const char *path, va_list args )
{
    rc_t rc;
    char full [ 4096 ];

    if ( self == NULL )
        rc =  RC ( rcDB, rcMgr, rcLocking, rcSelf, rcNull );
    else
    {
        /* TBD:
           Add code to validate that this path is not in a container
           object's control.  That is the last facet in the path
           is the name of the object.  To be valid the facet before
           must not be "col", "tbl", or "db" as in those cases
           the KDBManager should not be called for this object but 
           its containing object
        */

        /* get full path to object */
        rc = KDirectoryVResolvePath ( self -> wd, true,
            full, sizeof full, path, args );
        if ( rc == 0 )
        {
            /* if the path is not writable because it is already locked
             * the return from this will contain "rcLocked" and the 
             * caller will be forced to check for zero or RCState(rcLocked)
             *
             * a side effect is that if the call does not return 0 it will
             * be a wrong type to lock with the DBManager
             */
            rc = KDBManagerWritableInt ( self -> wd, full );
            if ( rc == 0 )
            {
                rc = KDBManagerCheckOpen ( self, full );
                if ( rc == 0 )
                    rc = KDBLockDir ( self -> wd, full );
            }
        }

        /* return dbmgr context */
        if ( rc != 0 )
            rc = ResetRCContext ( rc, rcDB, rcMgr, rcLocking );
    }

    return rc;
}