Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r793 - in trunk: Core Core/Util Engine/Control Interface


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r793 - in trunk: Core Core/Util Engine/Control Interface
  • Date: Thu, 15 Dec 2005 18:19:56 -0700 (MST)

Author: abe
Date: Thu Dec 15 18:19:55 2005
New Revision: 793

Added:
   trunk/Core/Util/ThreadStorage.cc
      - copied, changed from r790, trunk/Core/Util/ThreadStorageAllocator.cc
   trunk/Core/Util/ThreadStorage.h
      - copied, changed from r790, trunk/Core/Util/ThreadStorageAllocator.h
Removed:
   trunk/Core/Util/ThreadStorageAllocator.cc
   trunk/Core/Util/ThreadStorageAllocator.h
Modified:
   trunk/Core/CMakeLists.txt
   trunk/Engine/Control/RTRT.cc
   trunk/Engine/Control/RTRT.h
   trunk/Interface/CMakeLists.txt
   trunk/Interface/Context.h
   trunk/Interface/Fragment.h
Log:


Renamed ThreadStorageAllocator - ThreadStorage.
Refined interface. I'm close to having an example of actually using it.

A    Core/Util/ThreadStorage.cc
D    Core/Util/ThreadStorageAllocator.cc
A    Core/Util/ThreadStorage.h
D    Core/Util/ThreadStorageAllocator.h
M    Core/CMakeLists.txt
M    Engine/Control/RTRT.cc
M    Engine/Control/RTRT.h
M    Interface/Context.h


Removed Dynamic Fragment, will implement different.

M    Interface/Fragment.h
M    Interface/CMakeLists.txt





Modified: trunk/Core/CMakeLists.txt
==============================================================================
--- trunk/Core/CMakeLists.txt   (original)
+++ trunk/Core/CMakeLists.txt   Thu Dec 15 18:19:55 2005
@@ -38,8 +38,8 @@
 SET (CORE_SOURCES ${CORE_SOURCES}
      Util/Args.h
      Util/Args.cc
-     Util/ThreadStorageAllocator.h
-     Util/ThreadStorageAllocator.cc)
+     Util/ThreadStorage.h
+     Util/ThreadStorage.cc)
 SET (CORE_SOURCES ${CORE_SOURCES}
      Geometry/AffineTransform.h
      Geometry/AffineTransform.cc

Copied: trunk/Core/Util/ThreadStorage.cc (from r790, 
trunk/Core/Util/ThreadStorageAllocator.cc)
==============================================================================
--- trunk/Core/Util/ThreadStorageAllocator.cc   (original)
+++ trunk/Core/Util/ThreadStorage.cc    Thu Dec 15 18:19:55 2005
@@ -26,11 +26,11 @@
   DEALINGS IN THE SOFTWARE.
 */
 
-#include <Core/Util/ThreadStorageAllocator.h>
+#include <Core/Util/ThreadStorage.h>
 
 using namespace Manta;
 
-ThreadStorageAllocator::ThreadStorageAllocator( int num_procs_ ) :
+ThreadStorage::ThreadStorage( int num_procs_ ) :
   requested( 0 ),
   num_procs( num_procs_ )
 {
@@ -47,7 +47,7 @@
   }
 };
 
