1 | /****************************************************************************** |
---|
2 | * $Id: platform.h 2154 2007-06-18 19:39:52Z charles $ |
---|
3 | * |
---|
4 | * Copyright (c) 2005 Transmission authors and contributors |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
---|
7 | * copy of this software and associated documentation files (the "Software"), |
---|
8 | * to deal in the Software without restriction, including without limitation |
---|
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
10 | * and/or sell copies of the Software, and to permit persons to whom the |
---|
11 | * Software is furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
22 | * DEALINGS IN THE SOFTWARE. |
---|
23 | *****************************************************************************/ |
---|
24 | #ifndef TR_PLATFORM_H |
---|
25 | #define TR_PLATFORM_H 1 |
---|
26 | |
---|
27 | #ifdef SYS_BEOS |
---|
28 | #include <kernel/OS.h> |
---|
29 | typedef thread_id tr_thread_id_t; |
---|
30 | typedef sem_id tr_lock_t; |
---|
31 | typedef int tr_cond_t; |
---|
32 | #else |
---|
33 | #include <pthread.h> |
---|
34 | typedef pthread_t tr_thread_id_t; |
---|
35 | typedef pthread_mutex_t tr_lock_t; |
---|
36 | typedef pthread_cond_t tr_cond_t; |
---|
37 | #endif |
---|
38 | typedef struct tr_thread_s |
---|
39 | { |
---|
40 | void (* func ) ( void * ); |
---|
41 | void * arg; |
---|
42 | char * name; |
---|
43 | tr_thread_id_t thread;; |
---|
44 | } |
---|
45 | tr_thread_t; |
---|
46 | |
---|
47 | /* only for debugging purposes */ |
---|
48 | const char * tr_getHomeDirectory( void ); |
---|
49 | |
---|
50 | const char * tr_getCacheDirectory( void ); |
---|
51 | const char * tr_getTorrentsDirectory( void ); |
---|
52 | |
---|
53 | /** |
---|
54 | * When instantiating a thread with a deferred call to tr_threadCreate(), |
---|
55 | * initializing it to THREAD_EMPTY makes calls tr_threadJoin() safe. |
---|
56 | */ |
---|
57 | const tr_thread_t THREAD_EMPTY; |
---|
58 | |
---|
59 | void tr_threadCreate ( tr_thread_t *, void (*func)(void *), |
---|
60 | void * arg, char * name ); |
---|
61 | void tr_threadJoin ( tr_thread_t * ); |
---|
62 | void tr_lockInit ( tr_lock_t * ); |
---|
63 | void tr_lockClose ( tr_lock_t * ); |
---|
64 | |
---|
65 | static inline void tr_lockLock( tr_lock_t * l ) |
---|
66 | { |
---|
67 | #ifdef SYS_BEOS |
---|
68 | acquire_sem( *l ); |
---|
69 | #else |
---|
70 | pthread_mutex_lock( l ); |
---|
71 | #endif |
---|
72 | } |
---|
73 | |
---|
74 | static inline void tr_lockUnlock( tr_lock_t * l ) |
---|
75 | { |
---|
76 | #ifdef SYS_BEOS |
---|
77 | release_sem( *l ); |
---|
78 | #else |
---|
79 | pthread_mutex_unlock( l ); |
---|
80 | #endif |
---|
81 | } |
---|
82 | |
---|
83 | void tr_condInit( tr_cond_t * ); |
---|
84 | void tr_condWait( tr_cond_t *, tr_lock_t * ); |
---|
85 | void tr_condSignal( tr_cond_t * ); |
---|
86 | void tr_condClose( tr_cond_t * ); |
---|
87 | |
---|
88 | struct in_addr; /* forward declaration to calm gcc down */ |
---|
89 | int |
---|
90 | tr_getDefaultRoute( struct in_addr * addr ); |
---|
91 | |
---|
92 | #endif |
---|