Ejemplo n.º 1
0
void panda_assembler_unref(
	PandaAssembler assembler) {
	size_t count;
	if (assembler == NULL)
		return;
#ifdef HAVE_PTHREAD
	pthread_mutex_lock(&assembler->mutex);
#endif
	count = --(assembler->refcnt);
#ifdef HAVE_PTHREAD
	pthread_mutex_unlock(&assembler->mutex);
#endif
	if (count == 0) {
#ifdef HAVE_PTHREAD
		pthread_mutex_destroy(&assembler->mutex);
#endif
		free(assembler->kmerseen);
		module_destroy(assembler);
		DESTROY_MEMBER(assembler, next);
		DESTROY_MEMBER(assembler, noalgn);
		panda_algorithm_unref(assembler->algo);
		panda_log_proxy_unref(assembler->logger);
		free(assembler);
	}
}
Ejemplo n.º 2
0
void panda_mux_unref(
	PandaMux mux) {
	size_t count;
	if (mux == NULL)
		return;
	pthread_mutex_lock(&mux->mutex);
	count = --(mux->refcnt);
	pthread_mutex_unlock(&mux->mutex);
	if (count == 0) {
		pthread_mutex_destroy(&mux->mutex);

		panda_log_proxy_unref(mux->logger);

		pthread_mutex_lock(&mux->next_mutex);
		DESTROY_MEMBER(mux, next);
		pthread_mutex_unlock(&mux->next_mutex);
		pthread_mutex_destroy(&mux->next_mutex);

		pthread_rwlock_wrlock(&mux->noalgn_rwlock);
		DESTROY_MEMBER(mux, noalgn);
		pthread_rwlock_unlock(&mux->noalgn_rwlock);
		pthread_rwlock_destroy(&mux->noalgn_rwlock);
		free(mux);
	}
}
Ejemplo n.º 3
0
static void
stream_destroy(
	struct fastq_data *data) {
	if (data->non_empty && !data->seen_under_64 && data->qualmin < 64) {
		/* Used in the LOG macro. */
		panda_seq_identifier *id = NULL;
		LOG(PANDA_DEBUG_FILE, PANDA_CODE_PHRED_OFFSET);
	}
	DESTROY_MEMBER(&data->forward, next);
	DESTROY_MEMBER(&data->reverse, next);
	free(data);
}
Ejemplo n.º 4
0
void panda_writer_unref(
	PandaWriter writer) {
	size_t count;
	if (writer == NULL)
		return;
#ifdef HAVE_PTHREAD
	flush_buffer(writer, get_write_buffer(writer));
	pthread_mutex_lock(&writer->mutex);
#endif
	count = --(writer->refcnt);
#ifdef HAVE_PTHREAD
	pthread_mutex_unlock(&writer->mutex);
#endif
	if (count == 0) {
#ifdef HAVE_PTHREAD
		struct write_buffer *data;

		pthread_key_delete(writer->buffers);
		pthread_mutex_destroy(&writer->mutex);

		data = writer->buffer_list;
		while (data != NULL) {
			struct write_buffer *temp = data->next;
			writer->write(data->committed, data->committed_length, data->owner->write_data);
			writer->write(data->uncommitted, data->uncommitted_length, data->owner->write_data);
			free(data);
			data = temp;
		}
		if (writer->commit_slave != NULL)
			panda_writer_unref(writer->commit_slave);
#endif
		DESTROY_MEMBER(writer, write);
		free(writer);
	}
}
Ejemplo n.º 5
0
static bool
read_line(
	char *buffer,
	size_t max_len,
	struct stream_data *stream,
	size_t *len) {
	int pos = 0;
	if (stream->next == NULL)
		return false;
	while (pos < max_len) {
		int v = stream->next(stream->next_data);
		if (v == EOF) {
			DESTROY_MEMBER(stream, next);
			buffer[pos] = '\0';
			*len = pos;
			return pos > 0;
		}
		if (v == '\r' || v == '\n') {
			if (pos != 0) {
				buffer[pos] = '\0';
				return true;
			}
		} else {
			buffer[pos++] = v;
		}
	}
	return false;
}
Ejemplo n.º 6
0
void panda_linebuf_free(
    PandaLineBuf linebuf) {
    if (linebuf == NULL)
        return;
    DESTROY_MEMBER(linebuf, read);
    free(linebuf);
}
Ejemplo n.º 7
0
void hang_free(
	void *user_data) {
	struct hang_data *hang_data = (struct hang_data *) user_data;
	DESTROY_MEMBER(hang_data, next);
	panda_log_proxy_unref(hang_data->logger);
	free(hang_data);
}
Ejemplo n.º 8
0
void panda_assembler_set_fail_alignment(
	PandaAssembler assembler,
	PandaFailAlign handler,
	void *handler_data,
	PandaDestroy handler_destroy) {
	DESTROY_MEMBER(assembler, noalgn);
	assembler->noalgn = handler;
	assembler->noalgn_data = handler_data;
	assembler->noalgn_destroy = handler_destroy;
}
Ejemplo n.º 9
0
void panda_mux_set_fail_alignment(
	PandaMux mux,
	PandaFailAlign handler,
	void *handler_data,
	PandaDestroy handler_destroy) {
	pthread_rwlock_wrlock(&mux->noalgn_rwlock);
	DESTROY_MEMBER(mux, noalgn);
	mux->noalgn_data = handler_data;
	mux->noalgn_destroy = handler_destroy;
	mux->noalgn = handler;
	pthread_rwlock_unlock(&mux->noalgn_rwlock);
}
Ejemplo n.º 10
0
static bool
read_seq(
	panda_seq_identifier *id,
	panda_qual *buffer,
	size_t max_len,
	struct stream_data *stream,
	char *table,
	struct fastq_data *data,
	size_t *length) {
	int pos = 0;
	int qpos = 0;
	int v = EOF;
	if (stream->next == NULL)
		return false;
	while (pos < max_len) {
		v = stream->next(stream->next_data);
		if (v == EOF) {
			DESTROY_MEMBER(stream, next);
			LOG(PANDA_DEBUG_FILE, PANDA_CODE_PREMATURE_EOF);
			return false;
		}
		if (v == '\r' || v == '\n') {
			if (pos != 0) {
				break;
			}
		} else {
			if ((buffer[pos++].nt = table[v & 0x1F]) == '\0') {
				LOGV(PANDA_DEBUG_FILE, PANDA_CODE_BAD_NT, "%c@%d", v, pos);
				return false;
			}
		}
	}
	for (; v == '\n' || v == '\r'; v = stream->next(stream->next_data)) {
		if (v == EOF) {
			LOG(PANDA_DEBUG_FILE, PANDA_CODE_PREMATURE_EOF);
			DESTROY_MEMBER(stream, next);
			return false;
		}
	}
	if (v != '+') {
		LOG(PANDA_DEBUG_FILE, PANDA_CODE_PARSE_FAILURE);
		DESTROY_MEMBER(stream, next);
		return false;
	}
	for (; v != '\n' && v != '\r'; v = stream->next(stream->next_data)) {
		if (v == EOF) {
			LOG(PANDA_DEBUG_FILE, PANDA_CODE_PREMATURE_EOF);
			DESTROY_MEMBER(stream, next);
			return false;
		}
	}
	for (; v == '\n' || v == '\r'; v = stream->next(stream->next_data)) {
		if (v == EOF) {
			LOG(PANDA_DEBUG_FILE, PANDA_CODE_PREMATURE_EOF);
			DESTROY_MEMBER(stream, next);
			return false;
		}
	}
	for (; v != '\n' && v != '\r'; v = stream->next(stream->next_data)) {
		if (v == EOF) {
			LOG(PANDA_DEBUG_FILE, PANDA_CODE_PARSE_FAILURE);
			DESTROY_MEMBER(stream, next);
			return false;
		}
		if (v < 64) {
			data->seen_under_64 = true;
		}
		buffer[qpos++].qual = TOINDEX(v);
	}

	if (pos == 0) {
		LOG(PANDA_DEBUG_FILE, PANDA_CODE_NO_DATA);
		return false;
	}
	if (qpos != pos) {
		LOG(PANDA_DEBUG_FILE, PANDA_CODE_NO_QUALITY_INFO);
		return false;
	}
	*length = pos;
	data->non_empty = true;
	return true;
}
Ejemplo n.º 11
0
static void destroy_stream(
	struct bz_stream_data *data) {
	BZ2_bzDecompressEnd(&data->strm);
	DESTROY_MEMBER(data, source);
	free(data);
}
Ejemplo n.º 12
0
bool coldwave_cooldown(CHAR_DATA *ch, CHAR_DATA *victim, int max)
{
    OBJ_DATA *heated_item;
    DUEL_PLAYER_DATA   *player;
    DUEL_OBJ_DATA      *dobj = NULL, *dobj_next = NULL;
    DUEL_DATA          *duel;
    int coolcnt = 0;
    int coolmax;

    coolmax = max;
    duel = find_duel(victim);

    if (!duel) {
        for (heated_item = victim->first_carry; heated_item != NULL; heated_item = heated_item->next_in_carry_list) {
            if (heated_item->wear_loc == WEAR_NONE)
                continue;
            else {
                if (   IS_SET(heated_item->item_apply, ITEM_APPLY_HEATED)
                    || (!IS_NPC(victim) && victim->pcdata->in_arena && IS_SET(heated_item->item_apply, ITEM_APPLY_ARENAHEATED))) {
                    if (coolcnt >= coolmax)
                        break;

                    if (IS_SET(heated_item->item_apply, ITEM_APPLY_HEATED) && !victim->pcdata->in_arena) {
                        act("@@N@@g$n@@N@@g cools down @@N$p@@N@@g!@@N", ch, heated_item, victim, TO_NOTVICT);
                        if (ch != victim) {
                            act("@@N@@gYou cool down @@N$N@@N's @@N$p@@N@@g!@@N", ch, heated_item, victim, TO_CHAR);
                            act("@@N@@g$n cools down your @@N$p@@N@@g!@@N", ch, heated_item, victim, TO_VICT);
                        }
                        else
                            act("@@N@@gYou cool down @@N$p@@N@@g!@@N", ch, heated_item, NULL, TO_CHAR);

                        REMOVE_BIT(heated_item->item_apply, ITEM_APPLY_HEATED);
                        coolcnt++;
                    }
                    else if (IS_SET(heated_item->item_apply, ITEM_APPLY_ARENAHEATED) && victim->pcdata->in_arena) {
                        act("@@N@@g$n@@N@@g cools down @@N$p@@N@@g!@@N", ch, heated_item, victim, TO_NOTVICT);
                        if (ch != victim) {
                            act("@@N@@gYou cool down @@N$N@@N's @@N$p@@N@@g!@@N", ch, heated_item, victim, TO_CHAR);
                            act("@@N@@g$n cools down your @@N$p@@N@@g!@@N", ch, heated_item, victim, TO_VICT);
                        }
                        else
                            act("@@N@@gYou cool down @@N$p@@N@@g!@@N", ch, heated_item, NULL, TO_CHAR);

                        REMOVE_BIT(heated_item->item_apply, ITEM_APPLY_ARENAHEATED);
                        coolcnt++;
                    }
                }
            }
        }
    }

    if (   duel
        && (player = find_duel_player(victim))
        && duel->stage == DUEL_STAGE_GO) {
        for (dobj = player->first_obj; dobj != NULL; dobj = dobj_next) {
            dobj_next = dobj->next;

            if (dobj->obj && dobj->obj->wear_loc != WEAR_NONE && coolcnt < coolmax) {
                act("@@N@@gYour @@N$p@@N @@acools off@@N!!", player->ch, dobj->obj, NULL, TO_CHAR);
                DUNLINK(dobj, player->first_obj, player->last_obj, next, prev);
                DESTROY_MEMBER(dobj);
                coolcnt++;
            }
        }
    }

    if (coolcnt > 0)
        return TRUE;
    else
        return FALSE;
}