/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: 2021-01-07 22:32:25 UTC
  • mfrom: (151.1.2 simpletypesystem_meson)
  • Revision ID: gustav.hartvigsson@gmail.com-20210107223225-4i46581v09jkt7tr
* Merged lp:~gustav-hartvigsson/simpletypesystem/meson

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
s_thread_status_get_name (SThreadStatus status) {
25
25
  switch (status) {
26
26
    case (S_THREAD_STATUS_SUCCESS):
 
27
      return SThreadStatusName[0];
 
28
      break;
 
29
    case (S_THREAD_STATUS_TIMEOUT):
27
30
      return SThreadStatusName[1];
28
31
      break;
29
 
    case (S_THREAD_STATUS_TIMEOUT):
 
32
    case (S_THREAD_STATUS_ERROR):
30
33
      return SThreadStatusName[2];
31
34
      break;
32
 
    case (S_THREAD_STATUS_ERROR):
 
35
    case (S_THREAD_STATUS_BUSY):
33
36
      return SThreadStatusName[3];
34
37
      break;
35
 
    case (S_THREAD_STATUS_BUSY):
 
38
    case (S_THREAD_STATUS_NO_MEM):
36
39
      return SThreadStatusName[4];
37
40
      break;
38
 
    case (S_THREAD_STATUS_NO_MEM):
 
41
    case (S_THREAD_STATUS_LAST):
39
42
      return SThreadStatusName[5];
40
43
      break;
41
 
    case (S_THREAD_STATUS_LAST):
42
 
      return SThreadStatusName[6];
43
 
      break;
44
44
    default:
45
45
      return NULL;
46
46
  }
56
56
  _Atomic(sboolean) locked;
57
57
};
58
58
 
 
59
schar *
 
60
s_mutex_flag_get_name (SMutexFlag flag) {
 
61
  switch (flag) {
 
62
    case (S_MUTEX_FLAG_PLAIN):
 
63
      return SMutexFlagName[0];
 
64
      break;
 
65
    case (S_MUTEX_FLAG_TIMED):
 
66
      return SMutexFlagName[1];
 
67
      break;
 
68
    case (S_MUTEX_FLAG_RECURSIVE):
 
69
      return SMutexFlagName[2];
 
70
      break;
 
71
    case (S_MUTEX_FLAG_LAST):
 
72
      return SMutexFlagName[3];
 
73
      break;
 
74
    default:
 
75
      return NULL;
 
76
  }
 
77
}
59
78
 
60
79
SMutex *
61
80
s_mutex_new () {
140
159
SThreadStatus
141
160
s_thread_run (SThread * self, spointer user_data) {
142
161
  if (atomic_load(&(self->is_running)) == TRUE ) {
143
 
    s_warn_print ("Trying to run a thread that allready is running."
 
162
    s_err_print ("Trying to run a thread that allready is running."
144
163
                  "Returning.\n");
145
164
    return S_THREAD_STATUS_ERROR;
146
165
  }
151
170
void
152
171
s_thread_stop (SThread * self, sint res) {
153
172
  if (!thrd_equal (self->thread, thrd_current ())) {
154
 
    s_warn_print ("Trying to exit thread that is not owned by current thread.\n"
 
173
    s_err_print ("Trying to exit thread that is not owned by current thread.\n"
155
174
                  "Can only be called from running thread.\n");
156
175
    return;
157
176
  }
 
177
  atomic_store (&(self->is_running), FALSE);
158
178
  thrd_exit (res);
159
 
  
160
 
  atomic_store (&(self->is_running), FALSE);
161
179
}
162
180
 
163
181
 
 
182