BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

os.h
Go to the documentation of this file.
1 /* $Id: os.h 3664 2011-07-19 03:42:28Z nanang $ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 #ifndef __PJ_OS_H__
21 #define __PJ_OS_H__
22 
27 #include <pj/types.h>
28 
30 
36 /* **************************************************************************/
47 typedef enum pj_sys_info_flag
48 {
53 
55 
56 
61 typedef struct pj_sys_info
62 {
68 
75 
89 
96 
103 
109 
115 
116 } pj_sys_info;
117 
118 
124 PJ_DECL(const pj_sys_info*) pj_get_sys_info(void);
125 
126 /*
127  * @}
128  */
129 
130 /* **************************************************************************/
150 {
151  PJ_THREAD_SUSPENDED = 1
153 
154 
158 typedef int (PJ_THREAD_FUNC pj_thread_proc)(void*);
159 
163 #if !defined(PJ_THREAD_DESC_SIZE)
164 # define PJ_THREAD_DESC_SIZE (64)
165 #endif
166 
172 
177 PJ_DECL(pj_uint32_t) pj_getpid(void);
178 
198 PJ_DECL(pj_status_t) pj_thread_create( pj_pool_t *pool,
199  const char *thread_name,
200  pj_thread_proc *proc,
201  void *arg,
202  pj_size_t stack_size,
203  unsigned flags,
204  pj_thread_t **thread );
205 
222 PJ_DECL(pj_status_t) pj_thread_register ( const char *thread_name,
223  pj_thread_desc desc,
224  pj_thread_t **thread);
225 
231 PJ_DECL(pj_bool_t) pj_thread_is_registered(void);
232 
233 
241 PJ_DECL(int) pj_thread_get_prio(pj_thread_t *thread);
242 
243 
254 PJ_DECL(pj_status_t) pj_thread_set_prio(pj_thread_t *thread, int prio);
255 
262 PJ_DECL(int) pj_thread_get_prio_min(pj_thread_t *thread);
263 
264 
271 PJ_DECL(int) pj_thread_get_prio_max(pj_thread_t *thread);
272 
273 
285 PJ_DECL(void*) pj_thread_get_os_handle(pj_thread_t *thread);
286 
294 PJ_DECL(const char*) pj_thread_get_name(pj_thread_t *thread);
295 
303 PJ_DECL(pj_status_t) pj_thread_resume(pj_thread_t *thread);
304 
310 PJ_DECL(pj_thread_t*) pj_thread_this(void);
311 
321 PJ_DECL(pj_status_t) pj_thread_join(pj_thread_t *thread);
322 
323 
333 PJ_DECL(pj_status_t) pj_thread_destroy(pj_thread_t *thread);
334 
335 
343 PJ_DECL(pj_status_t) pj_thread_sleep(unsigned msec);
344 
351 #if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0
352 
353 # define PJ_CHECK_STACK() pj_thread_check_stack(__FILE__, __LINE__)
354 
358 PJ_DECL(void) pj_thread_check_stack(const char *file, int line);
359 
364 
369  const char **file,
370  int *line);
371 #else
372 
373 # define PJ_CHECK_STACK()
374 
375 # define pj_thread_get_stack_max_usage(thread) 0
376 
377 # define pj_thread_get_stack_info(thread,f,l) (*(f)="",*(l)=0)
378 #endif /* PJ_OS_HAS_CHECK_STACK */
379 
384 /* **************************************************************************/
441 PJ_DECL(pj_bool_t) pj_symbianos_poll(int priority, int ms_timeout);
442 
443 
448 typedef struct pj_symbianos_params
449 {
455  void *rsocketserv;
456 
462  void *rconnection;
463 
470 
477 
479 
490 
503 
508 /* **************************************************************************/
522 PJ_DECL(pj_status_t) pj_thread_local_alloc(long *index);
523 
529 PJ_DECL(void) pj_thread_local_free(long index);
530 
537 PJ_DECL(pj_status_t) pj_thread_local_set(long index, void *value);
538 
545 PJ_DECL(void*) pj_thread_local_get(long index);
546 
547 
553 /* **************************************************************************/
577 PJ_DECL(pj_status_t) pj_atomic_create( pj_pool_t *pool,
578  pj_atomic_value_t initial,
579  pj_atomic_t **atomic );
580 
588 PJ_DECL(pj_status_t) pj_atomic_destroy( pj_atomic_t *atomic_var );
589 
596 PJ_DECL(void) pj_atomic_set( pj_atomic_t *atomic_var,
597  pj_atomic_value_t value);
598 
606 PJ_DECL(pj_atomic_value_t) pj_atomic_get(pj_atomic_t *atomic_var);
607 
613 PJ_DECL(void) pj_atomic_inc(pj_atomic_t *atomic_var);
614 
623 
629 PJ_DECL(void) pj_atomic_dec(pj_atomic_t *atomic_var);
630 
639 
646 PJ_DECL(void) pj_atomic_add( pj_atomic_t *atomic_var,
647  pj_atomic_value_t value);
648 
658  pj_atomic_value_t value);
659 
664 /* **************************************************************************/
681 typedef enum pj_mutex_type_e
682 {
683  PJ_MUTEX_DEFAULT,
684  PJ_MUTEX_SIMPLE,
685  PJ_MUTEX_RECURSE
687 
688 
699 PJ_DECL(pj_status_t) pj_mutex_create(pj_pool_t *pool,
700  const char *name,
701  int type,
702  pj_mutex_t **mutex);
703 
715 PJ_DECL(pj_status_t) pj_mutex_create_simple( pj_pool_t *pool, const char *name,
716  pj_mutex_t **mutex );
717 
730  const char *name,
731  pj_mutex_t **mutex );
732 
739 PJ_DECL(pj_status_t) pj_mutex_lock(pj_mutex_t *mutex);
740 
747 PJ_DECL(pj_status_t) pj_mutex_unlock(pj_mutex_t *mutex);
748 
756 PJ_DECL(pj_status_t) pj_mutex_trylock(pj_mutex_t *mutex);
757 
764 PJ_DECL(pj_status_t) pj_mutex_destroy(pj_mutex_t *mutex);
765 
772 PJ_DECL(pj_bool_t) pj_mutex_is_locked(pj_mutex_t *mutex);
773 
778 /* **************************************************************************/
794 typedef struct pj_rwmutex_t pj_rwmutex_t;
795 
805 PJ_DECL(pj_status_t) pj_rwmutex_create(pj_pool_t *pool, const char *name,
806  pj_rwmutex_t **mutex);
807 
814 PJ_DECL(pj_status_t) pj_rwmutex_lock_read(pj_rwmutex_t *mutex);
815 
822 PJ_DECL(pj_status_t) pj_rwmutex_lock_write(pj_rwmutex_t *mutex);
823 
830 PJ_DECL(pj_status_t) pj_rwmutex_unlock_read(pj_rwmutex_t *mutex);
831 
838 PJ_DECL(pj_status_t) pj_rwmutex_unlock_write(pj_rwmutex_t *mutex);
839 
846 PJ_DECL(pj_status_t) pj_rwmutex_destroy(pj_rwmutex_t *mutex);
847 
848 
854 /* **************************************************************************/
877 PJ_DECL(void) pj_enter_critical_section(void);
878 
882 PJ_DECL(void) pj_leave_critical_section(void);
883 
888 /* **************************************************************************/
889 #if defined(PJ_HAS_SEMAPHORE) && PJ_HAS_SEMAPHORE != 0
890 
909 PJ_DECL(pj_status_t) pj_sem_create( pj_pool_t *pool,
910  const char *name,
911  unsigned initial,
912  unsigned max,
913  pj_sem_t **sem);
914 
922 PJ_DECL(pj_status_t) pj_sem_wait(pj_sem_t *sem);
923 
931 PJ_DECL(pj_status_t) pj_sem_trywait(pj_sem_t *sem);
932 
940 PJ_DECL(pj_status_t) pj_sem_post(pj_sem_t *sem);
941 
949 PJ_DECL(pj_status_t) pj_sem_destroy(pj_sem_t *sem);
950 
954 #endif /* PJ_HAS_SEMAPHORE */
955 
956 
957 /* **************************************************************************/
958 #if defined(PJ_HAS_EVENT_OBJ) && PJ_HAS_EVENT_OBJ != 0
959 
979 PJ_DECL(pj_status_t) pj_event_create(pj_pool_t *pool, const char *name,
980  pj_bool_t manual_reset, pj_bool_t initial,
981  pj_event_t **event);
982 
990 PJ_DECL(pj_status_t) pj_event_wait(pj_event_t *event);
991 
999 PJ_DECL(pj_status_t) pj_event_trywait(pj_event_t *event);
1000 
1012 PJ_DECL(pj_status_t) pj_event_set(pj_event_t *event);
1013 
1024 PJ_DECL(pj_status_t) pj_event_pulse(pj_event_t *event);
1025 
1033 PJ_DECL(pj_status_t) pj_event_reset(pj_event_t *event);
1034 
1042 PJ_DECL(pj_status_t) pj_event_destroy(pj_event_t *event);
1043 
1047 #endif /* PJ_HAS_EVENT_OBJ */
1048 
1049 /* **************************************************************************/
1070 
1071 
1080 PJ_DECL(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt);
1081 
1090 PJ_DECL(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv);
1091 
1100 
1109 
1114 /* **************************************************************************/
1115 #if defined(PJ_TERM_HAS_COLOR) && PJ_TERM_HAS_COLOR != 0
1116 
1130 PJ_DECL(pj_status_t) pj_term_set_color(pj_color_t color);
1131 
1137 PJ_DECL(pj_color_t) pj_term_get_color(void);
1138 
1143 #endif /* PJ_TERM_HAS_COLOR */
1144 
1145 /* **************************************************************************/
1166 /*
1167  * High resolution timer.
1168  */
1169 #if defined(PJ_HAS_HIGH_RES_TIMER) && PJ_HAS_HIGH_RES_TIMER != 0
1170 
1179 
1190 
1198 
1206  pj_uint32_t lo)
1207 {
1208  t->u32.hi = hi;
1209  t->u32.lo = lo;
1210 }
1211 
1212 
1220 {
1221 #if PJ_HAS_INT64
1222  if (t1->u64 < t2->u64)
1223  return -1;
1224  else if (t1->u64 > t2->u64)
1225  return 1;
1226  else
1227  return 0;
1228 #else
1229  if (t1->u32.hi < t2->u32.hi ||
1230  (t1->u32.hi == t2->u32.hi && t1->u32.lo < t2->u32.lo))
1231  return -1;
1232  else if (t1->u32.hi > t2->u32.hi ||
1233  (t1->u32.hi == t2->u32.hi && t1->u32.lo > t2->u32.lo))
1234  return 1;
1235  else
1236  return 0;
1237 #endif
1238 }
1239 
1240 
1247 {
1248 #if PJ_HAS_INT64
1249  t1->u64 += t2->u64;
1250 #else
1251  pj_uint32_t old = t1->u32.lo;
1252  t1->u32.hi += t2->u32.hi;
1253  t1->u32.lo += t2->u32.lo;
1254  if (t1->u32.lo < old)
1255  ++t1->u32.hi;
1256 #endif
1257 }
1258 
1265 {
1266 #if PJ_HAS_INT64
1267  t1->u64 += t2;
1268 #else
1269  pj_uint32_t old = t1->u32.lo;
1270  t1->u32.lo += t2;
1271  if (t1->u32.lo < old)
1272  ++t1->u32.hi;
1273 #endif
1274 }
1275 
1282 {
1283 #if PJ_HAS_INT64
1284  t1->u64 -= t2->u64;
1285 #else
1286  t1->u32.hi -= t2->u32.hi;
1287  if (t1->u32.lo >= t2->u32.lo)
1288  t1->u32.lo -= t2->u32.lo;
1289  else {
1290  t1->u32.lo -= t2->u32.lo;
1291  --t1->u32.hi;
1292  }
1293 #endif
1294 }
1295 
1302 {
1303 #if PJ_HAS_INT64
1304  t1->u64 -= t2;
1305 #else
1306  if (t1->u32.lo >= t2)
1307  t1->u32.lo -= t2;
1308  else {
1309  t1->u32.lo -= t2;
1310  --t1->u32.hi;
1311  }
1312 #endif
1313 }
1314 
1320  const pj_timestamp *t2)
1321 {
1322  /* Be careful with the signess (I think!) */
1323 #if PJ_HAS_INT64
1324  pj_int64_t diff = t2->u64 - t1->u64;
1325  return (pj_int32_t) diff;
1326 #else
1327  pj_int32 diff = t2->u32.lo - t1->u32.lo;
1328  return diff;
1329 #endif
1330 }
1331 
1332 
1348 PJ_DECL(pj_time_val) pj_elapsed_time( const pj_timestamp *start,
1349  const pj_timestamp *stop );
1350 
1366 PJ_DECL(pj_uint32_t) pj_elapsed_msec( const pj_timestamp *start,
1367  const pj_timestamp *stop );
1368 
1372 PJ_DECL(pj_uint64_t) pj_elapsed_msec64(const pj_timestamp *start,
1373  const pj_timestamp *stop );
1374 
1390 PJ_DECL(pj_uint32_t) pj_elapsed_usec( const pj_timestamp *start,
1391  const pj_timestamp *stop );
1392 
1408 PJ_DECL(pj_uint32_t) pj_elapsed_nanosec( const pj_timestamp *start,
1409  const pj_timestamp *stop );
1410 
1426 PJ_DECL(pj_uint32_t) pj_elapsed_cycle( const pj_timestamp *start,
1427  const pj_timestamp *stop );
1428 
1429 
1430 #endif /* PJ_HAS_HIGH_RES_TIMER */
1431 
1435 /* **************************************************************************/
1442 /* Type for main function. */
1443 typedef int (*pj_main_func_ptr)(int argc, char *argv[]);
1444 
1459 int pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[],
1460  unsigned flags);
1461 
1465 /* **************************************************************************/
1471 
1472 
1474 
1475 #endif /* __PJ_OS_H__ */
1476 

 


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