Exemple #1
0
void
clearHTable(Table ht)
{   int n;
    TableEnum e;

    LOCK_TABLE(ht);
    for( e=ht->enumerators; e; e = e->next )
    {   e->current = NULL;
        e->key     = ht->buckets;
    }

    for(n=0; n < ht->buckets; n++)
    {   Symbol s, q;

        for(s = ht->entries[n]; s; s = q)
        {   q = s->next;

            if ( ht->free_symbol )
                (*ht->free_symbol)(s);

            freeHeap(s, sizeof(struct symbol));
        }

        ht->entries[n] = NULL;
    }

    ht->size = 0;
    UNLOCK_TABLE(ht);
}
Exemple #2
0
void
deleteSymbolHTable(Table ht, Symbol s)
{   int v;
    Symbol *h;
    TableEnum e;

    LOCK_TABLE(ht);
    v = (int)pointerHashValue(s->name, ht->buckets);
    h = &ht->entries[v];

    for( e=ht->enumerators; e; e = e->next )
    {   if ( e->current == s )
            rawAdvanceTableEnum(e);
    }

    for( ; *h; h = &(*h)->next )
    {   if ( *h == s )
        {   *h = (*h)->next;

            s->next = NULL;				/* force crash */
            s->name = NULL;
            s->value = NULL;
            freeHeap(s, sizeof(struct symbol));
            ht->size--;

            break;
        }
    }

    UNLOCK_TABLE(ht);
}
Exemple #3
0
Symbol
addHTable(Table ht, void *name, void *value)
{   Symbol s;
    int v;

    LOCK_TABLE(ht);
    v = (int)pointerHashValue(name, ht->buckets);
    if ( lookupHTable(ht, name) )
    {   UNLOCK_TABLE(ht);
        return NULL;
    }
    s = allocHeapOrHalt(sizeof(struct symbol));
    s->name  = name;
    s->value = value;
    s->next  = ht->entries[v];
    ht->entries[v] = s;
    ht->size++;
    DEBUG(9, Sdprintf("addHTable(0x%x, 0x%x, 0x%x) --> size = %d\n",
                      ht, name, value, ht->size));

    if ( ht->buckets * 2 < ht->size && !ht->enumerators )
        s = rehashHTable(ht, s);
    UNLOCK_TABLE(ht);

    DEBUG(1, checkHTable(ht));
    return s;
}
Exemple #4
0
Symbol
advanceTableEnum(TableEnum e)
{   Symbol s;
#ifdef O_PLMT
    Table ht = e->table;
#endif

    LOCK_TABLE(ht);
    s = rawAdvanceTableEnum(e);
    UNLOCK_TABLE(ht);

    return s;
}
Exemple #5
0
TableEnum
newTableEnum(Table ht)
{   TableEnum e = allocHeapOrHalt(sizeof(struct table_enum));
    Symbol n;

    LOCK_TABLE(ht);
    e->table	  = ht;
    e->key	  = 0;
    e->next	  = ht->enumerators;
    ht->enumerators = e;

    n = ht->entries[0];
    while(!n && ++e->key < ht->buckets)
        n=ht->entries[e->key];
    e->current = n;
    UNLOCK_TABLE(ht);

    return e;
}
Exemple #6
0
void
freeTableEnum(TableEnum e)
{   TableEnum *ep;
    Table ht;

    if ( !e )
        return;

    ht = e->table;
    LOCK_TABLE(ht);
    for( ep=&ht->enumerators; *ep ; ep = &(*ep)->next )
    {   if ( *ep == e )
        {   *ep = (*ep)->next;

            freeHeap(e, sizeof(*e));
            break;
        }
    }
    UNLOCK_TABLE(ht);
}
Exemple #7
0
Table
copyHTable(Table org)
{   Table ht;
    int n;

    ht = allocHeapOrHalt(sizeof(struct table));
    LOCK_TABLE(org);
    *ht = *org;				/* copy all attributes */
#ifdef O_PLMT
    ht->mutex = NULL;
#endif
    ht->entries = allocHTableEntries(ht->buckets);

    for(n=0; n < ht->buckets; n++)
    {   Symbol s, *q;

        q = &ht->entries[n];
        for(s = org->entries[n]; s; s = s->next)
        {   Symbol s2 = allocHeapOrHalt(sizeof(*s2));

            *q = s2;
            q = &s2->next;
            s2->name = s->name;
            s2->value = s->value;

            if ( ht->copy_symbol )
                (*ht->copy_symbol)(s2);
        }
        *q = NULL;
    }
#ifdef O_PLMT
    if ( org->mutex )
    {   ht->mutex = allocHeapOrHalt(sizeof(simpleMutex));
        simpleMutexInit(ht->mutex);
    }
#endif
    UNLOCK_TABLE(org);

    return ht;
}
Exemple #8
0
DWORD
WINAPI
WahRemoveContextEx(
    LPCONTEXT_TABLE Table,
    SOCKET Socket,
    LPVOID Context
    )

