/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: 2017-01-24 20:55:19 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20170124205519-gtr18o3dwbunrrnx
* Fixed the tests in the CMake file
* Made doxygen output static declarations.
* Started work on SApplication
* Played with BaseN.c
  * Now it is a lil' bit better
* Spilt defs.h
  * Added types.h
    * Started work on the full typesystem.
      (Still needs testing)
  * Added primes.[c,h]
    * Contains some static array with primes.
      ("Good" primes, and all primes up to 5 000.
    * And helper functions related to Primes (Needs Tests).
* fixed s_dynamic_array_dump_array.
  (The old version did not make much sense)
* removed some functions from DymanicArray.c
* fixed compiler warnings in Mainloop.c
* removed s_map_(de)serialize_json functions.
* Made s_thread_status_get_name be less prone to error
  (This due to the C11 standard not specifing what these
   values should be)
* fixed s_thread_run
* fixed s_threa_stop

  TODO:
* Write tests for the s_prime_* functions
* Write tests for the s_type_* functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
char *
24
24
s_thread_status_get_name (SThreadStatus status) {
25
 
  return SThreadStatusName[status];
 
25
  switch (status) {
 
26
    case (S_THREAD_STATUS_SUCCESS):
 
27
      return SThreadStatusName[1];
 
28
      break;
 
29
    case (S_THREAD_STATUS_TIMEOUT):
 
30
      return SThreadStatusName[2];
 
31
      break;
 
32
    case (S_THREAD_STATUS_ERROR):
 
33
      return SThreadStatusName[3];
 
34
      break;
 
35
    case (S_THREAD_STATUS_BUSY):
 
36
      return SThreadStatusName[4];
 
37
      break;
 
38
    case (S_THREAD_STATUS_NO_MEM):
 
39
      return SThreadStatusName[5];
 
40
      break;
 
41
    case (S_THREAD_STATUS_LAST):
 
42
      return SThreadStatusName[6];
 
43
      break;
 
44
    default:
 
45
      return NULL;
 
46
  }
 
47
  
26
48
}
27
49
 
28
50
/* ****************************************************************************
115
137
  s_free (self);
116
138
}
117
139
 
118
 
sboolean
 
140
SThreadStatus
119
141
s_thread_run (SThread * self, spointer user_data) {
 
142
  if (atomic_load(&(self->is_running)) == TRUE ) {
 
143
    s_warn_print ("Trying to run a thread that allready is running."
 
144
                  "Returning.\n");
 
145
    return S_THREAD_STATUS_ERROR;
 
146
  }
 
147
  atomic_store(&(self->is_running), TRUE);
120
148
  return thrd_create ((thrd_t *)self, (thrd_start_t)self->func, user_data);
121
 
  atomic_store(&(self->is_running), TRUE);
122
 
}
 
149
}
 
150
 
 
151
void
 
152
s_thread_stop (SThread * self, sint res) {
 
153
  if (!thrd_equal (self->thread, thrd_current ())) {
 
154
    s_warn_print ("Trying to exit thread that is not owned by current thread.\n"
 
155
                  "Can only be called from running thread.\n");
 
156
    return;
 
157
  }
 
158
  thrd_exit (res);
 
159
  
 
160
  atomic_store (&(self->is_running), FALSE);
 
161
}
 
162
 
 
163