dynamic::apartment Class Reference
[Memory and thread management]

A mutually exclusive garbage-collected heap. More...

Inherits @74::ref_counted.

List of all members.

Public Member Functions

void * malloc (std::size_t bytes)
 Allocate an object in the apartment.
void free (void *p)
 Free an object in the apartment.
void defrag ()
 Defragment the heap (if supported by the memory manager).
gc::garbage_collectorgc () const
 Access the apartment's garbage collector.
void enter ()
 Enter the apartment.
void lock ()
 Locks the apartment.
void unlock ()
 Unlocks the apartment.

Static Public Member Functions

static apartmentcurrent ()
 Gets a pointer to the current apartment.


Detailed Description

A mutually exclusive garbage-collected heap.

All objects in C++Script are managed by an apartment. Roughly speaking, there is one apartment per thread, and the programmer can create further apartments as necessary.

Apartments are "acquired" and "released", and an thread must enter an apartment prior to accessing any data in the apartment.

This scheme is efficient because all objects are threadsafe, and there is no overhead when using objects or allocating memory. The only time there is overhead is when threads change apartments for some reason, for example to access an object in a different apartment. Cross-apartment access must be strictly regulated using a dynamic::types::proxy_impl object.

The apartment runs the garbage collector independently, which does not block the operation of other threads.

I realise this memory model is a bit wierd but it is completely scalable to any number of threads without overhead.

Definition at line 104 of file proxy.cpp.


Member Function Documentation

static apartment* dynamic::apartment::current (  )  [inline, static]

Gets a pointer to the current apartment.

Note that there will be a different apartment per thread.

Definition at line 141 of file proxy.cpp.

Referenced by dynamic::internal::apartment_defrag(), dynamic::internal::apartment_free(), dynamic::internal::apartment_malloc(), enter(), and dynamic::gc::global_gc().

void dynamic::apartment::enter (  )  [inline]

Enter the apartment.

Releases the previous apartment, and wait for the new apartment to become free if necessary.

Definition at line 159 of file proxy.cpp.

References current(), lock(), dynamic::set(), and unlock().

void dynamic::apartment::lock (  )  [inline]

Locks the apartment.

To prevent deadlock, never lock more than one apartment at a time

Definition at line 172 of file proxy.cpp.

References dynamic::api::mutex::lock().

Referenced by enter().


The documentation for this class was generated from the following file:

Generated on Thu Dec 18 22:14:19 2008 for C++Script by  doxygen 1.5.7.1