Пример #1
0
_WCRTLINK int dup2( int handle1, int handle2 )
{
    rdos_handle_type   *obj = 0;

    if( handle1 == handle2 )
        return( handle2 );

    if( handle2 < 0 )
        return( -1 );

    while( handle2 >= handle_count )
        GrowHandleArr( );
        
    RdosEnterKernelSection( &handle_section );

    if( handle1 >= 0 && handle1 < handle_count )
        if( handle_ptr[handle1] )
            obj = handle_ptr[handle1];

    if( obj )
        obj->ref_count++;
    
    RdosLeaveKernelSection( &handle_section );

    if( obj ) {
        if( ReplaceHandleEntry( handle2, obj ) )
            return( handle2 );
        else
            obj->ref_count--;
    }

    return( -1 );
}
Пример #2
0
void __SetIOMode_nogrow( int handle, unsigned value )
{
    RdosEnterKernelSection( &handle_section );

    if( handle >= 0 && handle < handle_count )
        if( handle_ptr[handle] )
            handle_ptr[handle]->mode = value;

    RdosLeaveKernelSection( &handle_section );
}
Пример #3
0
static void SetHandlePos( int handle, long pos )
{
    RdosEnterKernelSection( &handle_section );

    if( handle >= 0 && handle < handle_count ) {
        if( handle_ptr[handle] ) {
            handle_ptr[handle]->pos = pos;
        }
    }
    
    RdosLeaveKernelSection( &handle_section );
}
Пример #4
0
unsigned __GetIOMode( int handle )
{
    unsigned mode = 0;
    
    RdosEnterKernelSection( &handle_section );

    if( handle >= 0 && handle < handle_count )
        if( handle_ptr[handle] )
            mode = handle_ptr[handle]->mode;

    RdosLeaveKernelSection( &handle_section );

    return( mode );
}
Пример #5
0
signed __SetIOMode( int handle, unsigned value )
{
    signed ret = -1;

    RdosEnterKernelSection( &handle_section );

    if( handle >= 0 && handle < handle_count )
        if( handle_ptr[handle] ) {
            handle_ptr[handle]->mode = value;
            ret = handle;
        }

    RdosLeaveKernelSection( &handle_section );

    return( ret );
}
Пример #6
0
static long GetHandlePos( int handle )
{
    long pos = 0;

    RdosEnterKernelSection( &handle_section );

    if( handle >= 0 && handle < handle_count ) {
        if( handle_ptr[handle] ) {
            pos = handle_ptr[handle]->pos;
        }
    }
    
    RdosLeaveKernelSection( &handle_section );

    return( pos );
}
Пример #7
0
static int GetHandle( int handle )
{
    int rdos_handle = -1;

    RdosEnterKernelSection( &handle_section );
    
    if( handle >= 0 && handle < handle_count ) {
        if( handle_ptr[handle] ) {
            rdos_handle = handle_ptr[handle]->rdos_handle;
        }
    }
    
    RdosLeaveKernelSection( &handle_section );

    return( rdos_handle );
}
Пример #8
0
static rdos_handle_type *FreeHandleEntry( int handle )
{
    rdos_handle_type *obj = 0;
    
    RdosEnterKernelSection( &handle_section );

    if( handle >= 0 && handle < handle_count ) {
        if( handle_ptr[handle] ) {
            obj = handle_ptr[handle];
            handle_ptr[handle] = 0;
        }
    }

    RdosLeaveKernelSection( &handle_section );

    return( obj );
}
Пример #9
0
static int AllocHandleEntry( rdos_handle_type *obj )
{
    int i;

    RdosEnterKernelSection( &handle_section );

    for( i = 0; i < handle_count; i++)
        if( handle_ptr[i] == 0 )
            break;

    if( i == handle_count )
        GrowHandleArr();

    handle_ptr[i] = obj;

    RdosLeaveKernelSection( &handle_section );

    return( i );
}
Пример #10
0
_WCRTLINK int dup( int handle )
{
    rdos_handle_type   *obj = 0;

    RdosEnterKernelSection( &handle_section );

    if( handle >= 0 && handle < handle_count )
        if( handle_ptr[handle] )
            obj = handle_ptr[handle];

    if( obj )
        obj->ref_count++;
    
    RdosLeaveKernelSection( &handle_section );

    if( obj )
        return( AllocHandleEntry( obj ) );
    else
        return( -1 );
}
Пример #11
0
static int ReplaceHandleEntry( int handle, rdos_handle_type *new_obj )
{
    int                 ok = 0;
    rdos_handle_type   *obj = 0;
    
    RdosEnterKernelSection( &handle_section );

    if( handle >= 0 && handle < handle_count ) {
        if( handle_ptr[handle] )
            obj = handle_ptr[handle];
            
        handle_ptr[handle] = new_obj;
        ok = 1;
    }

    RdosLeaveKernelSection( &handle_section );

    if( obj )
        FreeHandleObj( obj );

    return ( ok );
}
Пример #12
0
_WCRTLINK void __ReleaseSemaphore( semaphore_object *obj )
{
    TID tid;

    tid = GetCurrentThreadId();
#if defined( _NETWARE_CLIB )
    if( tid == 0 )
        return;
#endif
    if( obj->count > 0 ) {
        if( obj->owner != tid ) {
            __fatal_runtime_error( "Semaphore unlocked by wrong owner", 1 );
        }
        if( --obj->count == 0 ) {
            obj->owner = 0;
#if defined( _M_I86 )
            DosSemClear( &obj->semaphore );
#else
  #if defined( __NETWARE__ )
            obj->semaphore = 0;
  #elif defined( __NT__ )
            LeaveCriticalSection( obj->semaphore );
  #elif defined( __QNX__ )
            __qsem_post( &obj->semaphore );
  #elif defined( __LINUX__ )
            // TODO: Relase semaphore under Linux!
  #elif defined( __RDOS__ )
            RdosLeaveSection( obj->semaphore );
  #elif defined( __RDOSDEV__ )
            RdosLeaveKernelSection( &obj->semaphore );
  #else
            DosReleaseMutexSem( obj->semaphore );
  #endif
#endif
        }
    }
}