Changeset 3457
- Timestamp:
- 07/17/08 12:41:39 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/opensync/xmlformat/opensync_xmlformat_schema.c
r3452 r3457 26 26 #include "opensync-xmlformat.h" 27 27 #include "opensync-xmlformat_internals.h" 28 29 static GList *schemas = NULL; 30 static GStaticMutex schema_mutex = G_STATIC_MUTEX_INIT; 31 32 static void _osync_xmlformat_schema_lock_mutex() { 33 g_static_mutex_lock(&schema_mutex); 34 } 35 36 static void _osync_xmlformat_schema_unlock_mutex() { 37 g_static_mutex_unlock(&schema_mutex); 38 } 39 28 40 29 41 /** … … 56 68 } 57 69 osyncschema->objtype = g_strdup(osync_xmlformat_get_objtype(xmlformat)); 70 58 71 char *schemafilepath = g_strdup_printf("%s%c%s%s%s", 59 72 path ? path : OPENSYNC_SCHEMASDIR, … … 109 122 110 123 OSyncXMLFormatSchema *osync_xmlformat_schema_get_instance_with_path(OSyncXMLFormat *xmlformat, const char *schemadir, OSyncError **error) { 111 static GList *schemas = NULL;112 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;113 124 OSyncXMLFormatSchema *osyncschema = NULL; 114 125 GList * entry; … … 120 131 121 132 objtype = osync_xmlformat_get_objtype(xmlformat); 133 122 134 // get mutex 123 g_static_mutex_lock(&mutex);135 _osync_xmlformat_schema_lock_mutex(); 124 136 // find schema for objtype 125 for ( entry = schemas; entry != NULL; entry=entry->next) { // should be fast enough for only a few objtypes137 for ( entry = g_list_first(schemas); entry != NULL; entry = g_list_next(entry)) { // should be fast enough for only a few objtypes 126 138 osyncschema = (OSyncXMLFormatSchema *) entry->data; 139 osync_assert(osyncschema->objtype); 127 140 if (!strcmp(osyncschema->objtype, objtype) ) { 128 141 osync_xmlformat_schema_ref(osyncschema); 129 return osyncschema;142 goto exit; 130 143 } 131 144 osyncschema = NULL; … … 137 150 } 138 151 } 152 exit: 139 153 // release mutex 140 g_static_mutex_unlock(&mutex);154 _osync_xmlformat_schema_unlock_mutex(); 141 155 osync_trace(TRACE_EXIT, "%s, (%p)", __func__, osyncschema ); 142 156 return osyncschema; … … 200 214 */ 201 215 void osync_xmlformat_schema_unref(OSyncXMLFormatSchema *osyncschema) { 202 216 GList *entry; 217 203 218 osync_assert(osyncschema); 204 219 205 220 if (g_atomic_int_dec_and_test(&(osyncschema->ref_count))) { 221 _osync_xmlformat_schema_lock_mutex(); 222 int number_schemas = g_list_length(schemas); 223 if ( number_schemas == 1 ) { 224 schemas = NULL; 225 } 226 else { 227 entry = g_list_remove(schemas, osyncschema); 228 } 229 _osync_xmlformat_schema_unlock_mutex(); 206 230 xmlSchemaFreeValidCtxt(osyncschema->context); 207 231 xmlSchemaFree(osyncschema->schema);
