4 * Copyright 1996 Alexandre Julliard
15 typedef void (*destroy_object
)(K32OBJ
*);
17 extern void VIRTUAL_DestroyMapping( K32OBJ
*obj
);
19 static const destroy_object K32OBJ_Destroy
[K32OBJ_NBOBJECTS
] =
22 NULL
, /* K32OBJ_SEMAPHORE */
23 NULL
, /* K32OBJ_EVENT */
24 NULL
, /* K32OBJ_MUTEX */
25 NULL
, /* K32OBJ_CRITICAL_SECTION */
26 PROCESS_Destroy
, /* K32OBJ_PROCESS */
27 THREAD_Destroy
, /* K32OBJ_THREAD */
28 FILE_Destroy
, /* K32OBJ_FILE */
29 NULL
, /* K32OBJ_CHANGE */
30 NULL
, /* K32OBJ_CONSOLE */
31 NULL
, /* K32OBJ_SCREEN_BUFFER */
32 VIRTUAL_DestroyMapping
, /* K32OBJ_MEM_MAPPED_FILE */
33 NULL
, /* K32OBJ_SERIAL */
34 NULL
, /* K32OBJ_DEVICE_IOCTL */
35 NULL
, /* K32OBJ_PIPE */
36 NULL
, /* K32OBJ_MAILSLOT */
37 NULL
, /* K32OBJ_TOOLHELP_SNAPSHOT */
38 NULL
/* K32OBJ_SOCKET */
49 static NAME_ENTRY
*K32OBJ_FirstEntry
= NULL
;
52 /***********************************************************************
55 void K32OBJ_IncCount( K32OBJ
*ptr
)
57 /* FIXME: not atomic */
58 assert( ptr
->type
&& ((unsigned)ptr
->type
< K32OBJ_NBOBJECTS
) );
63 /***********************************************************************
66 void K32OBJ_DecCount( K32OBJ
*ptr
)
70 /* FIXME: not atomic */
71 assert( ptr
->type
&& ((unsigned)ptr
->type
< K32OBJ_NBOBJECTS
) );
72 assert( ptr
->refcount
);
73 if (--ptr
->refcount
) return;
75 /* Check if the object has a name entry and free it */
77 pptr
= &K32OBJ_FirstEntry
;
78 while (*pptr
&& ((*pptr
)->obj
!= ptr
)) pptr
= &(*pptr
)->next
;
81 NAME_ENTRY
*entry
= *pptr
;
83 HeapFree( SystemHeap
, 0, entry
);
88 if (K32OBJ_Destroy
[ptr
->type
]) K32OBJ_Destroy
[ptr
->type
]( ptr
);
92 /***********************************************************************
95 * Add a name entry for an object. We don't check for duplicates here.
96 * FIXME: should use some sort of hashing.
98 BOOL32
K32OBJ_AddName( K32OBJ
*obj
, LPCSTR name
)
100 NAME_ENTRY
*entry
= K32OBJ_FirstEntry
;
101 UINT32 len
= strlen( name
);
103 if (!(entry
= HeapAlloc( SystemHeap
, 0, sizeof(entry
) + len
)))
105 SetLastError( ERROR_OUTOFMEMORY
);
108 entry
->next
= K32OBJ_FirstEntry
;
110 lstrcpy32A( entry
->name
, name
);
111 K32OBJ_FirstEntry
= entry
;
116 /***********************************************************************
119 * Find the object referenced by a given name.
120 * The reference count is not incremented.
122 K32OBJ
*K32OBJ_FindName( LPCSTR name
)
124 NAME_ENTRY
*entry
= K32OBJ_FirstEntry
;
127 if (!name
) return NULL
; /* Anonymous object */
128 len
= strlen( name
);
131 if ((len
== entry
->len
) && !lstrcmp32A( name
, entry
->name
))
139 /***********************************************************************
140 * K32OBJ_FindNameType
142 * Find an object by name and check its type.
143 * The reference count is not incremented.
145 K32OBJ
*K32OBJ_FindNameType( LPCSTR name
, K32OBJ_TYPE type
)
147 K32OBJ
*obj
= K32OBJ_FindName( name
);
148 if (!obj
) return NULL
;
149 if (obj
->type
== type
) return obj
;
150 SetLastError( ERROR_DUP_NAME
);