Symbian compilation fixes.
[silc.git] / lib / silcutil / symbian / silcepocthread.cpp
1 /*
2
3   silcepocthread.cpp
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2002 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19 /* $Id$ */
20
21 #include "silcincludes.h"
22
23 #ifdef SILC_THREADS
24
25 /* Thread structure for EPOC */
26 typedef struct {
27   RThread *thread;
28   SilcThreadStart start_func;
29   void *context;
30   bool waitable;
31 } *SilcEpocThread;
32
33 /* The actual thread function */
34
35 TInt silc_thread_epoc_start(TAny *context)
36 {
37   SilcEpocThread thread = (SilcEpocThread)context;
38
39   thread->start_func(thread->context);
40   silc_thread_exit(NULL);
41
42   return 0;
43 }
44
45 SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
46                               bool waitable)
47 {
48 #ifdef SILC_THREADS
49   SilcEpocThread thread;
50   TInt ret;
51
52   SILC_LOG_DEBUG(("Creating new thread"));
53
54   thread = silc_calloc(1, sizeof(*thread));
55   thread->start_func = start_func;
56   thread->context = context;
57   thread->waitable = waitable;
58
59   /* Create the thread */
60   /* XXX Unique name should be given for the thread */
61   thread->thread = new RThread();
62   ret = thread->thread->Create(NULL, silc_thread_epoc_start, 0, 0, 0,
63                                (TAny *)thread, EOwnerProcess);
64   if (ret != KErrNone) {
65     SILC_LOG_ERROR(("Could not create new thread"));
66     delete thread->thread;
67     silc_free(thread);
68     return NULL;
69   }
70
71   return (SilcThread)thread;
72 #else
73   /* Call thread callback immediately */
74   (*start_func)(context);
75   return NULL;
76 #endif
77 }
78
79 void silc_thread_exit(void *exit_value)
80 {
81 #ifdef SILC_THREADS
82   /* XXX */
83 #endif
84 }
85
86 SilcThread silc_thread_self(void)
87 {
88 #ifdef SILC_THREADS
89   /* XXX */
90   return NULL;
91 #else
92   return NULL;
93 #endif
94 }
95
96 bool silc_thread_wait(SilcThread thread, void **exit_value)
97 {
98 #ifdef SILC_THREADS
99   /* XXX */
100   return TRUE;
101 #else
102   return FALSE;
103 #endif
104 }