]> gitweb.factorcode.org Git - factor.git/commitdiff
cuda.contexts, cuda.gl: factor out set-up-cuda-context and clean-up-cuda-context...
authorJoe Groff <arcata@gmail.com>
Tue, 25 May 2010 04:38:25 +0000 (21:38 -0700)
committerJoe Groff <arcata@gmail.com>
Tue, 25 May 2010 05:13:15 +0000 (22:13 -0700)
extra/cuda/contexts/contexts.factor
extra/cuda/gl/gl.factor

index a218c588c53e767179f01914a42a5e18c895533c..7a9ab59a6a5bc51911152c897ea9b57ec752b4c8 100644 (file)
@@ -1,8 +1,12 @@
 ! (c)2010 Joe Groff bsd license
 USING: alien.c-types alien.data continuations cuda cuda.ffi
-cuda.libraries fry kernel namespaces ;
+cuda.libraries alien.destructors fry kernel namespaces ;
 IN: cuda.contexts
 
+: set-up-cuda-context ( -- )
+    H{ } clone cuda-modules set-global
+    H{ } clone cuda-functions set-global ; inline
+
 : create-context ( device flags -- context )
     swap
     [ CUcontext <c-object> ] 2dip
@@ -16,14 +20,15 @@ IN: cuda.contexts
 
 : destroy-context ( context -- ) cuCtxDestroy cuda-error ; inline
 
-: (set-up-cuda-context) ( device flags create-quot -- )
-    H{ } clone cuda-modules set-global
-    H{ } clone cuda-functions set
-    call ; inline
+: clean-up-context ( context -- )
+    [ sync-context ] ignore-errors destroy-context ; inline
+
+DESTRUCTOR: destroy-context
+DESTRUCTOR: clean-up-context
 
 : (with-cuda-context) ( context quot -- )
-    swap '[ [ sync-context ] ignore-errors _ destroy-context ] [ ] cleanup ; inline
+    swap '[ _ clean-up-context ] [ ] cleanup ; inline
 
 : with-cuda-context ( device flags quot -- )
-    [ [ create-context ] (set-up-cuda-context) ] dip (with-cuda-context) ; inline
+    [ set-up-cuda-context create-context ] dip (with-cuda-context) ; inline
 
index f3a6b47cf6bb3d06ec574859d656506360107e9a..71a2689b0895ffa64c0e241b81e31173c19165d9 100644 (file)
@@ -10,7 +10,7 @@ IN: cuda.gl
     [ cuGLCtxCreate cuda-error ] 3keep 2drop *void* ; inline
 
 : with-gl-cuda-context ( device flags quot -- )
-    [ [ create-gl-cuda-context ] (set-up-cuda-context) ] dip (with-cuda-context) ; inline 
+    [ set-up-cuda-context create-gl-cuda-context ] dip (with-cuda-context) ; inline 
 
 : gl-buffer>resource ( gl-buffer flags -- resource )
     enum>number