- Main Page
- Classes
- Files

- Search for |

# threadwrap.h

    00001 /*****************************
    00002 File:      Thredwrap.h
    00003 Language:   C++ (header)
    00004 Project:    H3DNetworkingUtils
    00005 The contents of this file are subject to the Mozilla Public License
    00006 Version 1.1 (the "License"); you may not use this file except in
    00007 compliance with the License. You may obtain a copy of the License at
    00008 http://www.mozilla.org/MPL/
    00009
    00010 Software distributed under the License is distributed on an "AS IS"
    00011 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
    00012 License for the specific language governing rights and limitations
    00013 under the License.
    00014
    00015 The Original Code is H3DNetworkingUtils v1.0.
    00016
    00017 The Initial Developer of the Original Code is CSIRO.
    00018 Portions created by the Initial Developer are Copyright (C) 1009 CSIRO. All Rights Reserved.
    00019 Contributor(s):
    00020     Chris Gunn  <Chris.Gunn@csiro.au> <ChrisJGunn@gmail.com>
    00021 ***************************/
    00022
    00023 // The threadwrap class provides an OO interface to threads.
    00024
    00025 #ifndef _threadwrap_
    00026 #define _threadwrap_
    00027
    00028 #include "H3DNetworkingUtils/Config.h"
    00029
    00030 /* Distributed under a BSD type license. See the netwrap COPYRIGHT file */
    00031
    00032 typedef void (* ThreadFunction)(void * arg);
    00033
    00034 class H3D_NETWORKING_UTILS_DLL_SPEC  Thread {
    00035   protected:
    00036     void * tid; // pthread_t if POSIX, HANDLE if Win32
    00037
    00038     static int * priorityMap; // Converts levels (below) into system values
    00039
    00040     virtual void buildPriorityMap ();
    00041
    00042   public:
    00043     enum {
    00044          PRI_LOWEST  = 0,
    00045     PRI_0      = 0,
    00046     PRI_LOW = 1,
    00047     PRI_1      = 1,
    00048     PRI_NORMAL = 2,
    00049     PRI_2      = 2,
    00050     PRI_HIGH   = 3,
    00051     PRI_3      = 3,
    00052     PRI_HIGHEST   = 4,
    00053     PRI_4      = 4
    00054     };
    00055
    00056     // Simple constructor: creates detached standard priority thread
    00057     Thread (ThreadFunction func, void * arg);
    00058
    00059     // For more control
    00060     Thread (ThreadFunction func, void * arg, int priority, int autoTerminate);
    00061
    00062     virtual ~Thread ();
    00063
    00064     void * sysRef () { return tid; }
    00065
    00066     virtual void wait ();
    00067     virtual void cancel ();
    00068
    00069     virtual int getPriority ();
    00070     virtual void setPriority (int newPriority);
    00071
    00072     // These ops are static because they must be/are almost always
    00073     // applied only to the current thread
    00074
    00075     static void exit ();
    00076     static void sleep (int seconds);
    00077     static void millisleep (int millisecs);
    00078 };
    00079
    00080 #endif