/*++

Routine Description:

    Removes a context association from the given table.

Arguments:

    Table - The table to remove the context from.

    Socket - The key to remove.

    Context - the context that should be in the table

Return Value:

    DWORD - NO_ERROR if successful, a Win32 error code if not.

--*/

{

    DWORD key = SOCKET_TO_KEY( Socket );
    DWORD err;

    //
    // Acquire the lock protecting the context table.
    //

    LOCK_TABLE( Table );

    //
    // Validate the key before indexing into the lookup array.
    //

    if( key < Table->LookupArraySize ) {

        if( !Context || ( Table->LookupArray[key] == Context ) ) {

            Table->LookupArray[key] = NULL;
            err = NO_ERROR;

        } else {

            if( Table->LookupArray[key] ) {

                err = ERROR_FILE_EXISTS;

            } else {

                err = ERROR_DEV_NOT_EXIST;

            }

        }

    } else {

        err = ERROR_INVALID_PARAMETER;

    }

    //
    // Cleanup and return
    //

    UNLOCK_TABLE( Table );
    return err;

}   // WahRemoveContextEx
Exemple #9
0
DWORD
WINAPI
WahGetContext(
    LPCONTEXT_TABLE Table,
    SOCKET Socket,
    LPVOID * Context
    )

/*++

Routine Description:

    Retrieves the context associated with the given key.

Arguments:

    Table - The table to use for the context lookup.

    Socket - The key to lookup.

    Context - If successful, receives the context value.

Return Value:

    DWORD - NO_ERROR if successful, a Win32 error code if not.

--*/

{

    DWORD key = SOCKET_TO_KEY( Socket );

    //
    // Acquire the lock protecting the context table.
    //

    LOCK_TABLE( Table );

    //
    // Validate the key before indexing into the lookup array.
    //

    if( key < Table->LookupArraySize ) {

        *Context = Table->LookupArray[key];

        if( *Context != NULL ) {

            UNLOCK_TABLE( Table );
            return NO_ERROR;

        }

    }

    //
    // Invalid key.
    //

    UNLOCK_TABLE( Table );

    return ERROR_INVALID_PARAMETER;

}   // WahGetContext
Exemple #10
0
DWORD
WINAPI
WahSetContext(
    LPCONTEXT_TABLE Table,
    SOCKET Socket,
    LPVOID Context
    )

/*++

Routine Description:

    Associates the given context with the given key.

Arguments:

    Table - The table to contain the new context.

    Socket - The key to index the new context.

    Context - The new context.

Return Value:

    DWORD - NO_ERROR if successful, a Win32 error code if not.

--*/

{

    DWORD newLookupArraySize;
    LPVOID * newLookupArray;
    DWORD key = SOCKET_TO_KEY( Socket );

    //
    // Acquire the lock protecting the context table.
    //

    LOCK_TABLE( Table );

    //
    // Determine if we can do this without growing the lookup array.
    //

    if( Table->LookupArraySize > key ) {

        Table->LookupArray[key] = Context;
        UNLOCK_TABLE( Table );
        return NO_ERROR;

    }

    //
    // We'll need to grow the lookup array first.
    //

    newLookupArraySize = Table->LookupArraySize +
        ARRAY_GROWTH_DELTA *
            ( ( ( key - Table->LookupArraySize ) / ARRAY_GROWTH_DELTA ) + 1 );

    newLookupArray = REALLOC_MEM(
                         Table->LookupArray,
                         newLookupArraySize * sizeof(LPVOID)
                         );

    if( newLookupArray != NULL ) {

        Table->LookupArray = newLookupArray;
        Table->LookupArraySize = newLookupArraySize;
        Table->LookupArray[key] = Context;
        UNLOCK_TABLE( Table );
        return NO_ERROR;

    }

    //
    // Error growing the lookup array.
    //

    UNLOCK_TABLE( Table );
    return ERROR_NOT_ENOUGH_MEMORY;

}   // WahSetContext