Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 811 → Rev 808

/shark/trunk/ports/first/first-contract.c
19,7 → 19,7
 
struct hash_entry {
mutex_t mx;
int id;
fsf_shared_obj_id_t id;
};
 
 
35,18 → 35,7
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)
{
290,19 → 279,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
while (htable[index].id != op->obj_id && index!=oldindex) index=(index+1) % MAX_HASH_ENTRY;
for (;htable[index].id != op->obj_id, index!=oldindex; (index++) % 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) );
 
}
317,11 → 306,9
oldindex=index;
index = (index + 1) % MAX_HASH_ENTRY;
// find
while (htable[index].id != op->obj_id && index!=oldindex) index=(index+1) % MAX_HASH_ENTRY;
for (;htable[index].id != op->obj_id, index!=oldindex; (index++) % MAX_HASH_ENTRY);
if (index==oldindex) return -1;
}
//kern_printf("UNLOCK index %d", index);
 
return mutex_unlock(&htable[index].mx);
 
333,27 → 320,22
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
while (htable[index].id >=0 && index!=oldindex) index=(index+1) % MAX_HASH_ENTRY;
for (;htable[index].id >=0, index!=oldindex; (index++) % 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");
 
}
 
 
380,7 → 362,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;