Esempio n. 1
0
void dbc_change_thread_support( DMHDBC connection, int level )
{
#if defined ( HAVE_LIBPTHREAD ) || defined( HAVE_LIBTHREAD ) || defined( HAVE_LIBPTH )
    int old_level;

    if ( connection -> protection_level == level )
	return;

    old_level =  connection -> protection_level;
    connection -> protection_level = level;

    if ( level == TS_LEVEL3 )
    {
	/*
         * if we are moving from level 3 we may have to release the existing
         * connection lock, and create the env lock
         */
	if(old_level != TS_LEVEL0)
            mutex_exit( &connection -> mutex );
        mutex_entry( &mutex_env );
    }
    else if ( old_level == TS_LEVEL3 )
    {
         /*
         * if we are moving from level 3 we may have to create the new
         * connection lock, and remove the env lock
         */
	if(level != TS_LEVEL0)
	    mutex_entry( &connection -> mutex );
        mutex_exit( &mutex_env );
    }

#endif
}
Esempio n. 2
0
void thread_protect( int type, void *handle )
{
    DMHDBC connection;
    DMHSTMT statement;
    DMHDESC descriptor;

    switch( type )
    {
      case SQL_HANDLE_ENV:
        mutex_entry( &mutex_env );
        break;

      case SQL_HANDLE_DBC:
        connection = handle;
        if ( connection -> protection_level == TS_LEVEL3 )
        {
            mutex_entry( &mutex_env );
        }
        else if ( connection -> protection_level == TS_LEVEL2 ||
                connection -> protection_level == TS_LEVEL1 )
        {
            mutex_entry( &connection -> mutex );
        }
        break;

      case SQL_HANDLE_STMT:
        statement = handle;
        if ( statement -> connection -> protection_level == TS_LEVEL3 )
        {
            mutex_entry( &mutex_env );
        }
        else if ( statement -> connection -> protection_level == TS_LEVEL2 )
        {
            mutex_entry( &statement -> connection -> mutex );
        }
        else if ( statement -> connection -> protection_level == TS_LEVEL1 )
        {
            mutex_entry( &statement -> mutex );
        }
        break;

      case SQL_HANDLE_DESC:
        descriptor = handle;
        if ( descriptor -> connection -> protection_level == TS_LEVEL3 )
        {
            mutex_entry( &mutex_env );
        }
        if ( descriptor -> connection -> protection_level == TS_LEVEL2 )
        {
            mutex_entry( &descriptor -> connection -> mutex );
        }
        if ( descriptor -> connection -> protection_level == TS_LEVEL1 )
        {
            mutex_entry( &descriptor -> mutex );
        }
        break;
    }
}
static int save_ini_cache( int ret,
                    LPCSTR  pszSection,
                    LPCSTR  pszEntry,
                    LPCSTR  pszDefault,
                    LPSTR   pRetBuffer,
                    int     nRetBuffer,
                    LPCSTR  pszFileName )
{
	int rval, cval;

	mutex_entry( &mutex_ini );

	/*
	 * check its not been inserted since the last check
	 */

	if ( !_check_ini_cache( &cval, pszSection, pszEntry, pszDefault,
			pRetBuffer, nRetBuffer, pszFileName )) {

		rval = _save_ini_cache( ret, pszSection, pszEntry, pszDefault,
			pRetBuffer, nRetBuffer, pszFileName );
	}

	mutex_exit( &mutex_ini );

	return rval;
}
Esempio n. 4
0
int __validate_desc( DMHDESC descriptor )
{
#ifdef FAST_HANDLE_VALIDATE

    if ( *(( int * ) descriptor ) == HDESC_MAGIC )
        return 1;
    else
        return 0;

#else

    DMHDESC ptr;
    int ret = 0;

    mutex_entry( &mutex_lists );

    ptr = descriptor_root;

    while( ptr )
    {
        if ( ptr == descriptor )
        {
            ret = 1;
            break;
        }

        ptr = ptr -> next_class_list;
    }

    mutex_exit( &mutex_lists );

    return ret;

#endif
}
Esempio n. 5
0
int __validate_dbc( DMHDBC connection )
{
#ifdef FAST_HANDLE_VALIDATE
    if ( *(( int * ) connection ) == HDBC_MAGIC )
        return 1;
    else
        return 0;

#else

    DMHDBC ptr;
    int ret = 0;

    mutex_entry( &mutex_lists );

    ptr = connection_root;

    while( ptr )
    {
        if ( ptr == connection )
        {
            ret = 1;
            break;
        }

        ptr = ptr -> next_class_list;
    }

    mutex_exit( &mutex_lists );

    return ret;
#endif
}
Esempio n. 6
0
int __validate_env( DMHENV env )
{
#ifdef FAST_HANDLE_VALIDATE

    if ( *(( int * ) env ) == HENV_MAGIC )
        return 1;
    else
        return 0;
#else

    DMHENV ptr;
    int ret = 0;

    mutex_entry( &mutex_lists );

    ptr = enviroment_root;

    while( ptr )
    {
        if ( ptr == env )
        {
            ret = 1;
            break;
        }

        ptr = ptr -> next_class_list;
    }

    mutex_exit( &mutex_lists );

    return ret;

#endif
}
Esempio n. 7
0
int __validate_stmt( DMHSTMT statement )
{
#ifdef FAST_HANDLE_VALIDATE

    if ( statement && *(( int * ) statement ) == HSTMT_MAGIC )
        return 1;
    else
        return 0;

#else

    DMHSTMT ptr;
    int ret = 0;

    mutex_entry( &mutex_lists );

    ptr = statement_root;

    while( ptr )
    {
        if ( ptr == statement )
        {
            ret = 1;
            break;
        }

        ptr = ptr -> next_class_list;
    }

    mutex_exit( &mutex_lists );

    return ret;

#endif
}
Esempio n. 8
0
void __release_env( DMHENV environment )
{
    DMHENV last = NULL;
    DMHENV ptr;

    mutex_entry( &mutex_lists );

    ptr = enviroment_root;

    while( ptr )
    {
        if ( environment == ptr )
        {
            break;
        }
        last = ptr;
        ptr = ptr -> next_class_list;
    }

    if ( ptr )
    {
        if ( last )
        {
            last -> next_class_list = ptr -> next_class_list;
        }
        else
        {
            enviroment_root = ptr -> next_class_list;
        }
    }

    clear_error_head( &environment -> error );

	/*
	 * free log
	 */

    dm_log_close();

#if defined ( COLLECT_STATS ) && defined( HAVE_SYS_SEM_H )
    if (environment->sh)
        uodbc_close_stats(environment->sh);
#endif
    
    /*
     * clear just to make sure
     */

    memset( environment, 0, sizeof( *environment ));

    free( environment );

    mutex_exit( &mutex_lists );
}
Esempio n. 9
0
void *find_parent_handle( DRV_SQLHANDLE drv_hand, int type )
{
	void *found_handle = NULL;

    mutex_entry( &mutex_lists );

	switch( type ) {
		case SQL_HANDLE_DBC:
			{
				DMHDBC hand = connection_root;
				while( hand ) {
					if ( hand -> driver_dbc == drv_hand ) {
						found_handle = hand;
						break;
					}
					hand = hand -> next_class_list;
				}
			}
			break;

		case SQL_HANDLE_STMT:
			{
				DMHSTMT hand = statement_root;
				while( hand ) {
					if ( hand -> driver_stmt == drv_hand ) {
						found_handle = hand;
						break;
					}
					hand = hand -> next_class_list;
				}
			}
			break;

		case SQL_HANDLE_DESC:
			{
				DMHDESC hand = descriptor_root;
				while( hand ) {
					if ( hand -> driver_desc == drv_hand ) {
						found_handle = hand;
						break;
					}
					hand = hand -> next_class_list;
				}
			}
			break;

		default:
			break;
	}

    mutex_exit( &mutex_lists );

	return found_handle;
}
Esempio n. 10
0
void __register_stmt ( DMHDBC connection, DMHSTMT statement )
{
    mutex_entry( &mutex_lists );

    connection -> statement_count ++;
    statement -> connection = connection;
#ifdef FAST_HANDLE_VALIDATE
    statement -> next_conn_list = connection -> statements;
    connection -> statements = statement;
#endif
    mutex_exit( &mutex_lists );
}
Esempio n. 11
0
/*! 
 * \brief   Get a reference to a message in the log.
 *
 *          The caller (SQLInstallerError) could call logPeekMsg directly
 *          but we would have to extern hODBCINSTLog and I have not given
 *          any thought to that at this time.
 * 
 * \param   nMsg
 * \param   phMsg
 * 
 * \return  int
 */
