Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 810 → Rev 811

/shark/trunk/ports/first/first-contract.c
19,7 → 19,7
 
struct hash_entry {
mutex_t mx;
fsf_shared_obj_id_t id;
int id;
};
 
 
35,7 → 35,18
return (*id % MAX_HASH_ENTRY);
}
 
void fsf_register_shared_object(void) {
int i=0;
// Init Hash table
//kern_printf("(IT SO)\n");
for (i=0; i<MAX_HASH_ENTRY; i++) {
htable[i].id=-1;
 
}
 
}
 
 
int fsf_initialize_contract
(fsf_contract_parameters_t *contract)
{
279,19 → 290,19
 
int fsf_lock_object(fsf_shared_operation_t *op) {
int index, oldindex;
index=hash_fun(&(op->obj_id));
//kern_printf("index %d, htableid %d, obj_op_id %d", index, htable[index].id,op->obj_id);
 
index=hash_fun(&op->obj_id);
 
if (htable[index].id!=op->obj_id) {
oldindex=index;
index = (index + 1) % MAX_HASH_ENTRY;
// find
for (;htable[index].id != op->obj_id, index!=oldindex; (index++) % MAX_HASH_ENTRY);
while (htable[index].id != op->obj_id && index!=oldindex) index=(index+1) % MAX_HASH_ENTRY;
if (index==oldindex) return -1;
}
 
//kern_printf("(SO LK)");
// we need a special implementation for mutex_lock ... additional parameter
 
return PISTAR_lock(FSF_get_shared_object_level(), &htable[index].mx,TIMESPEC2USEC(&op->wcet) );
 
}
306,9 → 317,11
oldindex=index;
index = (index + 1) % MAX_HASH_ENTRY;
// find
for (;htable[index].id != op->obj_id, index!=oldindex; (index++) % MAX_HASH_ENTRY);
while (htable[index].id != op->obj_id && index!=oldindex) index=(index+1) % MAX_HASH_ENTRY;
if (index==oldindex) return -1;
}
//kern_printf("UNLOCK index %d", index);
 
return mutex_unlock(&htable[index].mx);
 
320,22 → 333,27
int index;
int oldindex;
PISTAR_mutexattr_t a;
SYS_FLAGS f;
 
PISTAR_mutexattr_default(a);
 
//kern_printf("(SI SO)\n");
f=kern_fsave();
obj->size=0;
index=hash_fun(&id);
//kern_printf("Index %d Hash %d", index, htable[index].id);
if (htable[index].id>=0) {
oldindex=index;
index = (index + 1) % MAX_HASH_ENTRY;
// collision detection
for (;htable[index].id >=0, index!=oldindex; (index++) % MAX_HASH_ENTRY);
while (htable[index].id >=0 && index!=oldindex) index=(index+1) % MAX_HASH_ENTRY;
// table is full
if (index==oldindex) return;
}
mutex_init(&(htable[index]).mx, &a);
htable[index].id=id;
obj->obj_id=id;
 
kern_frestore(f);
//kern_printf("(EI SO)\n");
}
 
 
362,7 → 380,7
// fail if the object is full
if (obj->size>(FSF_MAX_SHARED_OPERATION-1))
return -1;
 
kern_printf("(DO SO)");
obj->size++;
obj->shared_op[i].op_id=op->op_id;
obj->shared_op[i].wcet=op->wcet;