thread.hpp
Go to the documentation of this file.
00001 /*
00002  *  RPLIDAR SDK
00003  *
00004  *  Copyright (c) 2009 - 2014 RoboPeak Team
00005  *  http://www.robopeak.com
00006  *  Copyright (c) 2014 - 2018 Shanghai Slamtec Co., Ltd.
00007  *  http://www.slamtec.com
00008  *
00009  */
00010 /*
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright notice,
00015  *    this list of conditions and the following disclaimer.
00016  *
00017  * 2. Redistributions in binary form must reproduce the above copyright notice,
00018  *    this list of conditions and the following disclaimer in the documentation
00019  *    and/or other materials provided with the distribution.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00023  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00024  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
00025  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00026  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00027  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00028  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00029  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00030  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00031  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  */
00034 
00035 #include "arch/macOS/arch_macOS.h"
00036 
00037 namespace rp{ namespace hal{
00038 
00039 Thread Thread::create(thread_proc_t proc, void * data)
00040 {
00041     Thread newborn(proc, data);
00042     
00043     // tricky code, we assume pthread_t is not a structure but a word size value
00044     assert( sizeof(newborn._handle) >= sizeof(pthread_t));
00045 
00046     pthread_create((pthread_t *)&newborn._handle, NULL,(void * (*)(void *))proc, data);
00047 
00048     return newborn;
00049 }
00050 
00051 u_result Thread::terminate()
00052 {
00053     if (!this->_handle) return RESULT_OK;
00054     
00055   //  return pthread_cancel((pthread_t)this->_handle)==0?RESULT_OK:RESULT_OPERATION_FAIL;
00056     return RESULT_OK;
00057 }
00058 
00059 u_result Thread::setPriority( priority_val_t p)
00060 {
00061         if (!this->_handle) return RESULT_OPERATION_FAIL;
00062     // simply ignore this request
00063         return  RESULT_OK;
00064 }
00065 
00066 Thread::priority_val_t Thread::getPriority()
00067 {
00068         return PRIORITY_NORMAL;
00069 }
00070 
00071 u_result Thread::join(unsigned long timeout)
00072 {
00073     if (!this->_handle) return RESULT_OK;
00074     
00075     pthread_join((pthread_t)(this->_handle), NULL);
00076     return RESULT_OK;
00077 }
00078 
00079 }}


rplidar_ros
Author(s):
autogenerated on Mon Mar 18 2019 02:34:23