/[svn]/liblscp/trunk/lscp/thread.h
ViewVC logotype

Annotation of /liblscp/trunk/lscp/thread.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 103 - (hide annotations) (download) (as text)
Fri Jun 4 14:32:51 2004 UTC (19 years, 10 months ago) by capela
File MIME type: text/x-c++hdr
File size: 3009 byte(s)
Initial alpha release.

1 capela 103 // thread.h
2     //
3     /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved.
6    
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public
9     License as published by the Free Software Foundation; either
10     version 2.1 of the License, or (at your option) any later version.
11    
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15     Lesser General Public License for more details.
16    
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20    
21     *****************************************************************************/
22    
23     #ifndef __LSCP_THREAD_H
24     #define __LSCP_THREAD_H
25    
26     #include <stdio.h>
27     #include <stdlib.h>
28     #include <string.h>
29    
30     #if (defined(_WIN32) || defined(__WIN32__))
31     #if (!defined(WIN32))
32     #define WIN32
33     #endif
34     #endif
35    
36     #if defined(WIN32)
37     #include <windows.h>
38     #else
39     #include <pthread.h>
40     #endif
41    
42     #include "lscp/version.h"
43    
44     #if defined(__cplusplus)
45     extern "C" {
46     #endif
47    
48     //-------------------------------------------------------------------------
49     // Status.
50    
51     typedef enum _lscp_status_t
52     {
53     LSCP_OK = 0,
54     LSCP_FAILED = -1,
55     LSCP_ERROR = -2,
56     LSCP_WARNING = -3,
57     LSCP_TIMEOUT = -4,
58     LSCP_QUIT = -5
59    
60     } lscp_status_t;
61    
62     //-------------------------------------------------------------------------
63     // Mutexes.
64    
65     #if defined(WIN32)
66     typedef HANDLE lscp_mutex_t;
67     #define lscp_mutex_init(m) { (m) = CreateMutex(NULL, 0, NULL); }
68     #define lscp_mutex_destroy(m) if (m) { CloseHandle(m); }
69     #define lscp_mutex_lock(m) WaitForSingleObject((m), INFINITE)
70     #define lscp_mutex_unlock(m) ReleaseMutex(m)
71     #else
72     typedef pthread_mutex_t lscp_mutex_t;
73     #define lscp_mutex_init(m) pthread_mutex_init(&(m), NULL)
74     #define lscp_mutex_destroy(m) pthread_mutex_destroy(&(m))
75     #define lscp_mutex_lock(m) pthread_mutex_lock(&(m))
76     #define lscp_mutex_unlock(m) pthread_mutex_unlock(&(m))
77     #endif
78    
79     //-------------------------------------------------------------------------
80     // Threads.
81    
82     struct _lscp_thread_t;
83    
84     typedef void (*lscp_thread_proc_t)(void *pvData);
85    
86     typedef struct _lscp_thread_t lscp_thread_t;
87    
88     lscp_thread_t *lscp_thread_create (lscp_thread_proc_t pfnProc, void *pvData, int iDetach);
89     lscp_status_t lscp_thread_join (lscp_thread_t *pThread);
90     lscp_status_t lscp_thread_cancel (lscp_thread_t *pThread);
91     lscp_status_t lscp_thread_destroy (lscp_thread_t *pThread);
92    
93     #if defined(WIN32)
94     #define lscp_thread_exit() pthread_exit(NULL)
95     #else
96     #define lscp_thread_exit() ExitThread(0)
97     #endif
98    
99     #if defined(__cplusplus)
100     }
101     #endif
102    
103     #endif // __LSCP_THREAD_H
104    
105     // end of thread.h

  ViewVC Help
Powered by ViewVC