Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

wvcont.h

00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * FIXME: I was too lazy to templatize this properly, so we only support
00006  * WvCallback<void*,void*>.  It should be possible to work with any kind
00007  * of return value and parameter, although it makes sense to limit things
00008  * to just one parameter (since it currently has to be returned by yield()
00009  * somehow).
00010  */
00011 
00012 #ifndef __WVCONT_H
00013 #define __WVCONT_H
00014 
00015 #include "wvcallback.h"
00016 
00017 typedef WvCallback<void*, void*> WvContCallback;
00018 
00027 class WvCont
00028 {
00029     struct Data;
00030     friend struct Data;
00031     
00032 private:
00038     Data *data;
00039 
00040     static Data *curdata;
00041     static int taskdepth;
00042     
00043     static void bouncer(void *userdata);
00044     
00049     void *call()
00050         { return _call(data); }
00051     
00056     static void *_call(Data *data);
00057 
00062     WvCont(Data *data);
00063 
00064 public:
00070     WvCont(const WvContCallback &cb, unsigned long stacksize = 64*1024);
00071     
00073     WvCont(const WvCont &cb);
00074     
00076     ~WvCont();
00077     
00083     void *operator() (void *p1 = 0);
00084     
00085     // the following are static because a function doesn't really know
00086     // which WvCont it belongs to, and only one WvCont can be the "current"
00087     // one globally in an application anyway.
00088     // 
00089     // Unfortunately this prevents us from assert()ing that you're in the
00090     // context you think you are.
00091     
00095     static WvCont current();
00096 
00103     static void *yield(void *ret = 0);
00104     
00110     static bool isok();
00111 
00112     
00126     template <typename R, typename T>
00127         static R c_bouncer(T t, void *_cont)
00128         {
00129             WvCont &cont = *(WvCont *)_cont;
00130             return (R)cont((T)t);
00131         }
00132 
00133 
00147     template <typename R>
00148      static R c_bouncer(void *_cont)
00149         {
00150             WvCont &cont = *(WvCont *)_cont;
00151             return (R)cont(0);
00152         }
00153 };
00154 
00155 #endif // __WVCONT_H
00156 

Generated on Sun Jul 10 15:30:56 2005 for WvStreams by  doxygen 1.4.0