Exemple #1
0
int
archiver_close(void *ctx)
{
	pc_ctx_t *pctx = (pc_ctx_t *)ctx;

	pctx->arc_closed = 1;
	pctx->arc_buf = NULL;
	pctx->arc_buf_size = 0;
	Sem_Post(&(pctx->write_sem));
	Sem_Post(&(pctx->read_sem));
	return (0);
}
Exemple #2
0
static ssize_t
extract_read_callback(struct archive *arc, void *ctx, const void **buf)
{
	pc_ctx_t *pctx = (pc_ctx_t *)ctx;

	if (pctx->arc_closed) {
		pctx->arc_buf_size = 0;
		log_msg(LOG_WARN, 0, "End of file.");
		archive_set_error(arc, ARCHIVE_EOF, "End of file.");
		return (-1);
	}

	if (!pctx->arc_writing) {
		Sem_Wait(&(pctx->read_sem));
	} else {
		Sem_Post(&(pctx->write_sem));
		Sem_Wait(&(pctx->read_sem));
	}

	if (pctx->arc_buf == NULL || pctx->arc_buf_size == 0) {
		pctx->arc_buf_size = 0;
		log_msg(LOG_ERR, 0, "End of file when extracting archive.");
		archive_set_error(arc, ARCHIVE_EOF, "End of file when extracting archive.");
		return (-1);
	}
	pctx->arc_writing = 1;
	*buf = pctx->arc_buf;

	return (pctx->arc_buf_size);
}
Exemple #3
0
void MI_CALL _L_LifecycleC1_Callback(
    _In_ MI_Uint32 types,
    _In_opt_ void* callbackData)
{
    Config* config = (Config*)callbackData;
    config->currentSubscriptionTypes = types;
    /* signal firing thread to fire indication */
    Sem_Post(&config->sem, 1);
}
Exemple #4
0
static int
extract_close_callback(struct archive *arc, void *ctx)
{
	pc_ctx_t *pctx = (pc_ctx_t *)ctx;

	pctx->arc_closed = 1;
	if (pctx->arc_buf) {
		Sem_Post(&(pctx->write_sem));
	} else {
		pctx->arc_buf_size = 0;
	}
	return (ARCHIVE_OK);
}
Exemple #5
0
static int
creat_close_callback(struct archive *arc, void *ctx)
{
	pc_ctx_t *pctx = (pc_ctx_t *)ctx;

	pctx->arc_closed = 1;
	if (pctx->arc_buf) {
		Sem_Post(&(pctx->read_sem));
	} else {
		pctx->arc_buf_pos = 0;
	}
	return (ARCHIVE_OK);
}
Exemple #6
0
static void *barber_work(void *arg)
{
    struct barber *barber = arg;
    struct chairs *chairs = &barber->simulator->chairs;
    struct customer *customer = 0; 

    /* Main barber loop */
    while (true) {
		Sem_Wait(&chairs->barber); 
		Sem_Wait(&chairs->mutex);
        /* Incrementing rear by one and modulo max to return back to 0 if
        * the que is at max index */
		customer = chairs->customer[chairs->r++ % chairs->max]; 
        thrlab_prepare_customer(customer, barber->room);
		Sem_Post(&chairs->mutex);
		Sem_Post(&chairs->chair);
		
        thrlab_sleep(5 * (customer->hair_length - customer->hair_goal));
        thrlab_dismiss_customer(customer, barber->room);
		Sem_Post(&customer->mutex);
    }
    return NULL;
}
Exemple #7
0
/**
 * Called in a new thread each time a customer has arrived.
 */
