Ignore:
Timestamp:
May 22, 2009, 4:47:07 PM (16 years ago)
Author:
pr
Message:

Add reference counting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/acpih.c

    r327 r380  
    1717
    1818/*
    19  *      Copyright (C) 2006 Paul Ratcliffe.
     19 *      Copyright (C) 2006-2009 Paul Ratcliffe.
    2020 *      This file is part of the "XWorkplace helpers" source package.
    2121 *      This is free software; you can redistribute it and/or modify
     
    4949 ********************************************************************/
    5050
    51 HMODULE       hmodACPI = NULLHANDLE;
     51HMODULE       G_hmodACPI = NULLHANDLE;
     52ULONG         G_ulCount = 0;
    5253
    5354ACPISTARTAPI  *pAcpiStartApi = NULL;
     
    6970    APIRET arc = NO_ERROR;
    7071
    71     if (!hmodACPI)
     72    if (!G_hmodACPI)
    7273        if (!(arc = DosLoadModule(NULL,
    7374                                  0,
    7475                                  "ACPI32",
    75                                   &hmodACPI)))
     76                                  &G_hmodACPI)))
    7677        {
    77             arc = DosQueryProcAddr(hmodACPI,
     78            arc = DosQueryProcAddr(G_hmodACPI,
    7879                                   ORD_ACPISTARTAPI,
    7980                                   NULL,
    8081                                   (PFN *) &pAcpiStartApi);
    8182            if (!arc)
    82                 arc = DosQueryProcAddr(hmodACPI,
     83                arc = DosQueryProcAddr(G_hmodACPI,
    8384                                   ORD_ACPIENDAPI,
    8485                                   NULL,
     
    8687
    8788            if (!arc)
    88                 arc = DosQueryProcAddr(hmodACPI,
     89                arc = DosQueryProcAddr(G_hmodACPI,
    8990                                   ORD_ACPIGOTOSLEEP,
    9091                                   NULL,
     
    9293            if (arc)
    9394            {
    94                 DosFreeModule(hmodACPI);
    95                 hmodACPI = NULLHANDLE;
     95                DosFreeModule(G_hmodACPI);
     96                G_hmodACPI = NULLHANDLE;
    9697                pAcpiStartApi = NULL;
    9798                pAcpiEndApi = NULL;
     
    104105        return(arc);
    105106    else
     107    {
     108        G_ulCount++;
    106109        return(pAcpiStartApi(phACPI));
     110    }
    107111}
    108112
     
    115119{
    116120    if (pAcpiEndApi)
     121    {
    117122        pAcpiEndApi(phACPI);
     123        G_ulCount--;
     124    }
     125
     126    if (!G_ulCount)
     127    {
     128        DosFreeModule(G_hmodACPI);
     129        G_hmodACPI = NULLHANDLE;
     130        pAcpiStartApi = NULL;
     131        pAcpiEndApi = NULL;
     132        pAcpiGoToSleep = NULL;
     133    }
    118134}
    119135
Note: See TracChangeset for help on using the changeset viewer.