00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __PJ_OS_H__
00021 #define __PJ_OS_H__
00022
00027 #include <pj/types.h>
00028
00029 PJ_BEGIN_DECL
00030
00036
00047 typedef enum pj_sys_info_flag
00048 {
00052 PJ_SYS_HAS_IOS_BG = 1
00053
00054 } pj_sys_info_flag;
00055
00056
00061 typedef struct pj_sys_info
00062 {
00067 pj_str_t machine;
00068
00074 pj_str_t os_name;
00075
00088 pj_uint32_t os_ver;
00089
00095 pj_str_t sdk_name;
00096
00102 pj_uint32_t sdk_ver;
00103
00108 pj_str_t info;
00109
00114 pj_uint32_t flags;
00115
00116 } pj_sys_info;
00117
00118
00124 PJ_DECL(const pj_sys_info*) pj_get_sys_info(void);
00125
00126
00127
00128
00129
00130
00149 typedef enum pj_thread_create_flags
00150 {
00151 PJ_THREAD_SUSPENDED = 1
00152 } pj_thread_create_flags;
00153
00154
00158 typedef int (PJ_THREAD_FUNC pj_thread_proc)(void*);
00159
00163 #if !defined(PJ_THREAD_DESC_SIZE)
00164 # define PJ_THREAD_DESC_SIZE (64)
00165 #endif
00166
00171 typedef long pj_thread_desc[PJ_THREAD_DESC_SIZE];
00172
00177 PJ_DECL(pj_uint32_t) pj_getpid(void);
00178
00198 PJ_DECL(pj_status_t) pj_thread_create( pj_pool_t *pool,
00199 const char *thread_name,
00200 pj_thread_proc *proc,
00201 void *arg,
00202 pj_size_t stack_size,
00203 unsigned flags,
00204 pj_thread_t **thread );
00205
00222 PJ_DECL(pj_status_t) pj_thread_register ( const char *thread_name,
00223 pj_thread_desc desc,
00224 pj_thread_t **thread);
00225
00231 PJ_DECL(pj_bool_t) pj_thread_is_registered(void);
00232
00233
00241 PJ_DECL(int) pj_thread_get_prio(pj_thread_t *thread);
00242
00243
00254 PJ_DECL(pj_status_t) pj_thread_set_prio(pj_thread_t *thread, int prio);
00255
00262 PJ_DECL(int) pj_thread_get_prio_min(pj_thread_t *thread);
00263
00264
00271 PJ_DECL(int) pj_thread_get_prio_max(pj_thread_t *thread);
00272
00273
00285 PJ_DECL(void*) pj_thread_get_os_handle(pj_thread_t *thread);
00286
00294 PJ_DECL(const char*) pj_thread_get_name(pj_thread_t *thread);
00295
00303 PJ_DECL(pj_status_t) pj_thread_resume(pj_thread_t *thread);
00304
00310 PJ_DECL(pj_thread_t*) pj_thread_this(void);
00311
00321 PJ_DECL(pj_status_t) pj_thread_join(pj_thread_t *thread);
00322
00323
00333 PJ_DECL(pj_status_t) pj_thread_destroy(pj_thread_t *thread);
00334
00335
00343 PJ_DECL(pj_status_t) pj_thread_sleep(unsigned msec);
00344
00351 #if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0
00352
00353 # define PJ_CHECK_STACK() pj_thread_check_stack(__FILE__, __LINE__)
00354
00358 PJ_DECL(void) pj_thread_check_stack(const char *file, int line);
00359
00363 PJ_DECL(pj_uint32_t) pj_thread_get_stack_max_usage(pj_thread_t *thread);
00364
00368 PJ_DECL(pj_status_t) pj_thread_get_stack_info(pj_thread_t *thread,
00369 const char **file,
00370 int *line);
00371 #else
00372
00373 # define PJ_CHECK_STACK()
00374
00375 # define pj_thread_get_stack_max_usage(thread) 0
00376
00377 # define pj_thread_get_stack_info(thread,f,l) (*(f)="",*(l)=0)
00378 #endif
00379
00384
00441 PJ_DECL(pj_bool_t) pj_symbianos_poll(int priority, int ms_timeout);
00442
00443
00448 typedef struct pj_symbianos_params
00449 {
00455 void *rsocketserv;
00456
00462 void *rconnection;
00463
00469 void *rhostresolver;
00470
00476 void *rhostresolver6;
00477
00478 } pj_symbianos_params;
00479
00489 PJ_DECL(pj_status_t) pj_symbianos_set_params(pj_symbianos_params *prm);
00490
00502 PJ_DECL(void) pj_symbianos_set_connection_status(pj_bool_t up);
00503
00508
00522 PJ_DECL(pj_status_t) pj_thread_local_alloc(long *index);
00523
00529 PJ_DECL(void) pj_thread_local_free(long index);
00530
00537 PJ_DECL(pj_status_t) pj_thread_local_set(long index, void *value);
00538
00545 PJ_DECL(void*) pj_thread_local_get(long index);
00546
00547
00553
00577 PJ_DECL(pj_status_t) pj_atomic_create( pj_pool_t *pool,
00578 pj_atomic_value_t initial,
00579 pj_atomic_t **atomic );
00580
00588 PJ_DECL(pj_status_t) pj_atomic_destroy( pj_atomic_t *atomic_var );
00589
00596 PJ_DECL(void) pj_atomic_set( pj_atomic_t *atomic_var,
00597 pj_atomic_value_t value);
00598
00606 PJ_DECL(pj_atomic_value_t) pj_atomic_get(pj_atomic_t *atomic_var);
00607
00613 PJ_DECL(void) pj_atomic_inc(pj_atomic_t *atomic_var);
00614
00622 PJ_DECL(pj_atomic_value_t) pj_atomic_inc_and_get(pj_atomic_t *atomic_var);
00623
00629 PJ_DECL(void) pj_atomic_dec(pj_atomic_t *atomic_var);
00630
00638 PJ_DECL(pj_atomic_value_t) pj_atomic_dec_and_get(pj_atomic_t *atomic_var);
00639
00646 PJ_DECL(void) pj_atomic_add( pj_atomic_t *atomic_var,
00647 pj_atomic_value_t value);
00648
00657 PJ_DECL(pj_atomic_value_t) pj_atomic_add_and_get( pj_atomic_t *atomic_var,
00658 pj_atomic_value_t value);
00659
00664
00681 typedef enum pj_mutex_type_e
00682 {
00683 PJ_MUTEX_DEFAULT,
00684 PJ_MUTEX_SIMPLE,
00685 PJ_MUTEX_RECURSE
00686 } pj_mutex_type_e;
00687
00688
00699 PJ_DECL(pj_status_t) pj_mutex_create(pj_pool_t *pool,
00700 const char *name,
00701 int type,
00702 pj_mutex_t **mutex);
00703
00715 PJ_DECL(pj_status_t) pj_mutex_create_simple( pj_pool_t *pool, const char *name,
00716 pj_mutex_t **mutex );
00717
00729 PJ_DECL(pj_status_t) pj_mutex_create_recursive( pj_pool_t *pool,
00730 const char *name,
00731 pj_mutex_t **mutex );
00732
00739 PJ_DECL(pj_status_t) pj_mutex_lock(pj_mutex_t *mutex);
00740
00747 PJ_DECL(pj_status_t) pj_mutex_unlock(pj_mutex_t *mutex);
00748
00756 PJ_DECL(pj_status_t) pj_mutex_trylock(pj_mutex_t *mutex);
00757
00764 PJ_DECL(pj_status_t) pj_mutex_destroy(pj_mutex_t *mutex);
00765
00772 PJ_DECL(pj_bool_t) pj_mutex_is_locked(pj_mutex_t *mutex);
00773
00778
00794 typedef struct pj_rwmutex_t pj_rwmutex_t;
00795
00805 PJ_DECL(pj_status_t) pj_rwmutex_create(pj_pool_t *pool, const char *name,
00806 pj_rwmutex_t **mutex);
00807
00814 PJ_DECL(pj_status_t) pj_rwmutex_lock_read(pj_rwmutex_t *mutex);
00815
00822 PJ_DECL(pj_status_t) pj_rwmutex_lock_write(pj_rwmutex_t *mutex);
00823
00830 PJ_DECL(pj_status_t) pj_rwmutex_unlock_read(pj_rwmutex_t *mutex);
00831
00838 PJ_DECL(pj_status_t) pj_rwmutex_unlock_write(pj_rwmutex_t *mutex);
00839
00846 PJ_DECL(pj_status_t) pj_rwmutex_destroy(pj_rwmutex_t *mutex);
00847
00848
00854
00877 PJ_DECL(void) pj_enter_critical_section(void);
00878
00882 PJ_DECL(void) pj_leave_critical_section(void);
00883
00888
00889 #if defined(PJ_HAS_SEMAPHORE) && PJ_HAS_SEMAPHORE != 0
00890
00909 PJ_DECL(pj_status_t) pj_sem_create( pj_pool_t *pool,
00910 const char *name,
00911 unsigned initial,
00912 unsigned max,
00913 pj_sem_t **sem);
00914
00922 PJ_DECL(pj_status_t) pj_sem_wait(pj_sem_t *sem);
00923
00931 PJ_DECL(pj_status_t) pj_sem_trywait(pj_sem_t *sem);
00932
00940 PJ_DECL(pj_status_t) pj_sem_post(pj_sem_t *sem);
00941
00949 PJ_DECL(pj_status_t) pj_sem_destroy(pj_sem_t *sem);
00950
00954 #endif
00955
00956
00957
00958 #if defined(PJ_HAS_EVENT_OBJ) && PJ_HAS_EVENT_OBJ != 0
00959
00979 PJ_DECL(pj_status_t) pj_event_create(pj_pool_t *pool, const char *name,
00980 pj_bool_t manual_reset, pj_bool_t initial,
00981 pj_event_t **event);
00982
00990 PJ_DECL(pj_status_t) pj_event_wait(pj_event_t *event);
00991
00999 PJ_DECL(pj_status_t) pj_event_trywait(pj_event_t *event);
01000
01012 PJ_DECL(pj_status_t) pj_event_set(pj_event_t *event);
01013
01024 PJ_DECL(pj_status_t) pj_event_pulse(pj_event_t *event);
01025
01033 PJ_DECL(pj_status_t) pj_event_reset(pj_event_t *event);
01034
01042 PJ_DECL(pj_status_t) pj_event_destroy(pj_event_t *event);
01043
01047 #endif
01048
01049
01069 PJ_DECL(pj_status_t) pj_gettimeofday(pj_time_val *tv);
01070
01071
01080 PJ_DECL(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt);
01081
01090 PJ_DECL(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv);
01091
01099 PJ_DECL(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv);
01100
01108 PJ_DECL(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv);
01109
01114
01115 #if defined(PJ_TERM_HAS_COLOR) && PJ_TERM_HAS_COLOR != 0
01116
01130 PJ_DECL(pj_status_t) pj_term_set_color(pj_color_t color);
01131
01137 PJ_DECL(pj_color_t) pj_term_get_color(void);
01138
01143 #endif
01144
01145
01166
01167
01168
01169 #if defined(PJ_HAS_HIGH_RES_TIMER) && PJ_HAS_HIGH_RES_TIMER != 0
01170
01178 PJ_DECL(pj_status_t) pj_gettickcount(pj_time_val *tv);
01179
01189 PJ_DECL(pj_status_t) pj_get_timestamp(pj_timestamp *ts);
01190
01197 PJ_DECL(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq);
01198
01205 PJ_INLINE(void) pj_set_timestamp32(pj_timestamp *t, pj_uint32_t hi,
01206 pj_uint32_t lo)
01207 {
01208 t->u32.hi = hi;
01209 t->u32.lo = lo;
01210 }
01211
01212
01219 PJ_INLINE(int) pj_cmp_timestamp(const pj_timestamp *t1, const pj_timestamp *t2)
01220 {
01221 #if PJ_HAS_INT64
01222 if (t1->u64 < t2->u64)
01223 return -1;
01224 else if (t1->u64 > t2->u64)
01225 return 1;
01226 else
01227 return 0;
01228 #else
01229 if (t1->u32.hi < t2->u32.hi ||
01230 (t1->u32.hi == t2->u32.hi && t1->u32.lo < t2->u32.lo))
01231 return -1;
01232 else if (t1->u32.hi > t2->u32.hi ||
01233 (t1->u32.hi == t2->u32.hi && t1->u32.lo > t2->u32.lo))
01234 return 1;
01235 else
01236 return 0;
01237 #endif
01238 }
01239
01240
01246 PJ_INLINE(void) pj_add_timestamp(pj_timestamp *t1, const pj_timestamp *t2)
01247 {
01248 #if PJ_HAS_INT64
01249 t1->u64 += t2->u64;
01250 #else
01251 pj_uint32_t old = t1->u32.lo;
01252 t1->u32.hi += t2->u32.hi;
01253 t1->u32.lo += t2->u32.lo;
01254 if (t1->u32.lo < old)
01255 ++t1->u32.hi;
01256 #endif
01257 }
01258
01264 PJ_INLINE(void) pj_add_timestamp32(pj_timestamp *t1, pj_uint32_t t2)
01265 {
01266 #if PJ_HAS_INT64
01267 t1->u64 += t2;
01268 #else
01269 pj_uint32_t old = t1->u32.lo;
01270 t1->u32.lo += t2;
01271 if (t1->u32.lo < old)
01272 ++t1->u32.hi;
01273 #endif
01274 }
01275
01281 PJ_INLINE(void) pj_sub_timestamp(pj_timestamp *t1, const pj_timestamp *t2)
01282 {
01283 #if PJ_HAS_INT64
01284 t1->u64 -= t2->u64;
01285 #else
01286 t1->u32.hi -= t2->u32.hi;
01287 if (t1->u32.lo >= t2->u32.lo)
01288 t1->u32.lo -= t2->u32.lo;
01289 else {
01290 t1->u32.lo -= t2->u32.lo;
01291 --t1->u32.hi;
01292 }
01293 #endif
01294 }
01295
01301 PJ_INLINE(void) pj_sub_timestamp32(pj_timestamp *t1, pj_uint32_t t2)
01302 {
01303 #if PJ_HAS_INT64
01304 t1->u64 -= t2;
01305 #else
01306 if (t1->u32.lo >= t2)
01307 t1->u32.lo -= t2;
01308 else {
01309 t1->u32.lo -= t2;
01310 --t1->u32.hi;
01311 }
01312 #endif
01313 }
01314
01319 PJ_INLINE(pj_int32_t) pj_timestamp_diff32(const pj_timestamp *t1,
01320 const pj_timestamp *t2)
01321 {
01322
01323 #if PJ_HAS_INT64
01324 pj_int64_t diff = t2->u64 - t1->u64;
01325 return (pj_int32_t) diff;
01326 #else
01327 pj_int32 diff = t2->u32.lo - t1->u32.lo;
01328 return diff;
01329 #endif
01330 }
01331
01332
01348 PJ_DECL(pj_time_val) pj_elapsed_time( const pj_timestamp *start,
01349 const pj_timestamp *stop );
01350
01366 PJ_DECL(pj_uint32_t) pj_elapsed_msec( const pj_timestamp *start,
01367 const pj_timestamp *stop );
01368
01372 PJ_DECL(pj_uint64_t) pj_elapsed_msec64(const pj_timestamp *start,
01373 const pj_timestamp *stop );
01374
01390 PJ_DECL(pj_uint32_t) pj_elapsed_usec( const pj_timestamp *start,
01391 const pj_timestamp *stop );
01392
01408 PJ_DECL(pj_uint32_t) pj_elapsed_nanosec( const pj_timestamp *start,
01409 const pj_timestamp *stop );
01410
01426 PJ_DECL(pj_uint32_t) pj_elapsed_cycle( const pj_timestamp *start,
01427 const pj_timestamp *stop );
01428
01429
01430 #endif
01431
01435
01442
01443 typedef int (*pj_main_func_ptr)(int argc, char *argv[]);
01444
01459 int pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[],
01460 unsigned flags);
01461
01465
01470 pj_status_t pj_thread_init(void);
01471
01472
01473 PJ_END_DECL
01474
01475 #endif
01476