BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB Reference

os.h
Go to the documentation of this file.
1 /* $Id: os.h 5012 2015-03-22 07:50:28Z ming $ */
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 
323 PJ_DECL(pj_status_t) pj_thread_join(pj_thread_t *thread);
324 
325 
335 PJ_DECL(pj_status_t) pj_thread_destroy(pj_thread_t *thread);
336 
337 
345 PJ_DECL(pj_status_t) pj_thread_sleep(unsigned msec);
346 
353 #if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0
354 
355 # define PJ_CHECK_STACK() pj_thread_check_stack(__FILE__, __LINE__)
356 
360 PJ_DECL(void) pj_thread_check_stack(const char *file, int line);
361 
366 
371  const char **file,
372  int *line);
373 #else
374 
375 # define PJ_CHECK_STACK()
376 
377 # define pj_thread_get_stack_max_usage(thread) 0
378 
379 # define pj_thread_get_stack_info(thread,f,l) (*(f)="",*(l)=0)
380 #endif /* PJ_OS_HAS_CHECK_STACK */
381 
386 /* **************************************************************************/
443 PJ_DECL(pj_bool_t) pj_symbianos_poll(int priority, int ms_timeout);
444 
445 
450 typedef struct pj_symbianos_params
451 {
457  void *rsocketserv;
458 
464  void *rconnection;
465 
472 
479 
481 
492 
505 
510 /* **************************************************************************/
524 PJ_DECL(pj_status_t) pj_thread_local_alloc(long *index);
525 
531 PJ_DECL(void) pj_thread_local_free(long index);
532 
539 PJ_DECL(pj_status_t) pj_thread_local_set(long index, void *value);
540 
547 PJ_DECL(void*) pj_thread_local_get(long index);
548 
549 
555 /* **************************************************************************/
579 PJ_DECL(pj_status_t) pj_atomic_create( pj_pool_t *pool,
580  pj_atomic_value_t initial,
581  pj_atomic_t **atomic );
582 
590 PJ_DECL(pj_status_t) pj_atomic_destroy( pj_atomic_t *atomic_var );
591 
598 PJ_DECL(void) pj_atomic_set( pj_atomic_t *atomic_var,
599  pj_atomic_value_t value);
600 
608 PJ_DECL(pj_atomic_value_t) pj_atomic_get(pj_atomic_t *atomic_var);
609 
615 PJ_DECL(void) pj_atomic_inc(pj_atomic_t *atomic_var);
616 
625 
631 PJ_DECL(void) pj_atomic_dec(pj_atomic_t *atomic_var);
632 
641 
648 PJ_DECL(void) pj_atomic_add( pj_atomic_t *atomic_var,
649  pj_atomic_value_t value);
650 
660  pj_atomic_value_t value);
661 
666 /* **************************************************************************/
683 typedef enum pj_mutex_type_e
684 {
685  PJ_MUTEX_DEFAULT,
686  PJ_MUTEX_SIMPLE,
687  PJ_MUTEX_RECURSE
689 
690 
701 PJ_DECL(pj_status_t) pj_mutex_create(pj_pool_t *pool,
702  const char *name,
703  int type,
704  pj_mutex_t **mutex);
705 
717 PJ_DECL(pj_status_t) pj_mutex_create_simple( pj_pool_t *pool, const char *name,
718  pj_mutex_t **mutex );
719 
732  const char *name,
733  pj_mutex_t **mutex );
734 
741 PJ_DECL(pj_status_t) pj_mutex_lock(pj_mutex_t *mutex);
742 
749 PJ_DECL(pj_status_t) pj_mutex_unlock(pj_mutex_t *mutex);
750 
758 PJ_DECL(pj_status_t) pj_mutex_trylock(pj_mutex_t *mutex);
759 
766 PJ_DECL(pj_status_t) pj_mutex_destroy(pj_mutex_t *mutex);
767 
774 PJ_DECL(pj_bool_t) pj_mutex_is_locked(pj_mutex_t *mutex);
775 
780 /* **************************************************************************/
796 typedef struct pj_rwmutex_t pj_rwmutex_t;
797 
807 PJ_DECL(pj_status_t) pj_rwmutex_create(pj_pool_t *pool, const char *name,
808  pj_rwmutex_t **mutex);
809 
816 PJ_DECL(pj_status_t) pj_rwmutex_lock_read(pj_rwmutex_t *mutex);
817 
824 PJ_DECL(pj_status_t) pj_rwmutex_lock_write(pj_rwmutex_t *mutex);
825 
832 PJ_DECL(pj_status_t) pj_rwmutex_unlock_read(pj_rwmutex_t *mutex);
833 
840 PJ_DECL(pj_status_t) pj_rwmutex_unlock_write(pj_rwmutex_t *mutex);
841 
848 PJ_DECL(pj_status_t) pj_rwmutex_destroy(pj_rwmutex_t *mutex);
849 
850 
856 /* **************************************************************************/
879 PJ_DECL(void) pj_enter_critical_section(void);
880 
884 PJ_DECL(void) pj_leave_critical_section(void);
885 
890 /* **************************************************************************/
891 #if defined(PJ_HAS_SEMAPHORE) && PJ_HAS_SEMAPHORE != 0
892 
911 PJ_DECL(pj_status_t) pj_sem_create( pj_pool_t *pool,
912  const char *name,
913  unsigned initial,
914  unsigned max,
915  pj_sem_t **sem);
916 
924 PJ_DECL(pj_status_t) pj_sem_wait(pj_sem_t *sem);
925 
933 PJ_DECL(pj_status_t) pj_sem_trywait(pj_sem_t *sem);
934 
942 PJ_DECL(pj_status_t) pj_sem_post(pj_sem_t *sem);
943 
951 PJ_DECL(pj_status_t) pj_sem_destroy(pj_sem_t *sem);
952 
956 #endif /* PJ_HAS_SEMAPHORE */
957 
958 
959 /* **************************************************************************/
960 #if defined(PJ_HAS_EVENT_OBJ) && PJ_HAS_EVENT_OBJ != 0
961 
981 PJ_DECL(pj_status_t) pj_event_create(pj_pool_t *pool, const char *name,
982  pj_bool_t manual_reset, pj_bool_t initial,
983  pj_event_t **event);
984 
992 PJ_DECL(pj_status_t) pj_event_wait(pj_event_t *event);
993 
1001 PJ_DECL(pj_status_t) pj_event_trywait(pj_event_t *event);
1002 
1014 PJ_DECL(pj_status_t) pj_event_set(pj_event_t *event);
1015 
1026 PJ_DECL(pj_status_t) pj_event_pulse(pj_event_t *event);
1027 
1035 PJ_DECL(pj_status_t) pj_event_reset(pj_event_t *event);
1036 
1044 PJ_DECL(pj_status_t) pj_event_destroy(pj_event_t *event);
1045 
1049 #endif /* PJ_HAS_EVENT_OBJ */
1050 
1051 /* **************************************************************************/
1072 
1073 
1082 PJ_DECL(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt);
1083 
1092 PJ_DECL(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv);
1093 
1102 
1111 
1116 /* **************************************************************************/
1117 #if defined(PJ_TERM_HAS_COLOR) && PJ_TERM_HAS_COLOR != 0
1118 
1132 PJ_DECL(pj_status_t) pj_term_set_color(pj_color_t color);
1133 
1139 PJ_DECL(pj_color_t) pj_term_get_color(void);
1140 
1145 #endif /* PJ_TERM_HAS_COLOR */
1146 
1147 /* **************************************************************************/
1168 /*
1169  * High resolution timer.
1170  */
1171 #if defined(PJ_HAS_HIGH_RES_TIMER) && PJ_HAS_HIGH_RES_TIMER != 0
1172 
1181 
1192 
1200 
1208  pj_uint32_t lo)
1209 {
1210  t->u32.hi = hi;
1211  t->u32.lo = lo;
1212 }
1213 
1214 
1222 {
1223 #if PJ_HAS_INT64
1224  if (t1->u64 < t2->u64)
1225  return -1;
1226  else if (t1->u64 > t2->u64)
1227  return 1;
1228  else
1229  return 0;
1230 #else
1231  if (t1->u32.hi < t2->u32.hi ||
1232  (t1->u32.hi == t2->u32.hi && t1->u32.lo < t2->u32.lo))
1233  return -1;
1234  else if (t1->u32.hi > t2->u32.hi ||
1235  (t1->u32.hi == t2->u32.hi && t1->u32.lo > t2->u32.lo))
1236  return 1;
1237  else
1238  return 0;
1239 #endif
1240 }
1241 
1242 
1249 {
1250 #if PJ_HAS_INT64
1251  t1->u64 += t2->u64;
1252 #else
1253  pj_uint32_t old = t1->u32.lo;
1254  t1->u32.hi += t2->u32.hi;
1255  t1->u32.lo += t2->u32.lo;
1256  if (t1->u32.lo < old)
1257  ++t1->u32.hi;
1258 #endif
1259 }
1260 
1267 {
1268 #if PJ_HAS_INT64
1269  t1->u64 += t2;
1270 #else
1271  pj_uint32_t old = t1->u32.lo;
1272  t1->u32.lo += t2;
1273  if (t1->u32.lo < old)
1274  ++t1->u32.hi;
1275 #endif
1276 }
1277 
1284 {
1285 #if PJ_HAS_INT64
1286  t1->u64 -= t2->u64;
1287 #else
1288  t1->u32.hi -= t2->u32.hi;
1289  if (t1->u32.lo >= t2->u32.lo)
1290  t1->u32.lo -= t2->u32.lo;
1291  else {
1292  t1->u32.lo -= t2->u32.lo;
1293  --t1->u32.hi;
1294  }
1295 #endif
1296 }
1297 
1304 {
1305 #if PJ_HAS_INT64
1306  t1->u64 -= t2;
1307 #else
1308  if (t1->u32.lo >= t2)
1309  t1->u32.lo -= t2;
1310  else {
1311  t1->u32.lo -= t2;
1312  --t1->u32.hi;
1313  }
1314 #endif
1315 }
1316 
1322  const pj_timestamp *t2)
1323 {
1324  /* Be careful with the signess (I think!) */
1325 #if PJ_HAS_INT64
1326  pj_int64_t diff = t2->u64 - t1->u64;
1327  return (pj_int32_t) diff;
1328 #else
1329  pj_int32 diff = t2->u32.lo - t1->u32.lo;
1330  return diff;
1331 #endif
1332 }
1333 
1334 
1350 PJ_DECL(pj_time_val) pj_elapsed_time( const pj_timestamp *start,
1351  const pj_timestamp *stop );
1352 
1368 PJ_DECL(pj_uint32_t) pj_elapsed_msec( const pj_timestamp *start,
1369  const pj_timestamp *stop );
1370 
1374 PJ_DECL(pj_uint64_t) pj_elapsed_msec64(const pj_timestamp *start,
1375  const pj_timestamp *stop );
1376 
1392 PJ_DECL(pj_uint32_t) pj_elapsed_usec( const pj_timestamp *start,
1393  const pj_timestamp *stop );
1394 
1410 PJ_DECL(pj_uint32_t) pj_elapsed_nanosec( const pj_timestamp *start,
1411  const pj_timestamp *stop );
1412 
1428 PJ_DECL(pj_uint32_t) pj_elapsed_cycle( const pj_timestamp *start,
1429  const pj_timestamp *stop );
1430 
1431 
1432 #endif /* PJ_HAS_HIGH_RES_TIMER */
1433 
1437 /* **************************************************************************/
1447 typedef int (*pj_main_func_ptr)(int argc, char *argv[]);
1448 
1463 PJ_DECL(int) pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[],
1464  unsigned flags);
1465 
1469 /* **************************************************************************/
1475 
1476 
1478 
1479 #endif /* __PJ_OS_H__ */
1480 

 


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