00001 /*---------------------------------------------------------------------------- 00002 MoMu: A Mobile Music Toolkit 00003 Copyright (c) 2010 Nicholas J. Bryan, Jorge Herrera, Jieun Oh, and Ge Wang 00004 All rights reserved. 00005 http://momu.stanford.edu/toolkit/ 00006 00007 Mobile Music Research @ CCRMA 00008 Music, Computing, Design Group 00009 Stanford University 00010 http://momu.stanford.edu/ 00011 http://ccrma.stanford.edu/groups/mcd/ 00012 00013 MoMu is distributed under the following BSD style open source license: 00014 00015 Permission is hereby granted, free of charge, to any person obtaining a 00016 copy of this software and associated documentation files (the 00017 "Software"), to deal in the Software without restriction, including 00018 without limitation the rights to use, copy, modify, merge, publish, 00019 distribute, sublicense, and/or sell copies of the Software, and to 00020 permit persons to whom the Software is furnished to do so, subject to 00021 the following conditions: 00022 00023 The authors encourage users of MoMu to include this copyright notice, 00024 and to let us know that you are using MoMu. Any person wishing to 00025 distribute modifications to the Software is encouraged to send the 00026 modifications to the original authors so that they can be incorporated 00027 into the canonical version. 00028 00029 The Software is provided "as is", WITHOUT ANY WARRANTY, express or implied, 00030 including but not limited to the warranties of MERCHANTABILITY, FITNESS 00031 FOR A PARTICULAR PURPOSE and NONINFRINGEMENT. In no event shall the authors 00032 or copyright holders by liable for any claim, damages, or other liability, 00033 whether in an actino of a contract, tort or otherwise, arising from, out of 00034 or in connection with the Software or the use or other dealings in the 00035 software. 00036 -----------------------------------------------------------------------------*/ 00037 00038 00039 /*----------------------------------------------------------------------------*/ 00052 /*----------------------------------------------------------------------------*/ 00053 00054 #ifndef __MO_THREAD_H__ 00055 #define __MO_THREAD_H__ 00056 00057 #include "mo_def.h" 00058 #include <pthread.h> 00059 00060 #define THREAD_TYPE 00061 typedef pthread_t THREAD_HANDLE; 00062 typedef void * THREAD_RETURN; 00063 typedef void * (*THREAD_FUNCTION)(void *); 00064 typedef pthread_mutex_t MUTEX; 00065 00066 00067 /*----------------------------------------------------------------------------*/ 00072 /*----------------------------------------------------------------------------*/ 00073 struct MoThread 00074 { 00075 public: 00076 00078 MoThread(); 00079 00081 ~MoThread(); 00082 00083 public: 00085 bool start( THREAD_FUNCTION routine, void * ptr = NULL ); 00086 00088 bool wait( long milliseconds = -1 ); 00089 00091 bool setPriority( long priority ); 00092 00093 public: 00095 static bool setSelfPriority( long priority ); 00096 00097 public: 00099 static void test( ); 00100 00102 void clear() { thread = 0; } 00103 00104 protected: 00105 THREAD_HANDLE thread; 00106 }; 00107 00108 00109 00110 /*----------------------------------------------------------------------------*/ 00115 /*----------------------------------------------------------------------------*/ 00116 struct MoMutex 00117 { 00118 public: 00120 MoMutex(); 00121 00123 ~MoMutex(); 00124 00125 public: 00126 00128 void acquire( ); 00129 00131 void release(void); 00132 00133 protected: 00134 MUTEX mutex; 00135 }; 00136 00137 00138 00139 00140 #endif