-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource.c
77 lines (64 loc) · 1.88 KB
/
resource.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* $Id: resource.c,v 39.1 1995/04/25 01:41:53 mbayne Exp $
*
* The information in this file was created by Michael D. Bayne. This
* information is in the public domain. You are permitted to reuse, rewrite,
* bend, fold and mutilate this information. When it comes down to it, all
* this distribution information is pretty much crap anyway and I maintain
* exclusive rights to everything you see here, but go ahead and use it
* anyway. I'm too busy doing cool stuff to sue anyone.
*
* $Log: resource.c,v $
* Revision 39.1 1995/04/25 01:41:53 mbayne
* Initial revision.
*
*/
#include <exec/memory.h>
#include <proto/exec.h>
#include <stdlib.h>
#include "resource.h"
struct List Resources;
void resourceClassDestruct( int value )
{
PvtResource *aRes;
while( aRes = ( PvtResource * )RemHead( &Resources ))
{
aRes->rs_Destructor( aRes->rs_Resource );
FreeMem( aRes, sizeof( PvtResource ));
}
exit( value );
}
void resourceClassInit( void )
{
NewList( &Resources );
}
int resourceDestroy( void *theResource )
{
PvtResource *aRes;
if( IsListEmpty( &Resources ))
return FALSE;
for( aRes = resourceHead( &Resources );; aRes = resourceSucc( aRes ))
{
if( aRes->rs_Resource == theResource )
{
Remove(( struct Node * )aRes );
aRes->rs_Destructor( aRes->rs_Resource );
FreeMem( aRes, sizeof( PvtResource ));
return TRUE;
}
if( aRes == resourceTail( &Resources ))
break;
}
return FALSE;
}
void resourceAdd( void *Resource, FREEFUNC Destructor )
{
PvtResource *theRes;
if( theRes = AllocMem( sizeof( PvtResource ), MEMF_CLEAR|MEMF_PUBLIC ))
{
theRes->rs_Resource = Resource;
theRes->rs_Destructor = Destructor;
AddHead( &Resources, ( struct Node * )theRes );
}
else
resourceClassDestruct( 2 );
}