source: trunk/libtransmission/platform.h @ 2323

Last change on this file since 2323 was 2323, checked in by titer, 15 years ago

Adds BeOS tr_condBroadcast implementation

  • Property svn:keywords set to Date Rev Author Id
File size: 3.5 KB
Line 
1/******************************************************************************
2 * $Id: platform.h 2323 2007-07-10 14:00:20Z titer $
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  #define BEOS_MAX_THREADS 256
30  typedef thread_id tr_thread_id_t;
31  typedef sem_id    tr_lock_t;
32  typedef struct
33  {
34      sem_id sem;
35      thread_id threads[BEOS_MAX_THREADS];
36      int start;
37      int end;
38  } tr_cond_t;
39#else
40  #include <pthread.h>
41  typedef pthread_t       tr_thread_id_t;
42  typedef pthread_mutex_t tr_lock_t;
43  typedef pthread_cond_t  tr_cond_t;
44#endif
45typedef struct tr_thread_s
46{
47    void          (* func ) ( void * );
48    void           * arg;
49    char           * name;
50    tr_thread_id_t thread;
51}
52tr_thread_t;
53
54const char * tr_getHomeDirectory( void );
55const char * tr_getCacheDirectory( void );
56const char * tr_getTorrentsDirectory( void );
57
58/**
59 * When instantiating a thread with a deferred call to tr_threadCreate(),
60 * initializing it to THREAD_EMPTY makes calls tr_threadJoin() safe.
61 */ 
62const tr_thread_t THREAD_EMPTY;
63
64void tr_threadCreate ( tr_thread_t *, void (*func)(void *),
65                       void * arg, const char * name );
66void tr_threadJoin   ( tr_thread_t * );
67void tr_lockInit     ( tr_lock_t * );
68void tr_lockClose    ( tr_lock_t * );
69int  tr_lockTryLock  ( tr_lock_t * );
70void tr_lockLock     ( tr_lock_t * );
71void tr_lockUnlock   ( tr_lock_t * );
72
73void tr_condInit      ( tr_cond_t * );
74void tr_condSignal    ( tr_cond_t * );
75void tr_condBroadcast ( tr_cond_t * );
76void tr_condClose     ( tr_cond_t * );
77void tr_condWait      ( tr_cond_t *, tr_lock_t * );
78
79/***
80**** RW lock:
81**** The lock can be had by one writer or any number of readers.
82***/
83
84typedef struct tr_rwlock_s
85{
86    tr_lock_t lock;
87    tr_cond_t readCond;
88    tr_cond_t writeCond;
89    size_t readCount;
90    size_t wantToRead;
91    size_t wantToWrite;
92    int haveWriter;
93}
94tr_rwlock_t;
95
96void  tr_rwInit          ( tr_rwlock_t * );
97void  tr_rwClose         ( tr_rwlock_t * );
98void  tr_rwReaderLock    ( tr_rwlock_t * );
99int   tr_rwReaderTrylock ( tr_rwlock_t * );
100void  tr_rwReaderUnlock  ( tr_rwlock_t * );
101void  tr_rwWriterLock    ( tr_rwlock_t * );
102int   tr_rwWriterTrylock ( tr_rwlock_t * );
103void  tr_rwWriterUnlock  ( tr_rwlock_t * );
104
105
106struct in_addr; /* forward declaration to calm gcc down */
107int
108tr_getDefaultRoute( struct in_addr * addr );
109
110#endif
Note: See TracBrowser for help on using the repository browser.