+ if (evt == NULL)
+ goto error;
+
+ /* initialize the event */
+ evt->watchs = NULL;
+ memcpy(evt->name, name, len + 1);
+
+ /* allocates the id */
+ pthread_mutex_lock(&events_mutex);
+ do {
+ if (++event_id_counter < 0) {
+ event_id_wrapped = 1;
+ event_id_counter = 1024; /* heuristic: small numbers are not destroyed */
+ }
+ if (!event_id_wrapped)
+ break;
+ evt = events;
+ while(evt != NULL && evt->id != event_id_counter)
+ evt = evt->next;
+ } while (evt != NULL);
+
+ /* initialize the event */
+ memcpy(evt->name, name, len + 1);
+ evt->next = events;
+ evt->watchs = NULL;
+ evt->id = event_id_counter;
+ pthread_mutex_init(&evt->mutex, NULL);
+ events = evt;
+ pthread_mutex_unlock(&events_mutex);
+
+ /* returns the event */