static void customer_arrived(struct customer *customer, void *arg)
{
    struct simulator *simulator = arg;
    struct chairs *chairs = &simulator->chairs;

    Sem_Init(&customer->mutex, 0, 0);

    /* If a chair is available we let the customer in, else we turn the
     * customer away. */
    if (sem_trywait(&chairs->chair) == 0) {
        Sem_Wait(&chairs->mutex);
        thrlab_accept_customer(customer);
        /* Incrementing front by one and modulo max to return back to 0 if
         * the que is at max index. */
        chairs->customer[chairs->f++ % chairs->max] = customer;
        Sem_Post(&chairs->mutex);
        Sem_Post(&chairs->barber);
        Sem_Wait(&customer->mutex);
    } else {
        thrlab_reject_customer(customer);
    }
    /* Destroying the customer semaphore */
    Sem_Destroy(&customer->mutex);
}
Exemple #8
0
int64_t
archiver_write(void *ctx, void *buf, uint64_t count)
{
	pc_ctx_t *pctx = (pc_ctx_t *)ctx;

	if (pctx->arc_closed) {
		log_msg(LOG_WARN, 0, "Archive extractor closed unexpectedly");
		return (0);
	}

	if (pctx->arc_buf != NULL) {
		log_msg(LOG_ERR, 0, "Incorrect sequencing of archiver_read() call.");
		return (-1);
	}

	pctx->arc_buf = buf;
	pctx->arc_buf_size = count;
	Sem_Post(&(pctx->read_sem));
	Sem_Wait(&(pctx->write_sem));
	pctx->arc_buf = NULL;
	return (pctx->arc_buf_size);
}
Exemple #9
0
int64_t
archiver_read(void *ctx, void *buf, uint64_t count)
{
	pc_ctx_t *pctx = (pc_ctx_t *)ctx;

	if (pctx->arc_closed)
		return (0);

	if (pctx->arc_buf != NULL) {
		log_msg(LOG_ERR, 0, "Incorrect sequencing of archiver_read() call.");
		return (-1);
	}

	pctx->arc_buf = buf;
	pctx->arc_buf_size = count;
	pctx->arc_buf_pos = 0;
	pctx->btype = TYPE_UNKNOWN;
	Sem_Post(&(pctx->write_sem));
	Sem_Wait(&(pctx->read_sem));
	pctx->arc_buf = NULL;
	return (pctx->arc_buf_pos);
}
Exemple #10
0
static ssize_t
creat_write_callback(struct archive *arc, void *ctx, const void *buf, size_t len)
{
	uchar_t *buff = (uchar_t *)buf;
	pc_ctx_t *pctx = (pc_ctx_t *)ctx;
	size_t remaining;

	if (pctx->arc_closed) {
		archive_set_error(arc, ARCHIVE_EOF, "End of file when writing archive.");
		return (-1);
	}

	if (!pctx->arc_writing) {
		Sem_Wait(&(pctx->write_sem));
	}

	if (pctx->arc_buf == NULL || pctx->arc_buf_size == 0) {
		archive_set_error(arc, ARCHIVE_EOF, "End of file when writing archive.");
		return (-1);
	}
	pctx->arc_writing = 1;

	remaining = len;
	while (remaining && !pctx->arc_closed) {
		uchar_t *tbuf;

		tbuf = pctx->arc_buf + pctx->arc_buf_pos;

		/*
		 * Determine if we should return the accumulated data to the caller.
		 * This is done if the data type changes and at least some minimum amount
		 * of data has accumulated in the buffer.
		 */
		if (pctx->btype != pctx->ctype) {
			if (pctx->btype == TYPE_UNKNOWN || pctx->arc_buf_pos == 0) {
				pctx->btype = pctx->ctype;
			} else {
				if (pctx->arc_buf_pos < pctx->min_chunk) {
					uint32_t diff = pctx->min_chunk - pctx->arc_buf_pos;
					if (len > diff)
						pctx->btype = pctx->ctype;
					else
						pctx->ctype = pctx->btype;
				} else {
					pctx->arc_writing = 0;
					Sem_Post(&(pctx->read_sem));
					Sem_Wait(&(pctx->write_sem));
					tbuf = pctx->arc_buf + pctx->arc_buf_pos;
					pctx->arc_writing = 1;
					if (remaining > 0)
						pctx->btype = pctx->ctype;
				}
			}
		}

		if (remaining > pctx->arc_buf_size - pctx->arc_buf_pos) {
			size_t nlen = pctx->arc_buf_size - pctx->arc_buf_pos;
			memcpy(tbuf, buff, nlen);
			remaining -= nlen;
			pctx->arc_buf_pos += nlen;
			buff += nlen;
			pctx->arc_writing = 0;
			Sem_Post(&(pctx->read_sem));
			Sem_Wait(&(pctx->write_sem));
			pctx->arc_writing = 1;
		} else {
			memcpy(tbuf, buff, remaining);
			pctx->arc_buf_pos += remaining;
			remaining = 0;
			if (pctx->arc_buf_pos == pctx->arc_buf_size) {
				pctx->arc_writing = 0;
				Sem_Post(&(pctx->read_sem));
			}
			break;
		}
	}

	return (len - remaining);
}
/// <summary>
/// End the operation of the method.
/// </summar>
void EndLcmOperation()
{
    int waitResult = 0;
    Atomic_Swap(&g_activeOperationMethodName, (ptrdiff_t)NULL);
    waitResult = Sem_Post(&g_h_ConfigurationStoppedEvent, 1); //Ignore the result
}