-ThreadStorageAllocator::~ThreadStorageAllocator() {
+ThreadStorage::~ThreadStorage() {
 
   // Free the local memory for each thread.
   for (int i=0;i<num_procs;++i) {
@@ -58,7 +58,7 @@
 }
 
 // Called by each thread to allocate its memory. Will reallocate if 
necessary.
-void ThreadStorageAllocator::allocateStorage( int proc ) {
+void ThreadStorage::allocateStorage( int proc ) {
 
   // Delete the storage if it exists.
   if (storage[proc])

Copied: trunk/Core/Util/ThreadStorage.h (from r790, 
trunk/Core/Util/ThreadStorageAllocator.h)
==============================================================================
--- trunk/Core/Util/ThreadStorageAllocator.h    (original)
+++ trunk/Core/Util/ThreadStorage.h     Thu Dec 15 18:19:55 2005
@@ -41,7 +41,7 @@
   // Thread local storage allocation.
   // Storage will be allocated after setupDisplayChannel but before the next
   // call to setupFrame.
-  class ThreadStorageAllocator {
+  class ThreadStorage {
   private:
     // Actual storage.
     char ** storage;
@@ -54,37 +54,46 @@
     
     
///////////////////////////////////////////////////////////////////////////
     // Token is returned by an allocation request.
+    // 
+    // Tokens are shared by all of the threads. Individual storage is 
accessed
+    // using a token and proc number.
     class Token {
-      friend class ThreadStorageAllocator;
+      friend class ThreadStorage;
     private:
       size_t offset;
-
+      size_t size;
     protected:
-      Token( size_t offset_ ) : offset( offset_ ) {  };
+      Token( size_t offset_, size_t size_ ) : offset( offset_ ), size( size_ 
) {  };
     };    
 
     
///////////////////////////////////////////////////////////////////////////
-    // Accessor provides access to the memory allocated for a specific 
request.
-    // Each request produces a token, which may be used to obtain an 
Accessor after
-    // the memory is allocated.
-    class Accessor {
-      friend class ThreadStorageAllocator;
-    private:
-      char *storage;
+    // Allocator
+    // Allocator are passed to overloaded new operators to allocate and
+    // initalize per thread storage.
+    class Allocator {
     public:
-    protected:
-      Accessor( void *storage_ ) :
-        storage( static_cast<char *>( storage_ ) ) { };
+      Allocator( ThreadStorage &storage_, int proc_, Token token_ )
+        : storage( storage_ ), proc( proc_ ), token( token_ ) {  };
 
-    public:
-      Accessor() { };
-    };
+      // Attempt to allocate the specified number of bytes.
+      void *check_fit( size_t bytes ) const {
+        if (bytes > token.size)
+          throw InternalError( "Requested number of bytes greater than 
allocated.", __FILE__, __LINE__ );
 
+        return storage.get( proc, token );
+      }
+      
+    private:
+      ThreadStorage &storage;
+      int            proc;
+      Token          token;
+    };
+    
     
///////////////////////////////////////////////////////////////////////////
     // Constructor.
-    ThreadStorageAllocator( int num_procs_ );
-    ThreadStorageAllocator(  );
-    ~ThreadStorageAllocator();
+    ThreadStorage( int num_procs_ );
+    ThreadStorage(  );
+    ~ThreadStorage();
 
     Token requestStorage( size_t size, size_t aligned ) {
 
@@ -97,14 +106,17 @@
 
       requested = offset + bytes;
 
-      return Token( offset );
+      return Token( offset, bytes );
     }
 
     // Obtain an accessor to the storage. This is only possible after it has 
been allocated.
-    template< typename StorageType >
-    StorageType getStorage( int proc, const Token &token ) {
+    void *get( int proc, const Token &token ) {
       if (storage[proc]) {
-        return static_cast<StorageType>(storage[proc]);
+
+        if (token.offset >= requested)
+          throw InternalError( "Token offset greater than allocated 
storage", __FILE__, __LINE__ );
+
+        return &storage[proc]+token.offset;
       }
       throw InternalError( "Attempt to access unallocated thread local 
storage.", __FILE__, __LINE__ );
     }

Modified: trunk/Engine/Control/RTRT.cc
==============================================================================
--- trunk/Engine/Control/RTRT.cc        (original)
+++ trunk/Engine/Control/RTRT.cc        Thu Dec 15 18:19:55 2005
@@ -710,7 +710,7 @@
   // Allocate/resize per thread local storage.
   if (thread_storage != 0)
     delete thread_storage;
-  thread_storage = new ThreadStorageAllocator( numProcs );
+  thread_storage = new ThreadStorage( numProcs );
   
   // Setup each channel.
   for(int index = 0;index < static_cast<int>(channels.size());index++){

Modified: trunk/Engine/Control/RTRT.h
==============================================================================
--- trunk/Engine/Control/RTRT.h (original)
+++ trunk/Engine/Control/RTRT.h Thu Dec 15 18:19:55 2005
@@ -10,7 +10,7 @@
 #include <Core/Thread/CrowdMonitor.h>
 #include <Core/Thread/Mutex.h>
 #include <Core/Thread/Semaphore.h>
-#include <Core/Util/ThreadStorageAllocator.h>
+#include <Core/Util/ThreadStorage.h>
 #include <map>
 #include <set>
 #include <vector>
@@ -288,7 +288,7 @@
     ChannelListType channels;
 
     // Thread local storage allocator.
-    ThreadStorageAllocator *thread_storage;
+    ThreadStorage *thread_storage;
     
     Scene* scene;
     string scenePath;

Modified: trunk/Interface/CMakeLists.txt
==============================================================================

Modified: trunk/Interface/Context.h
==============================================================================
--- trunk/Interface/Context.h   (original)
+++ trunk/Interface/Context.h   Thu Dec 15 18:19:55 2005
@@ -14,7 +14,7 @@
   class Scene;
   class ShadowAlgorithm;
   class XWindow;
-  class ThreadStorageAllocator;
+  class ThreadStorage;
   
   class ReadContext {
   public:
@@ -44,7 +44,7 @@
                  bool stereo, int xres, int yres,
                  LoadBalancer* loadBalancer,  PixelSampler* pixelSampler,
                  Renderer* renderer,
-                 ThreadStorageAllocator *storage_allocator_ )
+                 ThreadStorage *storage_allocator_ )
       
       : rtrt_int(rtrt_int),
         channelIndex(channelIndex), numChannels(numChannels),
@@ -83,7 +83,7 @@
     PixelSampler* pixelSampler;
     Renderer* renderer;
     
-    ThreadStorageAllocator *storage_allocator;
+    ThreadStorage *storage_allocator;
     mutable XWindow* masterWindow;
 
     void changeResolution(bool new_stereo, int new_xres, int new_yres) {
@@ -152,7 +152,7 @@
                   LoadBalancer* loadBalancer, PixelSampler* pixelSampler,
                   Renderer* renderer, ShadowAlgorithm* shadowAlgorithm,
                   const Camera* camera, const Scene* scene,
-                  ThreadStorageAllocator *storage_allocator_ )
+                  ThreadStorage *storage_allocator_ )
       : rtrt_int(rtrt_int), channelIndex(channelIndex),
         proc(proc), numProcs(numProcs),
         frameState(frameState),
@@ -174,7 +174,7 @@
     const Camera* camera;
     const Scene* scene;
 
-    mutable ThreadStorageAllocator *storage_allocator;
+    mutable ThreadStorage *storage_allocator;
     
   private:
     RenderContext(const RenderContext&);

Modified: trunk/Interface/Fragment.h
==============================================================================
--- trunk/Interface/Fragment.h  (original)
+++ trunk/Interface/Fragment.h  Thu Dec 15 18:19:55 2005
@@ -155,8 +155,6 @@
     int size;
   };
 
-
-  // Fragment with a dynamic size.
   
 }
 




  • [MANTA] r793 - in trunk: Core Core/Util Engine/Control Interface, abe, 12/15/2005

Archive powered by MHonArc 2.6.16.

Top of page