Changeset 1329
- Timestamp:
- 12/03/08 10:46:09 (10 months ago)
- Files:
-
- trunk/lib/format_dag25.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/format_dag25.c
r1328 r1329 73 73 int fd; 74 74 uint16_t ref_count; 75 struct dag_dev_t *prev; 75 76 struct dag_dev_t *next; 76 77 }; … … 99 100 struct dag_dev_t *dag_dev; 100 101 101 pthread_mutex_lock(&open_dag_mutex);102 102 dag_dev = open_dags; 103 103 … … 106 106 while (dag_dev != NULL) { 107 107 if (strcmp(dag_dev->dev_name, dev_name) == 0) { 108 pthread_mutex_unlock(&open_dag_mutex);108 dag_dev->ref_count ++; 109 109 return dag_dev; 110 110 … … 112 112 dag_dev = dag_dev->next; 113 113 } 114 pthread_mutex_unlock(&open_dag_mutex);115 114 return NULL; 116 115 … … 120 119 static void dag_close_device(struct dag_dev_t *dev) { 121 120 /* Need to remove from the device list */ 122 struct dag_dev_t *prev, *d; 123 124 prev = NULL; 125 pthread_mutex_lock(&open_dag_mutex); 126 127 d = open_dags; 128 129 while (d != NULL) { 130 if (strcmp(dev->dev_name, d->dev_name) == 0) { 131 /* Found it! */ 132 if (prev == NULL) { 133 open_dags = d->next; 134 } else { 135 prev->next = d->next; 136 } 137 assert(d->ref_count == 0); 138 dag_close(d->fd); 139 free(d->dev_name); 140 free(d); 141 return; 142 } 143 prev = d; 144 d = d->next; 145 } 146 147 /* Not sure what we do here - we've been asked to close a 148 * device that isn't in our linked list - probably safest to 149 * just return. Is there anything else we can really do? */ 150 return; 121 122 assert(dev->ref_count == 0); 123 124 if (dev->prev == NULL) { 125 open_dags = dev->next; 126 if (dev->next) 127 dev->next->prev = NULL; 128 } else { 129 dev->prev->next = dev->next; 130 if (dev->next) 131 dev->next->prev = dev->prev; 132 } 133 134 dag_close(dev->fd); 135 free(dev->dev_name); 136 free(dev); 137 151 138 } 152 139 … … 176 163 new_dev->fd = fd; 177 164 new_dev->dev_name = dev_name; 178 new_dev->ref_count = 0;179 180 pthread_mutex_lock(&open_dag_mutex);165 new_dev->ref_count = 1; 166 167 new_dev->prev = NULL; 181 168 new_dev->next = open_dags; 169 if (open_dags) 170 open_dags->prev = new_dev; 171 182 172 open_dags = new_dev; 183 pthread_mutex_unlock(&open_dag_mutex);184 173 185 174 return new_dev; … … 193 182 struct dag_dev_t *dag_device = NULL; 194 183 184 pthread_mutex_lock(&open_dag_mutex); 195 185 if ((scan = strchr(libtrace->uridata,',')) == NULL) { 196 186 dag_dev_name = strdup(libtrace->uridata); … … 225 215 226 216 227 dag_device->ref_count ++;228 217 229 218 DUCK.last_duck = 0; … … 235 224 FORMAT_DATA->drops = 0; 236 225 226 pthread_mutex_unlock(&open_dag_mutex); 237 227 return 0; 238 228 } … … 327 317 328 318 static int dag_fin_input(libtrace_t *libtrace) { 319 pthread_mutex_lock(&open_dag_mutex); 329 320 if (FORMAT_DATA->stream_attached) 330 321 dag_pause_input(libtrace); … … 336 327 trace_destroy_dead(DUCK.dummy_duck); 337 328 free(libtrace->format_data); 329 pthread_mutex_unlock(&open_dag_mutex); 338 330 return 0; /* success */ 339 331 }
