Exemplo n.º 1
0
int main()
{
    FILE *p;
    p=fopen("input.dat","r");
    o=fopen("output.dat","w");
    char a[100],*c,*d;
    while(fgets(a,100,p))
    {
        c=strtok(a," \n");
        d=strtok(NULL," \n");
        if(strcmp(c,"AF") == 0)
        {
            AddFirst(atoi(d), &Works);
        } else
        if (strcmp(c,"AL") == 0)
        {
            AddLast(atoi(d), &Works);
        }
        else if(strcmp(c,"DF")==0)
        {
            DeleteFirst(&Works);
        }
        else if(strcmp(c,"DL")==0)
        {
            DeleteLast(&Works);
        }
        else if(strcmp(c,"DE")==0)
        {
            DeleteElement(atoi(d), &Works);
        }
        else if(strcmp(c,"PRINT_ALL")==0)
        {
            print(&Works);
        }
        else if(strcmp(c,"PRINT_F")==0)
        {
            PrintNrOfElements(atoi(d), &Works);
        }
        else if(strcmp(c,"PRINT_L")==0)
        {
            PrintNrOfElementsLast(atoi(d), &Works);
        }
        else if(strcmp(c,"DOOM_THE_LIST")==0)
        {
            Doom(&Works);
        }
    }
    return 0;
}
NS_IMETHODIMP
nsCacheEntryDescriptor::Close()
{
    nsRefPtr<nsOutputStreamWrapper> outputWrapper;
    nsTArray<nsRefPtr<nsInputStreamWrapper> > inputWrappers;

    {
        nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_CLOSE));
        if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;

        // Make sure no other stream can be opened
        mClosingDescriptor = true;
        outputWrapper = mOutputWrapper;
        for (int32_t i = 0 ; i < mInputWrappers.Count() ; i++)
            inputWrappers.AppendElement(static_cast<nsInputStreamWrapper *>(
                        mInputWrappers[i]));
    }

    // Call Close() on the streams outside the lock since it might need to call
    // methods that grab the cache service lock, e.g. compressed output stream
    // when it finalizes the entry
    if (outputWrapper) {
        if (NS_FAILED(outputWrapper->Close())) {
            NS_WARNING("Dooming entry because Close() failed!!!");
            Doom();
        }
        outputWrapper = nullptr;
    }

    for (uint32_t i = 0 ; i < inputWrappers.Length() ; i++)
        inputWrappers[i]->Close();

    inputWrappers.Clear();

    nsCacheServiceAutoLock lock(LOCK_TELEM(NSCACHEENTRYDESCRIPTOR_CLOSE));
    if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;

    // XXX perhaps closing descriptors should clear/sever transports

    // tell nsCacheService we're going away
    nsCacheService::CloseDescriptor(this);
    NS_ASSERTION(mCacheEntry == nullptr, "mCacheEntry not null");

    return NS_OK;
}