BLOG | DOCUMENTATION | GITHUB

Home --> Documentations --> PJLIB Reference

os.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJ_OS_H__
20#define __PJ_OS_H__
21
26#include <pj/types.h>
27
29
35/* **************************************************************************/
46typedef enum pj_sys_info_flag
47{
52
54
55
60typedef struct pj_sys_info
61{
67
74
88
95
102
108
114
116
117
123PJ_DECL(const pj_sys_info*) pj_get_sys_info(void);
124
129/* **************************************************************************/
149{
150 PJ_THREAD_SUSPENDED = 1
152
153
157typedef int (PJ_THREAD_FUNC pj_thread_proc)(void*);
158
162#if !defined(PJ_THREAD_DESC_SIZE)
163# define PJ_THREAD_DESC_SIZE (64)
164#endif
165
171
176PJ_DECL(pj_uint32_t) pj_getpid(void);
177
198 const char *thread_name,
199 pj_thread_proc *proc,
200 void *arg,
201 pj_size_t stack_size,
202 unsigned flags,
203 pj_thread_t **thread );
204
221PJ_DECL(pj_status_t) pj_thread_register ( const char *thread_name,
222 pj_thread_desc desc,
223 pj_thread_t **thread);
224
231
232
240PJ_DECL(int) pj_thread_get_prio(pj_thread_t *thread);
241
242
256PJ_DECL(pj_status_t) pj_thread_set_prio(pj_thread_t *thread, int prio);
257
265
266
274
275
287PJ_DECL(void*) pj_thread_get_os_handle(pj_thread_t *thread);
288
296PJ_DECL(const char*) pj_thread_get_name(pj_thread_t *thread);
297
306
313
326
327
338
339
347PJ_DECL(pj_status_t) pj_thread_sleep(unsigned msec);
348
355#if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0
356
357# define PJ_CHECK_STACK() pj_thread_check_stack(__FILE__, __LINE__)
358
362PJ_DECL(void) pj_thread_check_stack(const char *file, int line);
363
368
373 const char **file,
374 int *line);
375#else
376
377# define PJ_CHECK_STACK()
379# define pj_thread_get_stack_max_usage(thread) 0
381# define pj_thread_get_stack_info(thread,f,l) (*(f)="",*(l)=0)
382#endif /* PJ_OS_HAS_CHECK_STACK */
383
388/* **************************************************************************/
445PJ_DECL(pj_bool_t) pj_symbianos_poll(int priority, int ms_timeout);
446
447
452typedef struct pj_symbianos_params
453{
460
467
474
481
483
494
507
512/* **************************************************************************/
526PJ_DECL(pj_status_t) pj_thread_local_alloc(long *index);
527
533PJ_DECL(void) pj_thread_local_free(long index);
534
541PJ_DECL(pj_status_t) pj_thread_local_set(long index, void *value);
542
549PJ_DECL(void*) pj_thread_local_get(long index);
550
551
557/* **************************************************************************/
582 pj_atomic_value_t initial,
583 pj_atomic_t **atomic );
584
593
600PJ_DECL(void) pj_atomic_set( pj_atomic_t *atomic_var,
601 pj_atomic_value_t value);
602
611
617PJ_DECL(void) pj_atomic_inc(pj_atomic_t *atomic_var);
618
627
633PJ_DECL(void) pj_atomic_dec(pj_atomic_t *atomic_var);
634
643
650PJ_DECL(void) pj_atomic_add( pj_atomic_t *atomic_var,
651 pj_atomic_value_t value);
652
662 pj_atomic_value_t value);
663
668/* **************************************************************************/
685typedef enum pj_mutex_type_e
686{
687 PJ_MUTEX_DEFAULT,
688 PJ_MUTEX_SIMPLE,
689 PJ_MUTEX_RECURSE
691
692
704 const char *name,
705 int type,
706 pj_mutex_t **mutex);
707
719PJ_DECL(pj_status_t) pj_mutex_create_simple( pj_pool_t *pool, const char *name,
720 pj_mutex_t **mutex );
721
734 const char *name,
735 pj_mutex_t **mutex );
736
744
752
761
769
777
782/* **************************************************************************/
799
809PJ_DECL(pj_status_t) pj_rwmutex_create(pj_pool_t *pool, const char *name,
810 pj_rwmutex_t **mutex);
811
819
827
835
843
851
852
858/* **************************************************************************/
881PJ_DECL(void) pj_enter_critical_section(void);
882
886PJ_DECL(void) pj_leave_critical_section(void);
887
892/* **************************************************************************/
893#if defined(PJ_HAS_SEMAPHORE) && PJ_HAS_SEMAPHORE != 0
914 const char *name,
915 unsigned initial,
916 unsigned max,
917 pj_sem_t **sem);
918
927
936
945
954
958#endif /* PJ_HAS_SEMAPHORE */
959
960
961/* **************************************************************************/
962#if defined(PJ_HAS_EVENT_OBJ) && PJ_HAS_EVENT_OBJ != 0
983PJ_DECL(pj_status_t) pj_event_create(pj_pool_t *pool, const char *name,
984 pj_bool_t manual_reset, pj_bool_t initial,
985 pj_event_t **event);
986
995
1004
1017
1029
1038
1047
1051#endif /* PJ_HAS_EVENT_OBJ */
1052
1053/* **************************************************************************/
1074
1075
1085
1095
1104
1113
1118/* **************************************************************************/
1119#if defined(PJ_TERM_HAS_COLOR) && PJ_TERM_HAS_COLOR != 0
1120
1134PJ_DECL(pj_status_t) pj_term_set_color(pj_color_t color);
1135
1141PJ_DECL(pj_color_t) pj_term_get_color(void);
1142
1147#endif /* PJ_TERM_HAS_COLOR */
1148
1149/* **************************************************************************/
1170/*
1171 * High resolution timer.
1172 */
1173#if defined(PJ_HAS_HIGH_RES_TIMER) && PJ_HAS_HIGH_RES_TIMER != 0
1174
1183
1194
1202
1210 pj_uint32_t lo)
1211{
1212 t->u32.hi = hi;
1213 t->u32.lo = lo;
1214}
1215
1216
1224{
1225#if PJ_HAS_INT64
1226 if (t1->u64 < t2->u64)
1227 return -1;
1228 else if (t1->u64 > t2->u64)
1229 return 1;
1230 else
1231 return 0;
1232#else
1233 if (t1->u32.hi < t2->u32.hi ||
1234 (t1->u32.hi == t2->u32.hi && t1->u32.lo < t2->u32.lo))
1235 return -1;
1236 else if (t1->u32.hi > t2->u32.hi ||
1237 (t1->u32.hi == t2->u32.hi && t1->u32.lo > t2->u32.lo))
1238 return 1;
1239 else
1240 return 0;
1241#endif
1242}
1243
1244
1251{
1252#if PJ_HAS_INT64
1253 t1->u64 += t2->u64;
1254#else
1255 pj_uint32_t old = t1->u32.lo;
1256 t1->u32.hi += t2->u32.hi;
1257 t1->u32.lo += t2->u32.lo;
1258 if (t1->u32.lo < old)
1259 ++t1->u32.hi;
1260#endif
1261}
1262
1269{
1270#if PJ_HAS_INT64
1271 t1->u64 += t2;
1272#else
1273 pj_uint32_t old = t1->u32.lo;
1274 t1->u32.lo += t2;
1275 if (t1->u32.lo < old)
1276 ++t1->u32.hi;
1277#endif
1278}
1279
1286{
1287#if PJ_HAS_INT64
1288 t1->u64 -= t2->u64;
1289#else
1290 t1->u32.hi -= t2->u32.hi;
1291 if (t1->u32.lo >= t2->u32.lo)
1292 t1->u32.lo -= t2->u32.lo;
1293 else {
1294 t1->u32.lo -= t2->u32.lo;
1295 --t1->u32.hi;
1296 }
1297#endif
1298}
1299
1306{
1307#if PJ_HAS_INT64
1308 t1->u64 -= t2;
1309#else
1310 if (t1->u32.lo >= t2)
1311 t1->u32.lo -= t2;
1312 else {
1313 t1->u32.lo -= t2;
1314 --t1->u32.hi;
1315 }
1316#endif
1317}
1318
1324 const pj_timestamp *t2)
1325{
1326 /* Be careful with the signess (I think!) */
1327#if PJ_HAS_INT64
1328 pj_int64_t diff = t2->u64 - t1->u64;
1329 return (pj_int32_t) diff;
1330#else
1331 pj_int32 diff = t2->u32.lo - t1->u32.lo;
1332 return diff;
1333#endif
1334}
1335
1336
1353 const pj_timestamp *stop );
1354
1371 const pj_timestamp *stop );
1372
1376PJ_DECL(pj_uint64_t) pj_elapsed_msec64(const pj_timestamp *start,
1377 const pj_timestamp *stop );
1378
1395 const pj_timestamp *stop );
1396
1413 const pj_timestamp *stop );
1414
1431 const pj_timestamp *stop );
1432
1433
1434#endif /* PJ_HAS_HIGH_RES_TIMER */
1435
1439/* **************************************************************************/
1449typedef int (*pj_main_func_ptr)(int argc, char *argv[]);
1450
1465PJ_DECL(int) pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[],
1466 unsigned flags);
1467
1471/* **************************************************************************/
1477
1478
1480
1481#endif /* __PJ_OS_H__ */
1482
int pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[], unsigned flags)
int(* pj_main_func_ptr)(int argc, char *argv[])
Definition: os.h:1449
pj_status_t pj_atomic_create(pj_pool_t *pool, pj_atomic_value_t initial, pj_atomic_t **atomic)
void pj_atomic_inc(pj_atomic_t *atomic_var)
pj_atomic_value_t pj_atomic_dec_and_get(pj_atomic_t *atomic_var)
pj_status_t pj_atomic_destroy(pj_atomic_t *atomic_var)
void pj_atomic_add(pj_atomic_t *atomic_var, pj_atomic_value_t value)
void pj_atomic_dec(pj_atomic_t *atomic_var)
pj_atomic_value_t pj_atomic_inc_and_get(pj_atomic_t *atomic_var)
pj_atomic_value_t pj_atomic_add_and_get(pj_atomic_t *atomic_var, pj_atomic_value_t value)
pj_atomic_value_t pj_atomic_get(pj_atomic_t *atomic_var)
void pj_atomic_set(pj_atomic_t *atomic_var, pj_atomic_value_t value)
int pj_bool_t
Definition: types.h:71
struct pj_mutex_t pj_mutex_t
Definition: types.h:245
struct pj_sem_t pj_sem_t
Definition: types.h:248
PJ_ATOMIC_VALUE_TYPE pj_atomic_value_t
Definition: types.h:231
struct pj_atomic_t pj_atomic_t
Definition: types.h:226
size_t pj_size_t
Definition: types.h:58
struct pj_event_t pj_event_t
Definition: types.h:251
int pj_status_t
Definition: types.h:68
int pj_int32_t
Definition: types.h:40
struct pj_thread_t pj_thread_t
Definition: types.h:236
unsigned int pj_color_t
Definition: types.h:273
unsigned int pj_uint32_t
Definition: types.h:43
void pj_leave_critical_section(void)
void pj_enter_critical_section(void)
pj_status_t pj_event_destroy(pj_event_t *event)
pj_status_t pj_event_create(pj_pool_t *pool, const char *name, pj_bool_t manual_reset, pj_bool_t initial, pj_event_t **event)
pj_status_t pj_event_reset(pj_event_t *event)
pj_status_t pj_event_wait(pj_event_t *event)
pj_status_t pj_event_pulse(pj_event_t *event)
pj_status_t pj_event_trywait(pj_event_t *event)
pj_status_t pj_event_set(pj_event_t *event)
pj_status_t pj_mutex_create(pj_pool_t *pool, const char *name, int type, pj_mutex_t **mutex)
pj_status_t pj_mutex_unlock(pj_mutex_t *mutex)
pj_status_t pj_mutex_create_recursive(pj_pool_t *pool, const char *name, pj_mutex_t **mutex)
pj_mutex_type_e
Definition: os.h:686
pj_status_t pj_mutex_lock(pj_mutex_t *mutex)
pj_status_t pj_mutex_destroy(pj_mutex_t *mutex)
pj_status_t pj_mutex_trylock(pj_mutex_t *mutex)
pj_status_t pj_mutex_create_simple(pj_pool_t *pool, const char *name, pj_mutex_t **mutex)
pj_bool_t pj_mutex_is_locked(pj_mutex_t *mutex)
pj_status_t pj_rwmutex_destroy(pj_rwmutex_t *mutex)
pj_status_t pj_rwmutex_create(pj_pool_t *pool, const char *name, pj_rwmutex_t **mutex)
struct pj_rwmutex_t pj_rwmutex_t
Definition: os.h:798
pj_status_t pj_rwmutex_lock_write(pj_rwmutex_t *mutex)
pj_status_t pj_rwmutex_lock_read(pj_rwmutex_t *mutex)
pj_status_t pj_rwmutex_unlock_read(pj_rwmutex_t *mutex)
pj_status_t pj_rwmutex_unlock_write(pj_rwmutex_t *mutex)
pj_status_t pj_sem_create(pj_pool_t *pool, const char *name, unsigned initial, unsigned max, pj_sem_t **sem)
pj_status_t pj_sem_post(pj_sem_t *sem)
pj_status_t pj_sem_wait(pj_sem_t *sem)
pj_status_t pj_sem_destroy(pj_sem_t *sem)
pj_status_t pj_sem_trywait(pj_sem_t *sem)
pj_bool_t pj_symbianos_poll(int priority, int ms_timeout)
pj_status_t pj_symbianos_set_params(pj_symbianos_params *prm)
void pj_symbianos_set_connection_status(pj_bool_t up)
const pj_sys_info * pj_get_sys_info(void)
pj_sys_info_flag
Definition: os.h:47
@ PJ_SYS_HAS_IOS_BG
Definition: os.h:51
#define pj_thread_get_stack_info(thread, f, l)
Definition: os.h:381
int pj_thread_get_prio_min(pj_thread_t *thread)
long pj_thread_desc[(64)]
Definition: os.h:170
pj_status_t pj_thread_resume(pj_thread_t *thread)
#define pj_thread_get_stack_max_usage(thread)
Definition: os.h:379
int() pj_thread_proc(void *)
Definition: os.h:157
pj_status_t pj_thread_destroy(pj_thread_t *thread)
void * pj_thread_get_os_handle(pj_thread_t *thread)
pj_status_t pj_thread_register(const char *thread_name, pj_thread_desc desc, pj_thread_t **thread)
pj_status_t pj_thread_join(pj_thread_t *thread)
pj_thread_t * pj_thread_this(void)
pj_status_t pj_thread_set_prio(pj_thread_t *thread, int prio)
const char * pj_thread_get_name(pj_thread_t *thread)
pj_status_t pj_thread_create(pj_pool_t *pool, const char *thread_name, pj_thread_proc *proc, void *arg, pj_size_t stack_size, unsigned flags, pj_thread_t **thread)
pj_thread_create_flags
Definition: os.h:149
pj_bool_t pj_thread_is_registered(void)
int pj_thread_get_prio(pj_thread_t *thread)
pj_status_t pj_thread_sleep(unsigned msec)
#define PJ_THREAD_DESC_SIZE
Definition: os.h:163
int pj_thread_get_prio_max(pj_thread_t *thread)
pj_uint32_t pj_getpid(void)
pj_status_t pj_get_timestamp_freq(pj_timestamp *freq)
pj_uint32_t pj_elapsed_nanosec(const pj_timestamp *start, const pj_timestamp *stop)
pj_status_t pj_gettickcount(pj_time_val *tv)
pj_uint32_t pj_elapsed_msec(const pj_timestamp *start, const pj_timestamp *stop)
void pj_add_timestamp(pj_timestamp *t1, const pj_timestamp *t2)
Definition: os.h:1250
void pj_add_timestamp32(pj_timestamp *t1, pj_uint32_t t2)
Definition: os.h:1268
void pj_set_timestamp32(pj_timestamp *t, pj_uint32_t hi, pj_uint32_t lo)
Definition: os.h:1209
pj_status_t pj_get_timestamp(pj_timestamp *ts)
pj_int32_t pj_timestamp_diff32(const pj_timestamp *t1, const pj_timestamp *t2)
Definition: os.h:1323
pj_uint32_t pj_elapsed_cycle(const pj_timestamp *start, const pj_timestamp *stop)
void pj_sub_timestamp(pj_timestamp *t1, const pj_timestamp *t2)
Definition: os.h:1285
void pj_sub_timestamp32(pj_timestamp *t1, pj_uint32_t t2)
Definition: os.h:1305
pj_time_val pj_elapsed_time(const pj_timestamp *start, const pj_timestamp *stop)
pj_uint32_t pj_elapsed_usec(const pj_timestamp *start, const pj_timestamp *stop)
int pj_cmp_timestamp(const pj_timestamp *t1, const pj_timestamp *t2)
Definition: os.h:1223
pj_uint64_t pj_elapsed_msec64(const pj_timestamp *start, const pj_timestamp *stop)
pj_status_t pj_gettimeofday(pj_time_val *tv)
pj_status_t pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv)
pj_status_t pj_time_local_to_gmt(pj_time_val *tv)
pj_status_t pj_time_gmt_to_local(pj_time_val *tv)
pj_status_t pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt)
pj_status_t pj_thread_local_set(long index, void *value)
pj_status_t pj_thread_local_alloc(long *index)
void pj_thread_local_free(long index)
void * pj_thread_local_get(long index)
#define PJ_BEGIN_DECL
Definition: config.h:1284
#define PJ_INLINE(type)
Definition: config.h:1178
#define PJ_END_DECL
Definition: config.h:1285
pj_status_t pj_thread_init(void)
Definition: types.h:510
Definition: pool.h:310
Definition: types.h:120
Definition: os.h:453
void * rhostresolver
Definition: os.h:473
void * rconnection
Definition: os.h:466
void * rsocketserv
Definition: os.h:459
void * rhostresolver6
Definition: os.h:480
Definition: os.h:61
pj_str_t info
Definition: os.h:107
pj_str_t os_name
Definition: os.h:73
pj_uint32_t sdk_ver
Definition: os.h:101
pj_str_t machine
Definition: os.h:66
pj_uint32_t flags
Definition: os.h:113
pj_str_t sdk_name
Definition: os.h:94
pj_uint32_t os_ver
Definition: os.h:87
Definition: types.h:397
Declaration of basic types and utility.
Definition: types.h:134
pj_uint32_t lo
Definition: types.h:142
pj_uint32_t hi
Definition: types.h:141
struct pj_timestamp::@9 u32

 


PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.