Right, I'm committing this session because I'm too cold and tired to go on.
It does not at present build (and it's going to take a good bit more work before it does).
This commit is contained in:
parent
f05d1af9d6
commit
6148d3699f
32 changed files with 364 additions and 309 deletions
|
|
@ -77,60 +77,60 @@ struct pso_pointer initialise_memory( uint32_t node ) {
|
|||
/**
|
||||
* @brief Pop an object off the freelist for the specified `size_class`.
|
||||
*/
|
||||
struct pso_pointer pop_freelist( uint8_t size_class) {
|
||||
// `t`, because if `allocate_page` fails it will be set to `nil`.
|
||||
struct pso_pointer result = t;
|
||||
|
||||
if ( size_class <= MAX_SIZE_CLASS ) {
|
||||
if ( nilp( freelists[size_class] ) ) {
|
||||
result = allocate_page( size_class );
|
||||
}
|
||||
struct pso_pointer pop_freelist( uint8_t size_class ) {
|
||||
// `t`, because if `allocate_page` fails it will be set to `nil`.
|
||||
struct pso_pointer result = t;
|
||||
|
||||
if ( nilp( result ) ) {
|
||||
fputws( L"FATAL: Page space exhausted\n", stderr );
|
||||
exit( 1 ); // TODO: we don't want to do this! Somehow, we need to
|
||||
// recover a workable environment, ideally by throwing a pre-made
|
||||
// exception.
|
||||
}
|
||||
if ( size_class <= MAX_SIZE_CLASS ) {
|
||||
if ( nilp( freelists[size_class] ) ) {
|
||||
result = allocate_page( size_class );
|
||||
}
|
||||
|
||||
if ( !exceptionp( result ) && !nilp( result ) ) {
|
||||
pthread_mutex_lock( &freelists_mutices[size_class]);
|
||||
result = freelists[size_class];
|
||||
struct pso2 *object = pointer_to_object( result );
|
||||
freelists[size_class] = object->payload.free.next;
|
||||
pthread_mutex_unlock(&freelists_mutices[size_class]);
|
||||
if ( nilp( result ) ) {
|
||||
fputws( L"FATAL: Page space exhausted\n", stderr );
|
||||
exit( 1 ); // TODO: we don't want to do this! Somehow, we need to
|
||||
// recover a workable environment, ideally by throwing a pre-made
|
||||
// exception.
|
||||
}
|
||||
|
||||
/* the object ought already to have the right size class in its tag
|
||||
* because it was popped off the freelist for that size class. */
|
||||
if ( object->header.tag.bytes.size_class != size_class ) {
|
||||
// TODO: return an exception instead? Or warn, set it, and continue?
|
||||
}
|
||||
/* the objext ought to have a reference count ot zero, because it's
|
||||
* on the freelist, but again we should sanity check. */
|
||||
if ( object->header.count != 0 ) {
|
||||
fwprintf( stderr,
|
||||
L"WARNING: Request to allocate object of size class %d, which is not implemented",
|
||||
size_class);
|
||||
}
|
||||
}
|
||||
} // TODO: else throw exception
|
||||
|
||||
return result;
|
||||
if ( !exceptionp( result ) && !nilp( result ) ) {
|
||||
pthread_mutex_lock( &freelists_mutices[size_class] );
|
||||
result = freelists[size_class];
|
||||
struct pso2 *object = pointer_to_object( result );
|
||||
freelists[size_class] = object->payload.free.next;
|
||||
pthread_mutex_unlock( &freelists_mutices[size_class] );
|
||||
|
||||
/* the object ought already to have the right size class in its tag
|
||||
* because it was popped off the freelist for that size class. */
|
||||
if ( object->header.tag.bytes.size_class != size_class ) {
|
||||
// TODO: return an exception instead? Or warn, set it, and continue?
|
||||
}
|
||||
/* the objext ought to have a reference count ot zero, because it's
|
||||
* on the freelist, but again we should sanity check. */
|
||||
if ( object->header.count != 0 ) {
|
||||
fwprintf( stderr,
|
||||
L"WARNING: Request to allocate object of size class %d, which is not implemented",
|
||||
size_class );
|
||||
}
|
||||
}
|
||||
} // TODO: else throw exception
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void push_freelist( struct pso_pointer p) {
|
||||
struct pso2 *obj = pointer_to_object( p );
|
||||
uint8_t size_class = ( obj->header.tag.bytes.size_class );
|
||||
void push_freelist( struct pso_pointer p ) {
|
||||
struct pso2 *obj = pointer_to_object( p );
|
||||
uint8_t size_class = ( obj->header.tag.bytes.size_class );
|
||||
|
||||
strncpy( ( char * ) ( obj->header.tag.bytes.mnemonic ), FREETAG,
|
||||
TAGLENGTH );
|
||||
|
||||
pthread_mutex_lock( &freelists_mutices[size_class]);
|
||||
strncpy( ( char * ) ( obj->header.tag.bytes.mnemonic ), FREETAG,
|
||||
TAGLENGTH );
|
||||
|
||||
if ( size_class <= MAX_SIZE_CLASS ) {
|
||||
obj->payload.free.next = freelists[size_class];
|
||||
freelists[size_class] = p;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&freelists_mutices[size_class]);
|
||||
pthread_mutex_lock( &freelists_mutices[size_class] );
|
||||
|
||||
if ( size_class <= MAX_SIZE_CLASS ) {
|
||||
obj->payload.free.next = freelists[size_class];
|
||||
freelists[size_class] = p;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock( &freelists_mutices[size_class] );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue