/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to libssts/Thread.c

  • Committer: Gustav Hartvigsson
  • Date: 2015-10-28 14:45:22 UTC
  • mto: This revision was merged to the branch mainline in revision 111.
  • Revision ID: gustav.hartvigsson@gmail.com-20151028144522-fo54z73ssjex0emw
* SMap seems to be broken... Or could it be SObject's Callback stuff? Or SLinkedList?

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
#include "Thread.h"
3
 
#if 0
4
 
  // We get this from src/external/threads.h now.
5
 
#if __WIN32__ || __WIN64__
6
 
  #if (NTDDI_VERSION >= NTDDI_WIN8)
7
 
    #include <Synchapi.h>
8
 
  #else
9
 
    #include <WinBase.h>
10
 
  #endif
11
 
#else
12
 
  /* To get nanosleep () we must define __USE_POSIX199309 for som reason.
13
 
   */
14
 
  #define __USE_POSIX199309
15
 
  #include <time.h>
16
 
  #undef __USE_POSIX199309
17
 
#endif
18
 
#endif
19
3
 
20
4
/*
21
5
  Utility functions associated with threads.
27
11
  Sleep (us / 1000)
28
12
#else
29
13
  /* We are not a windows system, so lets assume that we have posix's nanosleep
30
 
   * Taken from: 
 
14
   * Taken from:
31
15
   */
32
16
  struct timespec req = {0};
33
17
  req.tv_sec = (int)(us / 1000);
50
34
SMutex *
51
35
s_mutex_new () {
52
36
  SMutex * self = malloc (sizeof (SMutex));
53
 
  
 
37
 
54
38
  atomic_init(&(self->locked), FALSE);
55
 
  
 
39
 
56
40
  mtx_init (&(self->mutex), mtx_plain);
57
 
  
 
41
 
58
42
  return self;
59
43
}
60
44
 
95
79
struct SThread {
96
80
  thrd_t thread;
97
81
  RunFunc func;
98
 
  
 
82
 
99
83
  _Atomic(sboolean) is_running;
100
84
};
101
85
 
102
86
SThread *
103
87
s_thread_new (RunFunc func) {
104
88
  SThread * self = malloc (sizeof (SThread));
105
 
  
 
89
 
106
90
  self->func = func;
107
 
  
 
91
 
108
92
  atomic_store (&(self->is_running), FALSE);
109
 
  
 
93
 
110
94
  return self;
111
95
}
112
96