thread.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2014, RoboPeak
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without 
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice, 
00009  *    this list of conditions and the following disclaimer.
00010  *
00011  * 2. Redistributions in binary form must reproduce the above copyright notice, 
00012  *    this list of conditions and the following disclaimer in the documentation 
00013  *    and/or other materials provided with the distribution.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00017  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00018  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00019  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00021  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00022  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00023  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00024  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00025  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *
00027  */
00028 /*
00029  *  RoboPeak LIDAR System
00030  *  Thread abstract layer
00031  *
00032  *  Copyright 2009 - 2014 RoboPeak Team
00033  *  http://www.robopeak.com
00034  * 
00035  */
00036 
00037 #pragma once
00038 
00039 #include "rptypes.h"
00040 #define CLASS_THREAD(c , x ) \
00041         rp::hal::Thread::create_member<c, &c::x>(this )
00042 
00043 namespace rp{ namespace hal{
00044 
00045 class Thread
00046 {
00047 public:
00048     enum priority_val_t
00049         {
00050                 PRIORITY_REALTIME = 0,
00051                 PRIORITY_HIGH     = 1,
00052                 PRIORITY_NORMAL   = 2,
00053                 PRIORITY_LOW      = 3,
00054                 PRIORITY_IDLE     = 4,
00055         };
00056 
00057     template <class T, u_result (T::*PROC)(void)>
00058     static Thread create_member(T * pthis)
00059     {
00060                 return create(_thread_thunk<T,PROC>, pthis);
00061         }
00062 
00063         template <class T, u_result (T::*PROC)(void) >
00064         static _word_size_t THREAD_PROC _thread_thunk(void * data)
00065         {
00066                 return (static_cast<T *>(data)->*PROC)();
00067         }
00068         static Thread create(thread_proc_t proc, void * data = NULL );
00069 
00070 public:
00071     ~Thread() { }
00072     Thread():  _data(NULL),_func(NULL),_handle(0)  {}
00073     _word_size_t getHandle(){ return _handle;}
00074     u_result terminate();
00075     void *getData() { return _data;}
00076     u_result join(unsigned long timeout = -1);
00077         u_result setPriority( priority_val_t p);
00078         priority_val_t getPriority();
00079 
00080     bool operator== ( const Thread & right) { return this->_handle == right._handle; }
00081 protected:
00082     Thread( thread_proc_t proc, void * data ): _data(data),_func(proc), _handle(0)  {}
00083     void * _data;
00084     thread_proc_t _func;
00085     _word_size_t _handle;
00086 };
00087 
00088 }}
00089 


rplidar_ros
Author(s):
autogenerated on Fri Aug 28 2015 12:46:43