00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef SC_COR_PTHREAD_H
00029 #define SC_COR_PTHREAD_H
00030
00031
00032 #if defined(SC_USE_PTHREADS)
00033
00034 #include "sysc/kernel/sc_cor.h"
00035 #include "sysc/kernel/sc_cmnhdr.h"
00036 #include <pthread.h>
00037
00038 namespace sc_core {
00039
00040 class sc_cor_pkg_pthread;
00041 typedef sc_cor_pkg_pthread sc_cor_pkg_t;
00042
00043
00055 class sc_cor_pthread : public sc_cor
00056 {
00057 public:
00058
00059
00060 sc_cor_pthread();
00061
00062
00063 virtual ~sc_cor_pthread();
00064
00065
00066 static void* invoke_module_method( void* context_p );
00067
00071 virtual void increment_counter();
00072
00076 virtual void decrement_counter();
00077
00081 virtual unsigned int get_counter();
00082
00083 public:
00084
00085 static sc_cor_pthread* m_active_cor_p;
00086
00087 public:
00088 sc_cor_fn* m_cor_fn;
00089 void* m_cor_fn_arg;
00090
00091
00092 pthread_mutex_t m_mutex;
00093
00094 sc_cor_pkg_pthread* m_pkg_p;
00095 pthread_cond_t m_pt_condition;
00096 pthread_t m_thread;
00097
00101
00102 unsigned int m_counter;
00103
00104 private:
00105
00106
00107 sc_cor_pthread( const sc_cor_pthread& );
00108 sc_cor_pthread& operator = ( const sc_cor_pthread& );
00109 };
00110
00111
00112
00118 class sc_cor_pkg_pthread
00119 : public sc_cor_pkg
00120 {
00121 public:
00122
00123
00124 sc_cor_pkg_pthread( sc_simcontext* simc );
00125
00126
00127 virtual ~sc_cor_pkg_pthread();
00128
00129
00130 virtual sc_cor* create( std::size_t stack_size, sc_cor_fn* fn, void* arg );
00131
00132
00133 virtual void yield( sc_cor* next_cor );
00134
00138 virtual void wait( sc_cor* cur_cor );
00139
00143 virtual void go( sc_cor* next_cor );
00144
00145
00146 virtual void abort( sc_cor* next_cor );
00147
00148
00149 virtual void join( sc_cor* join_cor );
00150
00151
00152 virtual sc_cor* get_main();
00153
00157 virtual void acquire_sched_mutex();
00158
00162 virtual void release_sched_mutex();
00163
00167 virtual void set_thread_specific( void* process_b );
00168
00172 virtual void* get_thread_specific();
00173
00177 virtual bool is_locked();
00178
00182 virtual bool is_unlocked();
00183
00187 virtual bool is_lock_owner();
00188
00192 virtual bool is_not_owner();
00193
00198 virtual bool is_locked_and_owner();
00199
00200 private:
00201
00202 static int instance_count;
00203
00204 private:
00205
00206
00207 sc_cor_pkg_pthread();
00208 sc_cor_pkg_pthread( const sc_cor_pkg_pthread& );
00209 sc_cor_pkg_pthread& operator = ( const sc_cor_pkg_pthread& );
00210 };
00211
00212 }
00213
00214 #endif
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 #endif // defined(SC_USE_PTHREADS)
00238
00239