/* ============== ResetEdicts ============== */ void Level::ResetEdicts( void ) { int i; memset( g_entities, 0, game.maxentities * sizeof( g_entities[ 0 ] ) ); // Add all the edicts to the free list LL_Reset( &free_edicts, next, prev ); LL_Reset( &active_edicts, next, prev ); for( i = 0; i < game.maxentities; i++ ) { LL_Add( &free_edicts, &g_entities[ i ], next, prev ); } for( i = 0; i < game.maxclients; i++ ) { //char savedTeamName[ 16 ]; // set client fields on player ents g_entities[ i ].client = game.clients + i; //strcpy( savedTeamName, game.clients[i].pers.lastTeam ); G_InitClientPersistant (&game.clients[i]); //strcpy( game.clients[i].pers.lastTeam, savedTeamName ); } globals.num_entities = game.maxclients; }
schedule_t * New_Schedule (char *description, trace_t *tr) { schedule_t *schedule; schedule = New (schedule_t); schedule->ll_events = LL_Create (LL_DestroyFunction, Deref_Event, 0); if (description == NULL) description = strdup ("unknown"); schedule->description = strdup (description); /* this trace condition is delegated from the caller */ schedule->trace = tr; schedule->lastrun = 0; schedule->maxnum = 0; schedule->is_running = 0; schedule->can_pass = 0; #ifdef HAVE_LIBPTHREAD pthread_cond_init (&schedule->cond_new_event, NULL); #endif /* HAVE_LIBPTHREAD */ pthread_mutex_init (&schedule->mutex_cond_lock, NULL); pthread_mutex_init (&schedule->mutex_lock, NULL); pthread_mutex_lock (&SCHEDULE_MASTER->mutex_lock); LL_Add (SCHEDULE_MASTER->ll_schedules, schedule); pthread_mutex_unlock (&SCHEDULE_MASTER->mutex_lock); return (schedule); }
static void midi_dispose_buffer(MidiBuffer * node, const char * caller) { MMRESULT rv; if (node->prepared) { rv = midiOutUnprepareHeader( (HMIDIOUT) midiStream, &node->hdr, sizeof(MIDIHDR) ); if (rv != MMSYSERR_NOERROR) { midi_error(rv, "WinMM %s/midi_dispose_buffer midiOutUnprepareHeader", caller); } node->prepared = FALSE; } if (midiThread) { // remove the node from the activeMidiBuffers list LL_Remove( node, next, prev ); // when playing, we keep the buffers LL_Add( (MidiBuffer*) &spareMidiBuffers, node, next, prev ); //fprintf(stderr, "WinMM %s/midi_dispose_buffer recycling buffer %p\n", caller, node); } else { // when not, we throw them away free(node); //fprintf(stderr, "WinMM %s/midi_dispose_buffer freeing buffer %p\n", caller, node); } }
/* pick_off_secondary_fields * store some information like as_origin, communities, * and secondary indicie keys * Need some error checking added --ljb XXX */ void pick_off_secondary_fields (char *buffer, int curr_f, irr_object_t *irr_object) { char *cp = buffer; char *tmpptr; switch (curr_f) { case ORIGIN: /* if origin already found, ignore continuation lines */ if (irr_object->origin_found) break; whitespace_newline_remove(cp); cp += 2; /* Check for dots for now, can remove as asplain is standardized */ if ( (tmpptr = strchr(cp,'.')) != NULL) { *tmpptr = 0; irr_object->origin = atoi(cp)*65536 + atoi(tmpptr + 1); *tmpptr = '.'; irr_object->origin_found = 1; } else { if (convert_to_32(cp, &irr_object->origin) != 1) { irr_object->origin = 0; /* bogus value, need better handling */ } else irr_object->origin_found = 1; } break; case NIC_HDL: whitespace_newline_remove(cp); irr_object->nic_hdl = strdup (cp); break; case PREFIX: /* for IPv6 site objects */ if (irr_object->ll_prefix == NULL) /* create list if it does not exist */ irr_object->ll_prefix = LL_Create (LL_DestroyFunction, free, 0); whitespace_newline_remove(cp); LL_Add (irr_object->ll_prefix, strdup(cp)); break; case MNT_BY: add_field_items (cp, &irr_object->ll_mnt_by); break; case MEMBER_OF: /* ROUTE, ROUTE6 and AUT-NUM member-of: scanning */ add_field_items (cp, &irr_object->ll_mbr_of); break; case MEMBERS: case MP_MEMBERS: /* AS-SET, ROUTE-SET members: scanning */ add_field_items (cp, &irr_object->ll_mbrs); break; case MBRS_BY_REF: /* AS-SET, ROUTE-SET mbrs-by-ref: scanning */ add_field_items (cp, &irr_object->ll_mbr_by_ref); break; default: break; } }
/*----------------------------------------------------------- * Name: HASH_ToLinkedList() * Created: Fri Sep 9 00:01:14 1994 * Author: Jonathan DeKock <dekock@winter> * DESCR: converts a hash table to a linked list */ LINKED_LIST *HASH_ToLinkedList(HASH_TABLE *h, LINKED_LIST *ll) { unsigned index; #ifdef HASH_DEBUG if (!h) { if (HASH_Handler) { (HASH_Handler)(h, HASH_BadArgument, "HASH_ToLinkedList()"); } } #endif if (!ll) ll = LL_Create(0); if (h->attr & HASH_Intrusive) { DATA_PTR data; for (index = 0; index < h->size; index++) { for (data = h->array.data[index]; data; data = NextP(h, data)) { LL_Add(ll, data); } } } else { HASH_CONTAINER *cont; for (index = 0; index < h->size; index++) { for (cont = h->array.cont[index]; cont; cont = cont->next) { LL_Add(ll, cont->data); } } } #ifdef HASH_DEBUG if (h->attr & HASH_ReportAccess) { printf("HASH TABLE: 0x%.8x ToLinkedList(0x%.8x) complete\n", h, ll); } #endif #ifdef _HASH_INTERNAL_DEBUG HASH_Verify(h); #endif return(ll); }
void add_field_items (char *buf, LINKED_LIST **ll) { char *cp = buf, *last; if (*ll == NULL) /* create list if it does not exist */ *ll = LL_Create (LL_DestroyFunction, free, 0); whitespace_newline_remove (cp); strtok_r (cp, ",", &last); while (cp != NULL && *cp != '\0') { whitespace_remove (cp); /* sanity check */ if (*cp != '\0') LL_Add ((*ll), strdup (cp)); cp = strtok_r (NULL, ",", &last); } }
int schedule_event3 (schedule_t *schedule, event_t *event) { int n; /* obtain lock */ pthread_mutex_lock (&schedule->mutex_cond_lock); LL_Add (schedule->ll_events, event); schedule->new_event_flag++; n = LL_GetCount (schedule->ll_events); if (schedule->maxnum < n) schedule->maxnum = n; #ifdef HAVE_LIBPTHREAD #ifdef MRT_DEBUG trace (TR_THREAD, schedule->trace, "pthread_cond_signal for a new event\n"); #endif /* MRT_DEBUG */ pthread_cond_signal (&schedule->cond_new_event); #endif /* HAVE_LIBPTHREAD */ #ifdef MRT_DEBUG if (event->description) trace (TR_THREAD, schedule->trace, "THREAD Event %s scheduled (%d events) for %s\n", event->description, n, schedule->description); else trace (TR_THREAD, schedule->trace, "THREAD Event %x scheduled (%d events) for %s\n", event->call_fn, n, schedule->description); #endif /* MRT_DEBUG */ /* release lock */ pthread_mutex_unlock (&schedule->mutex_cond_lock); #ifdef MRT_DEBUG if (n > 5000) { trace (TR_THREAD, schedule->trace, "THREAD Over 5000 events !!!!!!"); trace (TR_THREAD, schedule->trace, "THREAD *** SCHEDULE OVERFLOW ***"); return (-1); } #endif /* MRT_DEBUG */ return (1); }
/* ================= FreeEdict Marks the edict as free ================= */ void Level::FreeEdict( gentity_t *ed ) { gclient_t *client; assert( ed != &free_edicts ); // unlink from world gi.unlinkentity ( ed ); assert( ed->next ); assert( ed->prev ); if ( next_edict == ed ) { next_edict = ed->next; } LL_Remove( ed, next, prev ); assert( ed->next == ed ); assert( ed->prev == ed ); assert( free_edicts.next ); assert( free_edicts.prev ); client = ed->client; memset( ed, 0, sizeof( *ed ) ); ed->client = client; ed->freetime = time; ed->inuse = false; ed->s.number = ed - g_entities; assert( free_edicts.next ); assert( free_edicts.prev ); LL_Add( &free_edicts, ed, next, prev ); assert( ed->next ); assert( ed->prev ); }
int add_access_list (int num, int permit, prefix_t *prefix, prefix_t *wildcard, int exact, int refine) { condition_t *condition = NULL; if (num < 0 || num >= MAX_ALIST) return (-1); if (find_access_list (num, permit, prefix, wildcard, exact, refine)) return (0); if (access_list[num] == NULL) { access_list[num] = LL_Create (0); } condition = irrd_malloc(sizeof(condition_t)); condition->permit = permit; /* expects Ref_Prefix can handle even a case of prefix == NULL */ condition->prefix = Ref_Prefix (prefix); condition->wildcard = Ref_Prefix (wildcard); condition->exact = exact; condition->refine = refine; LL_Add (access_list[num], condition); return (LL_GetCount (access_list[num])); }
static void MV_StopVoice(VoiceNode *voice) { DisableInterrupts(); // move the voice from the play list to the free list LL_Remove(voice, next, prev); LL_Add((VoiceNode*) &VoicePool, voice, next, prev); RestoreInterrupts(); switch (voice->wavetype) { #ifdef HAVE_VORBIS case FMT_VORBIS: MV_ReleaseVorbisVoice(voice); break; #endif #ifdef HAVE_FLAC case FMT_FLAC: MV_ReleaseFLACVoice(voice); break; #endif case FMT_XA: MV_ReleaseXAVoice(voice); break; default: break; } voice->handle = 0; }
/* ================= AllocEdict Either finds a free edict, or allocates a new one. Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails. ================= */ gentity_t *Level::AllocEdict( Entity *ent ) { int i; gentity_t *edict; if ( spawn_entnum >= 0 ) { edict = &g_entities[ spawn_entnum ]; spawn_entnum = -1; assert( !edict->inuse && !edict->entity ); // free up the entity pointer in case we took one that still exists if ( edict->inuse && edict->entity ) { delete edict->entity; } } else { edict = &g_entities[ maxclients->integer ]; for ( i = maxclients->integer; i < globals.num_entities; i++, edict++ ) { // the first couple seconds of server time can involve a lot of // freeing and allocating, so relax the replacement policy if ( !edict->inuse && ( ( edict->freetime < ( 2.0f + startTime ) ) || ( time - edict->freetime > 0.5f ) ) ) { break; } } // allow two spots for none and world if ( i == game.maxentities - 2.0f ) { // Try one more time before failing, relax timing completely edict = &g_entities[ maxclients->integer ]; for ( i = maxclients->integer; i < globals.num_entities; i++, edict++ ) { if ( !edict->inuse ) { break; } } if ( i == game.maxentities - 2.0f ) { gi.Error( ERR_DROP, "Level::AllocEdict: no free edicts" ); } } } assert( edict->next ); assert( edict->prev ); LL_Remove( edict, next, prev ); InitEdict( edict ); assert( active_edicts.next ); assert( active_edicts.prev ); LL_Add( &active_edicts, edict, next, prev ); assert( edict->next ); assert( edict->prev ); assert( edict->next != &free_edicts ); assert( edict->prev != &free_edicts ); // Tell the server about our data since we just spawned something if ( ( edict->s.number < ENTITYNUM_WORLD ) && ( globals.num_entities <= edict->s.number ) ) { globals.num_entities = edict->s.number + 1; gi.LocateGameData( g_entities, globals.num_entities, sizeof( gentity_t ), &game.clients[ 0 ].ps, sizeof( game.clients[ 0 ] ) ); } edict->entity = ent; edict->s.instanceNumber = currentInstanceNumber; currentInstanceNumber++; if ( currentInstanceNumber < 0 ) currentInstanceNumber = 0; return edict; }
static void read_ascii (FILE *fd, io_t *IO) { LINKED_LIST *ll_ann, *ll_with; bgp_attr_t *attr; int announce_flag = 0; int line_num = 0; int have_data = 0; int have_data2 = 0; time_t tstamp = 0; int type = 0; int subtype = 0; int bgptype = 0; int newtype = 0; gateway_t *gateway_from = NULL; gateway_t *gateway_to = NULL; int first = 1; u_char bgp_packet[BGPMAXPACKETSIZE], *bp = bgp_packet; u_char buffer[MAX_MSG_SIZE], *buffer_p = buffer; u_char *end = buffer + sizeof (buffer); int eof = 0; buffer_t *stdbuf; int state1 = 0, state2 = 0; int version = 0, as = 0, holdtime = 0, optlen = 0; u_long id = 0; int code = 0, subcode = 0; int viewno = 0; char *filename = NULL; prefix_t *route_prefix = NULL; time_t originated = 0; u_long status = 0; int seq_num = 0; attr = bgp_new_attr (PROTO_BGP); ll_ann = LL_Create (LL_DestroyFunction, Deref_Prefix, 0); ll_with = LL_Create (LL_DestroyFunction, Deref_Prefix, 0); stdbuf = New_Buffer_Stream (fd); for (;;) { char *line = NULL, *ret = NULL; int len = 0; int ok = 0; char *cp; if (buffer_gets (stdbuf) <= 0) { eof++; } else { len = buffer_data_len (stdbuf); line = buffer_data (stdbuf); if (line[len - 1] == '\n') { line[len - 1] = '\0'; len--; } trace (TR_TRACE, MRT->trace, "++%s\n", line); line_num++; if ((cp = strpbrk (line, "#!")) != NULL) { *cp = '\0'; len = cp - line; } if (first && nulline (line)) continue; first = 0; } if (eof || nulline (line)) { if (have_data && have_data2) { trace (TR_ERROR, MRT->trace, "Mixture of two formats\n"); goto error; } if (bgptype == BGP_UPDATE && have_data) { flushout (IO, tstamp, type, subtype, attr, ll_ann, ll_with, gateway_to); } else if (have_data2) { flushout2 (IO, tstamp, type, subtype, bgp_packet, bp - bgp_packet, gateway_from, gateway_to); } else if (bgptype == BGP_KEEPALIVE) { if (type == MSG_PROTOCOL_BGP4MP) { memset (bgp_packet, 0xff, BGP_HEADER_MARKER_LEN); BGP_PUT_HDRTYPE (bgptype, bgp_packet); bp = bgp_packet + BGP_HEADER_LEN; BGP_PUT_HDRLEN (bp - bgp_packet, bgp_packet); } else { bp = bgp_packet; } flushout2 (IO, tstamp, type, subtype, bgp_packet, bp - bgp_packet, gateway_from, gateway_to); } else if (bgptype == BGP_OPEN) { if (type == MSG_PROTOCOL_BGP4MP) { memset (bgp_packet, 0xff, BGP_HEADER_MARKER_LEN); BGP_PUT_HDRTYPE (bgptype, bgp_packet); bp = bgp_packet + BGP_HEADER_LEN; } else { bp = bgp_packet; } BGP_PUT_BYTE (version, bp); BGP_PUT_SHORT (as, bp); BGP_PUT_SHORT (holdtime, bp); BGP_PUT_NETLONG (id, bp); BGP_PUT_BYTE (0, bp); /* XXX */ if (type == MSG_PROTOCOL_BGP4MP) { BGP_PUT_HDRLEN (bp - bgp_packet, bgp_packet); } flushout2 (IO, tstamp, type, subtype, bgp_packet, bp - bgp_packet, gateway_from, gateway_to); } else if (bgptype == BGP_NOTIFY) { if (type == MSG_PROTOCOL_BGP4MP) { memset (bgp_packet, 0xff, BGP_HEADER_MARKER_LEN); BGP_PUT_HDRTYPE (bgptype, bgp_packet); bp = bgp_packet + BGP_HEADER_LEN; } else { bp = bgp_packet; } BGP_PUT_BYTE (code, bp); BGP_PUT_BYTE (subcode, bp); if (type == MSG_PROTOCOL_BGP4MP) { BGP_PUT_HDRLEN (bp - bgp_packet, bgp_packet); } flushout2 (IO, tstamp, type, subtype, bgp_packet, bp - bgp_packet, gateway_from, gateway_to); } else if (newtype == BGP4MP_STATE_CHANGE) { bp = bgp_packet; BGP_PUT_SHORT (state1, bp); BGP_PUT_SHORT (state2, bp); flushout2 (IO, tstamp, type, subtype, bgp_packet, bp - bgp_packet, gateway_from, NULL); } else if (newtype == BGP4MP_SNAPSHOT) { bp = bgp_packet; BGP_PUT_SHORT (viewno, bp); if (filename) BGP_PUT_DATA (filename, strlen (filename), bp); BGP_PUT_BYTE (0, bp); trace_mrt_header (MRT->trace, tstamp, type, subtype); io_write (IO, tstamp, type, subtype, bp - bgp_packet, bgp_packet); } else if (newtype == BGP4MP_ENTRY) { if (route_prefix != NULL) { buffer_p = bgp_table_dump_entry (buffer_p, end, type, subtype, viewno, route_prefix, status, originated, attr); } if (buffer_p - buffer > 0) { trace_mrt_header (MRT->trace, tstamp, type, subtype); io_write (IO, tstamp, type, subtype, buffer_p - buffer, buffer); } } if (eof) break; if (MRT->force_exit_flag) exit (1); bgp_deref_attr (attr); attr = bgp_new_attr (PROTO_BGP); LL_Clear (ll_ann); LL_Clear (ll_with); announce_flag = 0; have_data = 0; have_data2 = 0; tstamp = 0; type = 0; subtype = 0; bgptype = 0; newtype = 0; gateway_to = NULL; gateway_from = NULL; route_prefix = NULL; seq_num = 0; first = 1; if (filename) free (filename); filename = NULL; continue; } if (have_data) { /* a prefix -- line begins with a space */ if (isspace (line[0])) { prefix_t *prefix; char *cp = line +1; while (isspace (*cp)) cp++; if ((prefix = ascii2prefix (0, cp)) != NULL) { if (announce_flag == 1) { LL_Add (ll_ann, prefix); } else { LL_Add (ll_with, prefix); } continue; } } } if (have_data2) { prefix_t *prefix; int num; u_long value; if (isspace (line[0]) && strpbrk (line, ".:") && strchr (line, '/') && parse_line (line, "%d %m", &num, &prefix) == 2) { u_char *here = bp; /* v4 or v6 address with prefixlen */ #ifdef HAVE_IPV6 if (prefix->family == AF_INET6) BGP_PUT_PREFIX6 (prefix->bitlen, prefix_tochar (prefix), bp); else #endif /* HAVE_IPV6 */ BGP_PUT_PREFIX (prefix->bitlen, prefix_tochar (prefix), bp); Deref_Prefix (prefix); if (num != bp - here) { trace (TR_ERROR, MRT->trace, "length was %d but must be %d\n", num, bp - here); goto error; } continue; } else if (isspace (line[0]) && strpbrk (line, ".:") && parse_line (line, "%d %M", &num, &prefix) == 2) { /* v4 or v6 address w/o prefixlen */ if (prefix->family == AF_INET6 && num > 16) { trace (TR_ERROR, MRT->trace, "length was %d but must be less than or equal %d\n", num, 16); Deref_Prefix (prefix); goto error; } if (prefix->family == AF_INET && num > 4) { trace (TR_ERROR, MRT->trace, "length was %d but must be less than or equal %d\n", num, 4); Deref_Prefix (prefix); goto error; } BGP_PUT_DATA (prefix_tochar (prefix), num, bp); Deref_Prefix (prefix); continue; } else if (isspace (line[0]) && parse_line (line, "%d %i", &num, &value) == 2) { if (num == 1) BGP_PUT_BYTE (value, bp); else if (num == 2) BGP_PUT_SHORT (value, bp); else if (num == 4) BGP_PUT_LONG (value, bp); else { trace (TR_ERROR, MRT->trace, "unknown length %d\n", num); goto error; } continue; } } if ((ret = checkstradvance (line, "TIME"))) { struct tm tm; if (strptime (ret, "%D %T", &tm)) { time_t now; time (&now); tm.tm_isdst = localtime (&now)->tm_isdst; adjust_y2k (&tm); tstamp = mktime (&tm); } } else if ((ret = checkstradvance (line, "TO"))) { int as; char data[MAXLINE]; prefix_t *prefix; if (sscanf (ret, "%s AS%d", data, &as) >= 2 || sscanf (ret, "AS%d %s", &as, data) >= 2 /* obsolete */) { prefix = ascii2prefix (0, data); gateway_to = add_gateway (prefix, as, NULL); Deref_Prefix (prefix); } } else if ((ret = checkstradvance (line, "FROM"))) { int as; char data[MAXLINE]; if (sscanf (ret, "%s AS%d", data, &as) >= 2 || sscanf (ret, "AS%d %s", &as, data) >= 2 /* obsolete */) { prefix_t *prefix = ascii2prefix (0, data); gateway_from = add_gateway (prefix, as, NULL); attr->gateway = gateway_from; Deref_Prefix (prefix); } } /* type BGP/UPDATE */ else if ((ret = checkstradvance (line, "TYPE"))) { char *subtypestr; char **cpp; int i; if ((subtypestr = strchr (ret, '/')) != NULL) *subtypestr++ = '\0'; cpp = S_MRT_MSG_TYPES; for (i = 0; cpp[i]; i++) { if (strcasecmp (cpp[i], ret) == 0) break; } type = (enum MRT_MSG_TYPES) i; if (subtypestr) { char *subsubtypestr; if ((subsubtypestr = strchr (subtypestr, '/')) != NULL) *subsubtypestr++ = '\0'; if ((cpp = S_MRT_MSG_SUBTYPES[type]) != NULL) { for (i = 0; cpp[i]; i++) { if (strcasecmp (cpp[i], subtypestr) == 0) break; } subtype = i; } newtype = subtype; if (type == MSG_PROTOCOL_BGP || type == MSG_PROTOCOL_BGP4PLUS || type == MSG_PROTOCOL_BGP4PLUS_01) { if (subtype == MSG_BGP_UPDATE) { bgptype = BGP_UPDATE; newtype = BGP4MP_MESSAGE; } else if (subtype == MSG_BGP_KEEPALIVE) { bgptype = BGP_KEEPALIVE; newtype = BGP4MP_MESSAGE; } else if (subtype == MSG_BGP_NOTIFY) { bgptype = BGP_NOTIFY; newtype = BGP4MP_MESSAGE; } else if (subtype == MSG_BGP_OPEN) { bgptype = BGP_OPEN; newtype = BGP4MP_MESSAGE; } else if (subtype == MSG_BGP_SYNC) { newtype = BGP4MP_SNAPSHOT; } else if (subtype == MSG_BGP_STATE_CHANGE) { newtype = BGP4MP_STATE_CHANGE; } else if (subtype == MSG_TABLE_DUMP) { newtype = BGP4MP_ENTRY; } } else if (type == MSG_PROTOCOL_BGP4MP && ( subtype == BGP4MP_MESSAGE || subtype == BGP4MP_MESSAGE_OLD)) { for (i = 0; sbgp_pdus[i]; i++) { if (strcasecmp (sbgp_pdus[i], subsubtypestr) == 0) { bgptype = i; break; } } } } if (type == MSG_PROTOCOL_BGP || type == MSG_PROTOCOL_BGP4PLUS || type == MSG_PROTOCOL_BGP4PLUS_01 || type == MSG_TABLE_DUMP || type == MSG_PROTOCOL_BGP4MP ) { /* OK */ } else { trace (TR_ERROR, MRT->trace, "Unknown message type %s at line %d\n", ret, line_num); goto error; } } else if ((ret = checkstradvance (line, "DATA"))) { bp = bgp_packet; have_data2++; } else if (newtype == BGP4MP_STATE_CHANGE && (ret = checkstradvance (line, "PEER"))) { int as; char data[MAXLINE]; if (sscanf (ret, "%s AS%d", data, &as) >= 2 || sscanf (ret, "AS%d %s", &as, data) >= 2 /* obsolete */) { prefix_t *prefix = ascii2prefix (0, data); gateway_from = add_gateway (prefix, as, NULL); Deref_Prefix (prefix); } } else if (newtype == BGP4MP_STATE_CHANGE && (ret = checkstradvance (line, "STATE"))) { char *cp = strchr (ret, '/'); int i; if (cp == NULL) goto error; *cp++ = '\0'; for (i = 0; sbgp_states[i]; i++) { if (strcasecmp (sbgp_states[i], ret) == 0) { state1 = i; } } for (i = 0; sbgp_states[i]; i++) { if (strcasecmp (sbgp_states[i], cp) == 0) { state2 = i; } } } else if ((newtype == BGP4MP_SNAPSHOT || newtype == BGP4MP_ENTRY) && (ret = checkstradvance (line, "VIEW"))) { viewno = atoi (ret); } else if (newtype == BGP4MP_SNAPSHOT && (ret = checkstradvance (line, "FILE"))) { if (filename) free (filename); filename = strdup (ret); } else if (newtype == BGP4MP_ENTRY && (ret = checkstradvance (line, "PREFIX"))) { if (route_prefix == NULL) { buffer_p = buffer; if (type == MSG_TABLE_DUMP) { BGP_PUT_SHORT (viewno, buffer_p); BGP_PUT_SHORT (seq_num, buffer_p); } } else { buffer_p = bgp_table_dump_entry (buffer_p, end, type, subtype, viewno, route_prefix, status, originated, attr); } route_prefix = ascii2prefix (0, ret); bgp_deref_attr (attr); attr = bgp_new_attr (PROTO_BGP); } else if (newtype == BGP4MP_ENTRY && (ret = checkstradvance (line, "SEQUENCE"))) { seq_num = atoi (ret); } else if (newtype == BGP4MP_ENTRY && (ret = checkstradvance (line, "ORIGINATED"))) { struct tm tm; if (strptime (ret, "%D %T", &tm)) { time_t now; time (&now); tm.tm_isdst = localtime (&now)->tm_isdst; adjust_y2k (&tm); originated = mktime (&tm); } } else if (newtype == BGP4MP_ENTRY && (ret = checkstradvance (line, "STATUS"))) { sscanf (ret, "%li", &status); } else if (bgptype == BGP_OPEN && (ret = checkstradvance (line, "VERSION"))) { version = atoi (ret); } else if (bgptype == BGP_OPEN && (ret = checkstradvance (line, "AS"))) { as = atoi (ret); } else if (bgptype == BGP_OPEN && (ret = checkstradvance (line, "HOLD_TIME"))) { holdtime = atoi (ret); } else if (bgptype == BGP_OPEN && (ret = checkstradvance (line, "ID"))) { inet_pton (AF_INET, ret, &id); } else if (bgptype == BGP_OPEN && (ret = checkstradvance (line, "OPT_PARM_LEN"))) { optlen = atoi (ret); } else if (bgptype == BGP_NOTIFY && (ret = checkstradvance (line, "CODE"))) { char *cp; code = atoi (ret); if ((cp = strchr (ret, '/')) != NULL) subcode = atoi (cp + 1); } else if (bgptype == BGP_UPDATE && (ret = checkstradvance (line, "ANNOUNCE"))) { announce_flag = 1; have_data++; } else if (bgptype == BGP_UPDATE && (ret = checkstradvance (line, "WITHDRAW"))) { announce_flag = 0; have_data++; } else if ((bgptype == BGP_UPDATE || newtype == BGP4MP_ENTRY) && (ok = bgp_scan_attr (line, attr, MRT->trace)) > 0) { /* OK */ } else if ((bgptype == BGP_UPDATE || newtype == BGP4MP_ENTRY) && ok < 0) { trace (TR_ERROR, MRT->trace, "Invalid BGP attribute at line %d\n", line_num); goto error; } else { trace (TR_ERROR, MRT->trace, "Unrecognized line at %d\n", line_num); goto error; } } error: if (filename) free (filename); bgp_deref_attr (attr); LL_Destroy (ll_ann); LL_Destroy (ll_with); Delete_Buffer (stdbuf); }
static void midi_flush_current_buffer(void) { MMRESULT rv; MIDIEVENT * evt; BOOL needsPrepare = FALSE; if (!currentMidiBuffer) { return; } evt = (MIDIEVENT *) currentMidiBuffer->hdr.lpData; if (!midiThread) { // immediate messages don't use a MIDIEVENT header so strip it off and // make some adjustments currentMidiBuffer->hdr.dwBufferLength = currentMidiBuffer->hdr.dwBytesRecorded - 12; currentMidiBuffer->hdr.dwBytesRecorded = 0; currentMidiBuffer->hdr.lpData = (LPSTR) &evt->dwParms[0]; if (currentMidiBuffer->hdr.dwBufferLength > 0) { needsPrepare = TRUE; } } else { needsPrepare = TRUE; } if (needsPrepare) { // playing a file, or sending a sysex when not playing means // we need to prepare the buffer rv = midiOutPrepareHeader( (HMIDIOUT) midiStream, ¤tMidiBuffer->hdr, sizeof(MIDIHDR) ); if (rv != MMSYSERR_NOERROR) { midi_error(rv, "WinMM midi_flush_current_buffer midiOutPrepareHeader"); return; } currentMidiBuffer->prepared = TRUE; } if (midiThread) { // midi file playing, so send events to the stream LL_Add( (MidiBuffer*) &activeMidiBuffers, currentMidiBuffer, next, prev ); rv = midiStreamOut(midiStream, ¤tMidiBuffer->hdr, sizeof(MIDIHDR)); if (rv != MMSYSERR_NOERROR) { midi_error(rv, "WinMM midi_flush_current_buffer midiStreamOut"); midi_dispose_buffer(currentMidiBuffer, "midi_flush_current_buffer"); return; } //fprintf(stderr, "WinMM midi_flush_current_buffer queued buffer %p\n", currentMidiBuffer); } else { // midi file not playing, so send immediately if (currentMidiBuffer->hdr.dwBufferLength > 0) { rv = midiOutLongMsg( (HMIDIOUT) midiStream, ¤tMidiBuffer->hdr, sizeof(MIDIHDR) ); if (rv == MMSYSERR_NOERROR) { // busy-wait for Windows to be done with it while (!(currentMidiBuffer->hdr.dwFlags & MHDR_DONE)) ; //fprintf(stderr, "WinMM midi_flush_current_buffer sent immediate long\n"); } else { midi_error(rv, "WinMM midi_flush_current_buffer midiOutLongMsg"); } } else { rv = midiOutShortMsg( (HMIDIOUT) midiStream, evt->dwEvent ); if (rv == MMSYSERR_NOERROR) { //fprintf(stderr, "WinMM midi_flush_current_buffer sent immediate short\n"); } else { midi_error(rv, "WinMM midi_flush_current_buffer midiOutShortMsg"); } } midi_dispose_buffer(currentMidiBuffer, "midi_flush_current_buffer"); } currentMidiBuffer = 0; }
int32_t MV_Init(int32_t soundcard, int32_t MixRate, int32_t Voices, int32_t numchannels, void *initdata) { if (MV_Installed) MV_Shutdown(); MV_SetErrorCode(MV_Ok); // MV_TotalMemory + 2: FIXME, see valgrind_errors.log int const totalmem = Voices * sizeof(VoiceNode) + MV_TOTALBUFFERSIZE + 2; #ifdef _3DS char *ptr = (char *) linearAlloc( totalmem); #else char *ptr = (char *) Xaligned_alloc(16, totalmem); #endif if (!ptr) { MV_SetErrorCode(MV_NoMem); return MV_Error; } Bmemset(ptr, 0, totalmem); MV_Voices = (VoiceNode *)ptr; ptr += Voices * sizeof(VoiceNode); // Set number of voices before calculating volume table MV_MaxVoices = Voices; LL_Reset((VoiceNode*) &VoiceList, next, prev); LL_Reset((VoiceNode*) &VoicePool, next, prev); for (int index = 0; index < Voices; index++) { LL_Add((VoiceNode*) &VoicePool, &MV_Voices[ index ], next, prev); } MV_SetReverseStereo(FALSE); ASS_SoundDriver = soundcard; // Initialize the sound card if (SoundDriver_Init(&MixRate, &numchannels, initdata) != MV_Ok) MV_SetErrorCode(MV_DriverError); if (MV_ErrorCode != MV_Ok) { ALIGNED_FREE_AND_NULL(MV_Voices); return MV_Error; } MV_Installed = TRUE; MV_CallBackFunc = NULL; MV_ReverbLevel = 0; MV_ReverbTable = NULL; // Set the sampling rate MV_MixRate = MixRate; // Set Mixer to play stereo digitized sound MV_SetMixMode(numchannels); MV_ReverbDelay = MV_BufferSize * 3; // Make sure we don't cross a physical page MV_MixBuffer[ MV_NumberOfBuffers ] = ptr; for (int buffer = 0; buffer < MV_NumberOfBuffers; buffer++) { MV_MixBuffer[ buffer ] = ptr; ptr += MV_BufferSize; } // Calculate pan table MV_CalcPanTable(); MV_SetVolume(MV_MAXTOTALVOLUME); // Start the playback engine if (MV_StartPlayback() != MV_Ok) { // Preserve error code while we shutdown. int status = MV_ErrorCode; MV_Shutdown(); MV_SetErrorCode(status); return MV_Error; } return MV_Ok; }
/*--------------------------------------------------------------------- JBF: no synchronisation happens inside MV_ServiceVoc nor the supporting functions it calls. This would cause a deadlock between the mixer thread in the driver vs the nested locking in the user-space functions of MultiVoc. The call to MV_ServiceVoc is synchronised in the driver. ---------------------------------------------------------------------*/ static void MV_ServiceVoc(void) { // Toggle which buffer we'll mix next if (++MV_MixPage >= MV_NumberOfBuffers) MV_MixPage -= MV_NumberOfBuffers; if (MV_ReverbLevel == 0) { // Initialize buffer //Commented out so that the buffer is always cleared. //This is so the guys at Echo Speech can mix into the //buffer even when no sounds are playing. if (!MV_BufferEmpty[MV_MixPage]) { Bmemset(MV_MixBuffer[MV_MixPage], 0, MV_BufferSize); MV_BufferEmpty[ MV_MixPage ] = TRUE; } } else { char const *const end = MV_MixBuffer[0] + MV_BufferLength; char *dest = MV_MixBuffer[MV_MixPage]; char const *source = MV_MixBuffer[MV_MixPage] - MV_ReverbDelay; if (source < MV_MixBuffer[ 0 ]) source += MV_BufferLength; int32_t length = MV_BufferSize; while (length > 0) { int const count = (source + length > end) ? (end - source) : length; MV_16BitReverb(source, dest, MV_ReverbTable, count / 2); // if we go through the loop again, it means that we've wrapped around the buffer source = MV_MixBuffer[ 0 ]; dest += count; length -= count; } } // Play any waiting voices //DisableInterrupts(); VoiceNode *voice; if (!VoiceList.next || (voice = VoiceList.next) == &VoiceList) return; int iter = 0; VoiceNode *next; do { next = voice->next; if (++iter > MV_MaxVoices && MV_Printf) MV_Printf("more iterations than voices! iter: %d\n",iter); if (voice->Paused) continue; MV_BufferEmpty[ MV_MixPage ] = FALSE; MV_Mix(voice, MV_MixPage); // Is this voice done? if (!voice->Playing) { //JBF: prevent a deadlock caused by MV_StopVoice grabbing the mutex again //MV_StopVoice( voice ); LL_Remove(voice, next, prev); LL_Add((VoiceNode*) &VoicePool, voice, next, prev); switch (voice->wavetype) { #ifdef HAVE_VORBIS case FMT_VORBIS: MV_ReleaseVorbisVoice(voice); break; #endif #ifdef HAVE_FLAC case FMT_FLAC: MV_ReleaseFLACVoice(voice); break; #endif case FMT_XA: MV_ReleaseXAVoice(voice); break; default: break; } voice->handle = 0; if (MV_CallBackFunc) MV_CallBackFunc(voice->callbackval); } } while ((voice = next) != &VoiceList); //RestoreInterrupts(); }