int inst_logPeekMsg( long nMsg, HLOGMSG *phMsg )
{
    int ret = LOG_NO_DATA;

    mutex_entry();

    if ( hODBCINSTLog )
        ret = logPeekMsg( hODBCINSTLog, nMsg, phMsg );

    mutex_exit();

    return ret;
}
Esempio n. 12
0
int inst_logClear( void )
{
    int ret = LOG_ERROR;

    mutex_entry();

    if ( hODBCINSTLog ) 
        ret = logClear( hODBCINSTLog );

    mutex_exit();

    return ret;
}
Esempio n. 13
0
void __release_dbc( DMHDBC connection )
{
    DMHDBC last = NULL;
    DMHDBC ptr;

    mutex_entry( &mutex_lists );

    ptr = connection_root;

    while( ptr )
    {
        if ( connection == ptr )
        {
            break;
        }
        last = ptr;
        ptr = ptr -> next_class_list;
    }

    if ( ptr )
    {
        if ( last )
        {
            last -> next_class_list = ptr -> next_class_list;
        }
        else
        {
            connection_root = ptr -> next_class_list;
        }
    }

    clear_error_head( &connection -> error );

#ifdef HAVE_LIBPTH
#elif HAVE_LIBPTHREAD
    pthread_mutex_destroy( &connection -> mutex );
#elif HAVE_LIBTHREAD
    mutex_destroy( &connection -> mutex );
#endif

    /*
     * clear just to make sure
     */

    memset( connection, 0, sizeof( *connection ));

    free( connection );

    mutex_exit( &mutex_lists );
}
Esempio n. 14
0
int __check_stmt_from_dbc_v( DMHDBC connection, int statecount, ... )
{
    va_list ap;
    int states[ MAX_STATE_ARGS ];
    DMHSTMT ptr;
    int found = 0;
    int i;

    va_start (ap, statecount);
    for ( i = 0; i < statecount; i ++ ) {
        states[ i ] = va_arg (ap, int );
    }
    va_end (ap);

    mutex_entry( &mutex_lists );
#ifdef FAST_HANDLE_VALIDATE
    ptr = connection -> statements;
    while( !found && ptr )
    {
        for ( i = 0; i < statecount; i ++ ) {
            if ( ptr -> state == states[ i ] ) {
                found = 1;
                break;
            }
       }
    
        ptr = ptr -> next_conn_list;
    }
#else
    ptr = statement_root;
    while( !found && ptr )
    {
        if ( ptr -> connection == connection )
        {
            for ( i = 0; i < statecount; i ++ ) {
                if ( ptr -> state == states[ i ] ) {
                    found = 1;
                    break;
                }
            }
        }

        ptr = ptr -> next_class_list;
    }
#endif
    mutex_exit( &mutex_lists );

    return found;
}
Esempio n. 15
0
int __check_stmt_from_desc_ird( DMHDESC desc, int state )
{
    DMHDBC connection;
    DMHSTMT ptr;
    int found = 0;

    mutex_entry( &mutex_lists );
    connection = desc -> connection;
#ifdef FAST_HANDLE_VALIDATE
    ptr = connection -> statements;
    while( ptr )
    {
        if ( ptr -> ird == desc ) 
        {
            if ( ptr -> state == state ) 
            {
                found = 1;
                break;
            }
        }
    
        ptr = ptr -> next_conn_list;
    }
#else
    ptr = statement_root;
    while( ptr )
    {
        if ( ptr -> connection == connection )
        {
            if ( ptr -> ird == desc ) 
            {
                if ( ptr -> state == state ) 
                {
                    found = 1;
                    break;
                }
            }
        }

        ptr = ptr -> next_class_list;
    }
#endif
    mutex_exit( &mutex_lists );

    return found;
}
Esempio n. 16
0
DMHDBC __alloc_dbc( void )
{
    DMHDBC connection = NULL;

    mutex_entry( &mutex_lists );

    connection = calloc( sizeof( *connection ), 1 );

    if ( connection )
    {
        /*
         * add to list of connection handles
         */

        connection -> next_class_list = connection_root;
        connection_root = connection;
        connection -> type = HDBC_MAGIC;

        setup_error_head( &connection -> error, connection,
                SQL_HANDLE_DBC );

#ifdef HAVE_LIBPTH
        pth_mutex_init( &connection -> mutex );
        /*
         * for the moment protect at the environment level
         */
        connection -> protection_level = TS_LEVEL3;
#elif HAVE_LIBPTHREAD
        pthread_mutex_init( &connection -> mutex, NULL );
        /*
         * for the moment protect at the environment level
         */
        connection -> protection_level = TS_LEVEL3;
#elif HAVE_LIBTHREAD
        mutex_init( &connection -> mutex, USYNC_THREAD, NULL );
        connection -> protection_level = TS_LEVEL3;
#endif

    }

    mutex_exit( &mutex_lists );

    return connection;
}
Esempio n. 17
0
static int check_ini_cache( int *ret,
                     LPCSTR  pszSection,
                     LPCSTR  pszEntry,
                     LPCSTR  pszDefault,
                     LPSTR   pRetBuffer,
                     int     nRetBuffer,
                     LPCSTR  pszFileName )
{
	int rval;

	mutex_entry( &mutex_ini );

	rval = _check_ini_cache( ret, pszSection, pszEntry, pszDefault,
			pRetBuffer, nRetBuffer, pszFileName );

	mutex_exit( &mutex_ini );

	return rval;
}
Esempio n. 18
0
DMHSTMT __alloc_stmt( void )
{
    DMHSTMT statement = NULL;

    mutex_entry( &mutex_lists );

    statement = calloc( sizeof( *statement ), 1 );

    if ( statement )
    {
        /*
         * add to list of statement handles
         */

        statement -> next_class_list = statement_root;
#ifdef FAST_HANDLE_VALIDATE
        if ( statement_root )
        {
            statement_root -> prev_class_list = statement;
        }
#endif    
        statement_root = statement;
        statement -> type = HSTMT_MAGIC;

        setup_error_head( &statement -> error, statement,
                SQL_HANDLE_STMT );

#ifdef HAVE_LIBPTH
        pth_mutex_init( &statement -> mutex );
#elif HAVE_LIBPTHREAD
        pthread_mutex_init( &statement -> mutex, NULL );
#elif HAVE_LIBTHREAD
        mutex_init( &statement -> mutex, USYNC_THREAD, NULL );
#endif

    }

    mutex_exit( &mutex_lists );

    return statement;
}
Esempio n. 19
0
DMHDESC __alloc_desc( void )
{
    DMHDESC descriptor = NULL;

    mutex_entry( &mutex_lists );

    descriptor = calloc( sizeof( *descriptor ), 1 );

    if ( descriptor )
    {
        /*
         * add to list of descriptor handles
         */

        descriptor -> next_class_list = descriptor_root;
#ifdef FAST_HANDLE_VALIDATE
        if ( descriptor_root )
        {
            descriptor_root -> prev_class_list = descriptor;
        }
#endif    
        descriptor_root = descriptor;
        descriptor -> type = HDESC_MAGIC;
    }

    setup_error_head( &descriptor -> error, descriptor,
            SQL_HANDLE_DESC );

#ifdef HAVE_LIBPTH
    pth_mutex_init( &descriptor -> mutex );
#elif HAVE_LIBPTHREAD
    pthread_mutex_init( &descriptor -> mutex, NULL );
#elif HAVE_LIBTHREAD
    mutex_init( &descriptor -> mutex, USYNC_THREAD, NULL );
#endif

    mutex_exit( &mutex_lists );

    return descriptor;
}
Esempio n. 20
0
int inst_logPushMsg( char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessage )
{
    int ret = LOG_ERROR;

    mutex_entry();

    if ( !log_tried )
    {
        long nMaxMessages = 10; /* \todo ODBC spec says 8 max. We would make it 0 (unlimited) but at the moment logPeekMsg 
                                   would be slow if many messages. Revisit when opt is made to log storage. */

        log_tried = 1;
        if ( logOpen( &hODBCINSTLog, "odbcinst", NULL, nMaxMessages ) != LOG_SUCCESS )
        {
            hODBCINSTLog = NULL;
        }
        else
        {
            logOn( hODBCINSTLog, 1 );
        }
    }
    if ( hODBCINSTLog )
    {
        ret = logPushMsg( hODBCINSTLog,
                pszModule, 
                pszFunctionName, 
                nLine, 
                nSeverity, 
                nCode, 
                pszMessage );
    }

    mutex_exit();

    return ret;
}
Esempio n. 21
0
void mutex_pool_entry( void )
{
    mutex_entry( &mutex_pool );
}
Esempio n. 22
0
int __clean_stmt_from_dbc( DMHDBC connection )
{
    DMHSTMT ptr, last;
    int ret = 0;

    mutex_entry( &mutex_lists );
#ifdef FAST_HANDLE_VALIDATE
    while ( connection -> statements )
    {
        ptr  = connection -> statements;
        last = connection -> statements -> prev_class_list;
        
        connection -> statements = ptr -> next_conn_list;
        if ( last )
        {
            last -> next_class_list = ptr -> next_class_list;
            if ( last -> next_class_list )
            {
                last -> next_class_list -> prev_class_list = last;
            }
        }
        else
        {
            statement_root = ptr -> next_class_list;
            if ( statement_root )
            {
                statement_root -> prev_class_list = NULL;
            }
        }
        clear_error_head( &ptr -> error );

#ifdef HAVE_LIBPTH
#elif HAVE_LIBPTHREAD
        pthread_mutex_destroy( &ptr -> mutex );
#elif HAVE_LIBTHREAD
        mutex_destroy( &ptr -> mutex );
#endif
        free( ptr );
    }        
#else
    last = NULL;
    ptr  = statement_root;

    while( ptr )
    {
        if ( ptr -> connection == connection )
        {
            if ( last )
            {
                last -> next_class_list = ptr -> next_class_list;
            }
            else
            {
                statement_root = ptr -> next_class_list;
            }
            clear_error_head( &ptr -> error );

#ifdef HAVE_LIBPTH
#elif HAVE_LIBPTHREAD
            pthread_mutex_destroy( &ptr -> mutex );
#elif HAVE_LIBTHREAD
            mutex_destroy( &ptr -> mutex );
#endif
            free( ptr );

            /*
             * go back to the start
             */

            last = NULL;
            ptr = statement_root;
        }
        else
        {
            last = ptr;
            ptr = ptr -> next_class_list;
        }
    }
#endif
    mutex_exit( &mutex_lists );

    return ret;
}
Esempio n. 23
0
/*
 * Sets statement state after commit or rollback transaction
 */ 
