Example #1
0
void
MR_STM_detach_waiter(MR_STM_Var *var, MR_STM_ConditionVar *cvar)
{
    MR_STM_Waiter   *curr_waiter;

    MR_assert(var != NULL);
    MR_assert(var->MR_STM_var_waiters != NULL);

    curr_waiter = var->MR_STM_var_waiters;
    while (curr_waiter != NULL) {
        if (curr_waiter->MR_STM_cond_var == cvar) {
            if (curr_waiter == var->MR_STM_var_waiters) {
                var->MR_STM_var_waiters =
                        var->MR_STM_var_waiters->MR_STM_waiter_next;
            }
            if (curr_waiter->MR_STM_waiter_prev != NULL) {
                curr_waiter->MR_STM_waiter_prev->MR_STM_waiter_next =
                        curr_waiter->MR_STM_waiter_next;
            }
            if (curr_waiter->MR_STM_waiter_next != NULL) {
                curr_waiter->MR_STM_waiter_next->MR_STM_waiter_prev =
                        curr_waiter->MR_STM_waiter_prev;
            }
            curr_waiter = NULL;
            return;
        }
        curr_waiter = curr_waiter->MR_STM_waiter_next;
    }

    MR_fatal_error("MR_STM_detach_waiter: Thread ID not in wait queue");
}
Example #2
0
int
MR_vfprintf(MR_StreamInfo *info, const char *format, va_list ap)
{
    MR_assert(info != NULL);
    MR_assert(format != NULL);

    return vfprintf(info->file, format, ap);
}
Example #3
0
void
MR_STM_merge_transactions(MR_STM_TransLog *tlog)
{
    MR_STM_TransLog     *parent_log;
    MR_STM_TransRecord  *parent_current;
    MR_STM_TransRecord  *current;
    MR_bool             found_tvar_in_parent;

    MR_assert(tlog != NULL);
    MR_assert(tlog->MR_STM_tl_parent != NULL);

    parent_log = tlog->MR_STM_tl_parent;

    current = tlog->MR_STM_tl_records;
    while (current != NULL) {
        found_tvar_in_parent = MR_NO;
        parent_current = parent_log->MR_STM_tl_records;

        while (parent_current != NULL) {
            if (current->MR_STM_tr_var == parent_current->MR_STM_tr_var) {
                parent_current->MR_STM_tr_new_value =
                    current->MR_STM_tr_new_value;
                found_tvar_in_parent = MR_YES;
                break;
            }

            parent_current = parent_current->MR_STM_tr_next;
        }

        if (! found_tvar_in_parent) {
            MR_STM_record_transaction(parent_log,
                current->MR_STM_tr_var, current->MR_STM_tr_old_value,
                current->MR_STM_tr_new_value);
        }

        current = current->MR_STM_tr_next;
    }

#if defined(MR_STM_DEBUG)
    fprintf(stderr, "STM: Merging log end: <0x%.8lx>\n",
        (MR_Word) tlog);
#endif

    /* Deallocate child log */
#if !defined(MR_CONSERVATIVE_GC)
    /* XXX -- Free tlog and log entries */
#endif
}
Example #4
0
int
MR_write(MR_StreamInfo *info, const void *buffer, size_t size)
{
    int rc;

    MR_assert(info != NULL);
    rc = fwrite(buffer, sizeof(unsigned char), size, info->file);

    return (rc < size ? -1 : rc);
}
Example #5
0
MR_Dlist *
MR_dlist_makelist(const void *data)
{
    MR_Dlist    *list;

    MR_assert(data != NULL);
    list = MR_dlist_makelist0();
    MR_dlist_addhead(list, data);
    return list;
}
Example #6
0
int
MR_read(MR_StreamInfo *info, void *buffer, size_t size)
{
    int rc;
    MR_assert(info != NULL);
    rc = fread(buffer, sizeof(unsigned char), size, info->file);

    // Handle error/eof special cases.
    if ((rc < size) && feof(info->file)) {
        // Nothing to do.
        ;
    } else if (ferror(info->file)) {
        rc = -1;
    }

    return rc;
}
Example #7
0
MR_Integer
MR_STM_validate(MR_STM_TransLog *tlog)
{
    MR_STM_TransRecord  *current;

    MR_assert(tlog != NULL);

#if defined(MR_STM_DEBUG)
    fprintf(stderr, "STM VALIDATE: validating log <0x%.8lx>\n",
        (MR_Word) tlog);
    fprintf(stderr, "\tRecords: <0x%.8lx>\n",
        (MR_Word) tlog->MR_STM_tl_records);
#endif

    while (tlog != NULL) {
        current = tlog->MR_STM_tl_records;

        while (current != NULL) {
            if (current->MR_STM_tr_var->MR_STM_var_value !=
                current->MR_STM_tr_old_value)
            {
#if defined(MR_STM_DEBUG)
                fprintf(stderr, "\ttransaction INVALID.\n");
#endif
                return MR_STM_TRANSACTION_INVALID;
            }

            current = current->MR_STM_tr_next;
        }

        tlog = tlog->MR_STM_tl_parent;
    }

#if defined(MR_STM_DEBUG)
    fprintf(stderr, "\ttransaction VALID.\n");
#endif

    return MR_STM_TRANSACTION_VALID;
}
Example #8
0
int
MR_flush(MR_StreamInfo *info)
{
    MR_assert(info != NULL);
    return fflush(info->file);
}
Example #9
0
int
MR_close(MR_StreamInfo *info)
{
    MR_assert(info != NULL);
    return fclose(info->file);
}
Example #10
0
int
MR_ferror(MR_StreamInfo *info)
{
    MR_assert(info != NULL);
    return ferror(info->file);
}
Example #11
0
int
MR_putch(MR_StreamInfo *info, int ch)
{
    MR_assert(info != NULL);
    return putc(ch, info->file);
}
Example #12
0
int
MR_getch(MR_StreamInfo *info)
{
    MR_assert(info != NULL);
    return getc(info->file);
}