Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Programming Threads > wait-free globa...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 4071 of 4146
Post > Topic >>

wait-free global region allocator...

by "Chris M. Thomasson" <no@[EMAIL PROTECTED] > Oct 6, 2008 at 11:57 PM

_________________________________________________________________
#define REGION_SIZE (4096 * 1024)

struct region {
  unsigned char buf[REGION_SIZE];
  atomicuword volatile offset; /* == 0 */
};

static void* 
galloc(
 struct region* const this,
 size_t const size
) {
  atomicuword offset;
  if (this->offset + size >= REGION_SIZE) {
    return NULL;
  }
  offset = XADD(&this->offset, size);
  if (offset + size >= REGION_SIZE) {
    return NULL;
  }
  return this->buf + offset;
}

static void 
gflush(
 struct region* const this
) {
  XCHG(&this->offset, 0);
}
_________________________________________________________________




Simple.
 




 1 Posts in Topic:
wait-free global region allocator...
"Chris M. Thomasson&  2008-10-06 23:57:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 8:57:12 CST 2008.