Skip to content

Commit

Permalink
put hashing back into the fn calls
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewsot committed May 13, 2024
1 parent ad599a2 commit f7a19c0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
9 changes: 1 addition & 8 deletions libptimc/examples/hashing.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
#include "libptimc.h"
#include <assert.h>

static hash_t HASH = 0;
hash_t state_hasher() { return (hash_t)HASH; }

void imc_check_main(void) {
register_hasher(state_hasher);

int counter = 0;
for (int i = 0; i < 5; i++) {
HASH = (counter << 8) | i;

counter += choose(2);
counter += choose(2, (counter << 8) | i);
assert(counter < 6);
}
}
4 changes: 1 addition & 3 deletions libptimc/libimc/libimc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
typedef uint8_t choice_t;
typedef uint64_t hash_t;

choice_t choose(choice_t n);
choice_t choose(choice_t n, hash_t hash);
void report_error();
void check_exit_normal();
extern void check_main();

void register_hasher(hash_t (*hasher)(void));
7 changes: 1 addition & 6 deletions libptimc/libimc/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ struct partial_path CURRENT_PATH;
int CURRENT_N_CHOICES;
struct message_bundle BUNDLE;

static hash_t (*HASHER)(void);
void register_hasher(hash_t (*hasher)(void)) { HASHER = hasher; }

choice_t choose(choice_t n) {
choice_t choose(choice_t n, hash_t hash) {
if (n == 1) return 0;

hash_t hash = HASHER ? HASHER() : 0;

if (CURRENT_N_CHOICES++ < CURRENT_PATH.n_choices)
return CURRENT_PATH.choices[CURRENT_N_CHOICES - 1];

Expand Down
8 changes: 6 additions & 2 deletions libptimc/libptimc.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int imcthread_create(imcthread_t *threadp,
return 0;
}

int imcthread_yield(void) {
int imcthread_yieldh(hash_t hash) {
// pauses the current thread and returns to the master thread
assert(CURRENT_THREAD);
struct imcthread *thread = CURRENT_THREAD;
Expand All @@ -48,6 +48,7 @@ int imcthread_yield(void) {

return 0;
}
int imcthread_yield(void) { imcthread_yieldh(0); }

static void *_imc_check_main(void *_) { imc_check_main(); return 0; }
void check_main() {
Expand Down Expand Up @@ -76,7 +77,7 @@ void check_main() {
}
}

int imcthread_join(imcthread_t thread, void **retval) {
int imcthread_joinh(imcthread_t thread, void **retval, hash_t hash) {
if (thread->state != THREAD_STATE_DEAD) {
CURRENT_THREAD->waiting_on = thread;
imcthread_yield();
Expand All @@ -85,6 +86,9 @@ int imcthread_join(imcthread_t thread, void **retval) {
if (retval) *retval = thread->retval;
return 0;
}
int imcthread_join(imcthread_t thread, void **retval) {
return imcthread_joinh(thread, retval, 0);
}

static void switch_to_thread(struct imcthread *thread) {
assert(!CURRENT_THREAD);
Expand Down
3 changes: 3 additions & 0 deletions libptimc/libptimc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ int imcthread_create(imcthread_t *thread,
int imcthread_yield(void);
int imcthread_join(imcthread_t thread, void **retval);

int imcthread_yieldh(hash_t hash);
int imcthread_joinh(imcthread_t thread, void **retval, hash_t hash);

void check_main(void);

extern void imc_check_main(void);
Expand Down

0 comments on commit f7a19c0

Please sign in to comment.