void __set_stmt_state ( DMHDBC connection, SQLSMALLINT cb_value )
{
    DMHSTMT         statement;
    SQLINTEGER stmt_remaining;

    mutex_entry( &mutex_lists );
#ifdef FAST_HANDLE_VALIDATE
    statement      = connection -> statements;
    while ( statement )
    {
        if ( (statement -> state == STATE_S2 ||
              statement -> state == STATE_S3) &&
             cb_value == SQL_CB_DELETE )
        {
            statement -> state = STATE_S1;
            statement -> prepared = 0;
        }
        else if ( statement -> state == STATE_S4 ||
              statement -> state == STATE_S5 ||
              statement -> state == STATE_S6 ||
              statement -> state == STATE_S7 )
        {
            if( !statement -> prepared && 
                (cb_value == SQL_CB_DELETE ||
                 cb_value == SQL_CB_CLOSE) )
            {
                statement -> state = STATE_S1;
            }
            else if( statement -> prepared )
            {
                if( cb_value == SQL_CB_DELETE )
                {
                    statement -> state = STATE_S1;
                    statement -> prepared = 0;
                }
                else if( cb_value == SQL_CB_CLOSE )
                {
                    if ( statement -> state == STATE_S4 )
                      statement -> state = STATE_S2;
                    else
                      statement -> state = STATE_S3;
                }
            }
        }
        statement = statement -> next_conn_list;
    }
#else
    statement      = statement_root;
    stmt_remaining = connection -> statement_count;

    while ( statement && stmt_remaining > 0 )
    {
        if ( statement -> connection == connection )
        {
            if ( (statement -> state == STATE_S2 ||
                  statement -> state == STATE_S3) &&
                 cb_value == SQL_CB_DELETE )
            {
                statement -> state = STATE_S1;
                statement -> prepared = 0;
            }
            else if ( statement -> state == STATE_S4 ||
                  statement -> state == STATE_S5 ||
                  statement -> state == STATE_S6 ||
                  statement -> state == STATE_S7 )
            {
                if( !statement -> prepared && 
                    (cb_value == SQL_CB_DELETE ||
                     cb_value == SQL_CB_CLOSE) )
                {
                    statement -> state = STATE_S1;
                }
                else if( statement -> prepared )
                {
                    if( cb_value == SQL_CB_DELETE )
                    {
                        statement -> state = STATE_S1;
                        statement -> prepared = 0;
                    }
                    else if( cb_value == SQL_CB_CLOSE )
                    {
                        if ( statement -> state == STATE_S4 )
                          statement -> state = STATE_S2;
                        else
                          statement -> state = STATE_S3;
                    }
                }
            }

            stmt_remaining --;
        }

        statement = statement -> next_class_list;
    }
#endif
    mutex_exit( &mutex_lists );
}
Esempio n. 24
0
void __release_stmt( DMHSTMT statement )
{
    DMHSTMT last = NULL;
    DMHSTMT ptr;

    mutex_entry( &mutex_lists );
#ifdef FAST_HANDLE_VALIDATE
    /*
     * A check never mind
     */
    if ( statement && ( *(( int * ) statement ) == HSTMT_MAGIC ))
    {
        ptr  = statement;
        last = statement->prev_class_list;
        
        if ( statement -> connection )
        {
            DMHDBC connection = statement -> connection;
            DMHSTMT conn_last = NULL;
            DMHSTMT  conn_ptr = connection -> statements;
            while ( conn_ptr )
            {
                if ( statement == conn_ptr )
                {
                    break;
                }
                conn_last = conn_ptr;
                conn_ptr  = conn_ptr -> next_conn_list;
            }
            if ( conn_ptr )
            {
                if ( conn_last )
                {
                    conn_last -> next_conn_list = conn_ptr -> next_conn_list;
                }
                else
                {
                    connection -> statements    = conn_ptr -> next_conn_list;
                }
            }
        }
    }
    else
    {
        ptr  = NULL;
        last = NULL;
    }
#else
    ptr = statement_root;

    while( ptr )
    {
        if ( statement == ptr )
        {
            break;
        }
        last = ptr;
        ptr = ptr -> next_class_list;
    }
#endif
    if ( ptr )
    {
        if ( last )
        {
            last -> next_class_list = ptr -> next_class_list;
#ifdef FAST_HANDLE_VALIDATE
            if ( last -> next_class_list )
            {
                last -> next_class_list -> prev_class_list = last;
            }
#endif            
        }
        else
        {
            statement_root = ptr -> next_class_list;
#ifdef FAST_HANDLE_VALIDATE
            if ( statement_root )
            {
                statement_root -> prev_class_list = NULL;
            }
#endif            
        }
    }

    clear_error_head( &statement -> error );

#ifdef HAVE_LIBPTH
#elif HAVE_LIBPTHREAD
    pthread_mutex_destroy( &statement -> mutex );
#elif HAVE_LIBTHREAD
    mutex_destroy( &statement -> mutex );
#endif

    /*
     * clear just to make sure
     */

    memset( statement, 0, sizeof( *statement ));

    free( statement );

    mutex_exit( &mutex_lists );
}
Esempio n. 25
0
int __clean_desc_from_dbc( DMHDBC connection )
{
    DMHDESC ptr, last;
    int ret = 0;

    mutex_entry( &mutex_lists );
    last = NULL;
    ptr = descriptor_root;

    while( ptr )
    {
        if ( ptr -> connection == connection )
        {
            if ( last )
            {
                last -> next_class_list = ptr -> next_class_list;
#ifdef FAST_HANDLE_VALIDATE
                if ( last -> next_class_list )
                {
                    last -> next_class_list -> prev_class_list = last;
                }
#endif            
            }
            else
            {
                descriptor_root = ptr -> next_class_list;
#ifdef FAST_HANDLE_VALIDATE
                if ( descriptor_root )
                {
                    descriptor_root -> prev_class_list = NULL;
                }
#endif            
            }
            clear_error_head( &ptr -> error );

#ifdef HAVE_LIBPTH
#elif HAVE_LIBPTHREAD
            pthread_mutex_destroy( &ptr -> mutex );
#elif HAVE_LIBTHREAD
            mutex_destroy( &ptr -> mutex );
#endif
            free( ptr );

            /*
             * go back to the start
             */

            last = NULL;
            ptr = descriptor_root;
        }
        else
        {
            last = ptr;
            ptr = ptr -> next_class_list;
        }
    }

    mutex_exit( &mutex_lists );

    return ret;
}
Esempio n. 26
0
void __release_desc( DMHDESC descriptor )
{
    DMHDESC last = NULL;
    DMHDESC ptr;

    mutex_entry( &mutex_lists );
#ifdef FAST_HANDLE_VALIDATE
    /*
     * A check never mind
     */
    if ( descriptor && ( *(( int * ) descriptor ) == HDESC_MAGIC ))
    {
        ptr  = descriptor;
        last = descriptor->prev_class_list;
    }
    else
    {
        ptr  = NULL;
        last = NULL;
    }
#else
    ptr = descriptor_root;

    while( ptr )
    {
        if ( descriptor == ptr )
        {
            break;
        }
        last = ptr;
        ptr = ptr -> next_class_list;
    }
#endif

    if ( ptr )
    {
        if ( last )
        {
            last -> next_class_list = ptr -> next_class_list;
#ifdef FAST_HANDLE_VALIDATE
            if ( last -> next_class_list )
            {
                last -> next_class_list -> prev_class_list = last;
            }
#endif            
        }
        else
        {
            descriptor_root = ptr -> next_class_list;
#ifdef FAST_HANDLE_VALIDATE
            if ( descriptor_root )
            {
                descriptor_root -> prev_class_list = NULL;
            }
#endif            
        }
    }

    clear_error_head( &descriptor -> error );

#ifdef HAVE_LIBPTH
#elif HAVE_LIBPTHREAD
    pthread_mutex_destroy( &descriptor -> mutex );
#elif HAVE_LIBTHREAD
    mutex_destroy( &descriptor -> mutex );
#endif

    /*
     * clear just to make sure
     */

    memset( descriptor, 0, sizeof( *descriptor ));

    free( descriptor );

    mutex_exit( &mutex_lists );
}
Esempio n. 27
0
void mutex_iconv_entry( void )
{
    mutex_entry( &mutex_iconv );
}
Esempio n. 28
0
void mutex_lib_entry( void )
{
    mutex_entry( &mutex_lists );
}
Esempio n. 29
0
DMHENV __alloc_env( void )
{
    DMHENV environment = NULL;

    mutex_entry( &mutex_lists );

    environment = calloc( sizeof( *environment ), 1 );

    if ( environment )
    {
        char tracing_string[ 64 ];
        char tracing_file[ 64 ];

#if defined ( COLLECT_STATS ) && defined( HAVE_SYS_SEM_H )
        if (uodbc_open_stats(&environment->sh, UODBC_STATS_WRITE) != 0)
        {
            ;
        }
        uodbc_update_stats(environment->sh, UODBC_STATS_TYPE_HENV, (void *)1);
#endif
        
        /*
         * add to list of env handles
         */

        environment -> next_class_list = enviroment_root;
        enviroment_root = environment;
        environment -> type = HENV_MAGIC;

        SQLGetPrivateProfileString( "ODBC", "Trace", "No",
                    tracing_string, sizeof( tracing_string ), 
                    "odbcinst.ini" );

        if ( tracing_string[ 0 ] == '1' ||
                toupper( tracing_string[ 0 ] ) == 'Y' ||
                    ( toupper( tracing_string[ 0 ] ) == 'O' &&
                    toupper( tracing_string[ 1 ] ) == 'N' ))
        {
            SQLGetPrivateProfileString( "ODBC", "TraceFile", "/tmp/sql.log",
                    tracing_file, sizeof( tracing_file ), 
                    "odbcinst.ini" );

            /*
             * start logging
             */

            SQLGetPrivateProfileString( "ODBC", "TracePid", "No",
                    tracing_string, sizeof( tracing_string ), 
                    "odbcinst.ini" );

            if ( tracing_string[ 0 ] == '1' ||
                        toupper( tracing_string[ 0 ] ) == 'Y' ||
                        ( toupper( tracing_string[ 0 ] ) == 'O' &&
                        toupper( tracing_string[ 1 ] ) == 'N' ))
            {
                dm_log_open( "ODBC", tracing_file, 1 );
            }
            else
            {
                dm_log_open( "ODBC", tracing_file, 0 );
            }

            sprintf( environment -> msg,
                    "\n\t\tExit:[SQL_SUCCESS]\n\t\t\tEnvironment = %p",	environment );

            dm_log_write( __FILE__,
                    __LINE__,
                    LOG_INFO,
                    LOG_INFO, environment -> msg );
        }
    }

    setup_error_head( &environment -> error, environment,
            SQL_HANDLE_ENV );

    mutex_exit( &mutex_lists );

    return environment;
}