/src/libhevc/encoder/osal_thread.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2018 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | |
21 | | /*****************************************************************************/ |
22 | | /* */ |
23 | | /* File Name : osal_thread.c */ |
24 | | /* */ |
25 | | /* Description : This file contains Thread API's implemented for */ |
26 | | /* different platforms. */ |
27 | | /* */ |
28 | | /* List of Functions : osal_thread_create */ |
29 | | /* osal_thread_destroy */ |
30 | | /* osal_func */ |
31 | | /* osal_set_thread_priority */ |
32 | | /* osal_set_thread_core_affinity */ |
33 | | /* osal_thread_sleep */ |
34 | | /* osal_thread_yield */ |
35 | | /* osal_thread_suspend */ |
36 | | /* osal_thread_resume */ |
37 | | /* osal_thread_wait */ |
38 | | /* osal_get_thread_handle */ |
39 | | /* osal_get_time */ |
40 | | /* osal_get_time_usec */ |
41 | | /* osal_get_last_error */ |
42 | | /* osal_print_last_error */ |
43 | | /* */ |
44 | | /* Issues / Problems : None */ |
45 | | /* */ |
46 | | /* Revision History : */ |
47 | | /* */ |
48 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
49 | | /* 06 03 2006 Ittiam Draft */ |
50 | | /* */ |
51 | | /*****************************************************************************/ |
52 | | |
53 | | /*****************************************************************************/ |
54 | | /* File Includes */ |
55 | | /*****************************************************************************/ |
56 | | |
57 | | /* System include files */ |
58 | | #include <stdio.h> |
59 | | |
60 | | #include <semaphore.h> |
61 | | #include <pthread.h> |
62 | | #include <errno.h> |
63 | | #include <sys/time.h> |
64 | | #include <sys/resource.h> |
65 | | |
66 | | #include <unistd.h> |
67 | | #include <math.h> |
68 | | #include <sched.h> /*for CPU_SET, etc.. */ |
69 | | #ifndef DARWIN |
70 | | #include<linux/unistd.h> |
71 | | #endif |
72 | | #include <sys/syscall.h> |
73 | | |
74 | | /* User include files */ |
75 | | #include "cast_types.h" |
76 | | #include "osal.h" |
77 | | #include "osal_handle.h" |
78 | | #include "osal_thread.h" |
79 | | #include "osal_errno.h" |
80 | | |
81 | | /*****************************************************************************/ |
82 | | /* Static Function Declarations */ |
83 | | /*****************************************************************************/ |
84 | | |
85 | | static void osal_func(void *param); |
86 | | |
87 | | /*****************************************************************************/ |
88 | | /* */ |
89 | | /* Function Name : osal_thread_create */ |
90 | | /* */ |
91 | | /* Description : This function create a new thread. */ |
92 | | /* */ |
93 | | /* Inputs : OSAL handle */ |
94 | | /* Memory Manager Handle */ |
95 | | /* Thread creation attributes */ |
96 | | /* */ |
97 | | /* Globals : None */ |
98 | | /* */ |
99 | | /* Processing : This function calls OS specific thread create API's and */ |
100 | | /* creates a new thread with specified attributes. */ |
101 | | /* */ |
102 | | /* Outputs : Status of thread creation */ |
103 | | /* */ |
104 | | /* Returns : On SUCCESS - 0 */ |
105 | | /* On FAILURE - -1 */ |
106 | | /* */ |
107 | | /* Issues : Only supports creating threads with default attributes */ |
108 | | /* */ |
109 | | /* Revision History: */ |
110 | | /* */ |
111 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
112 | | /* 06 03 2006 Ittiam Draft */ |
113 | | /* */ |
114 | | /*****************************************************************************/ |
115 | | |
116 | | void *osal_thread_create(IN void *osal_handle, IN osal_thread_attr_t *attr) |
117 | 35.6k | { |
118 | 35.6k | osal_t *handle = (osal_t *)osal_handle; |
119 | 35.6k | WORD32 priority = 0; |
120 | 35.6k | void *mmr_handle = 0; |
121 | | |
122 | | /* If Handle or attributes are not valid, return ERRORED. */ |
123 | 35.6k | if(0 == attr) |
124 | 0 | return 0; |
125 | | |
126 | 35.6k | if(0 == handle || 0 == handle->alloc || 0 == handle->free) |
127 | 0 | return 0; |
128 | | |
129 | | /* Initialize MMR handle */ |
130 | 35.6k | mmr_handle = handle->mmr_handle; |
131 | | |
132 | 35.6k | { |
133 | 35.6k | pthread_attr_t tattr; |
134 | 35.6k | thread_handle_t *hdl = 0; |
135 | | |
136 | 35.6k | attr->sched_policy = OSAL_SCHED_RR; |
137 | | |
138 | | /* Allocate memory for thread handle */ |
139 | 35.6k | hdl = handle->alloc(mmr_handle, sizeof(thread_handle_t)); |
140 | 35.6k | if(0 == hdl) |
141 | 0 | return 0; |
142 | | |
143 | | /* Initialize thread handle parameters */ |
144 | 35.6k | hdl->mmr_handle = mmr_handle; |
145 | 35.6k | hdl->hdl = handle; |
146 | 35.6k | hdl->exit_code = attr->exit_code; |
147 | 35.6k | hdl->priority = priority; |
148 | 35.6k | hdl->thread_func = attr->thread_func; |
149 | 35.6k | hdl->thread_param = attr->thread_param; |
150 | | |
151 | | /* initialized with default attributes */ |
152 | 35.6k | if(0 != pthread_attr_init(&tattr)) |
153 | 0 | { |
154 | 0 | handle->free(hdl->mmr_handle, hdl); |
155 | 0 | return 0; |
156 | 0 | } |
157 | | |
158 | | /* Create the thread */ |
159 | 35.6k | hdl->thread_id = pthread_create( |
160 | 35.6k | &(hdl->thread_handle), /* Thread Handle */ |
161 | 35.6k | &tattr, /* Attributes */ |
162 | 35.6k | (void *(*)(void *))osal_func, |
163 | 35.6k | hdl); /* Parameters */ |
164 | | |
165 | | /* In case of error in thread creationn, Free the handle memory and */ |
166 | | /* return error. */ |
167 | 35.6k | if(0 != hdl->thread_id) |
168 | 0 | { |
169 | 0 | handle->free(hdl->mmr_handle, hdl); |
170 | 0 | return 0; |
171 | 0 | } |
172 | | |
173 | 35.6k | pthread_attr_destroy(&tattr); |
174 | | |
175 | 35.6k | return hdl; |
176 | 35.6k | } |
177 | 35.6k | } |
178 | | |
179 | | /*****************************************************************************/ |
180 | | /* */ |
181 | | /* Function Name : osal_thread_destroy */ |
182 | | /* */ |
183 | | /* Description : This function calls OS specific API's to close a thread */ |
184 | | /* which is represented by specified handle. */ |
185 | | /* */ |
186 | | /* Inputs : Initialized thread handle */ |
187 | | /* */ |
188 | | /* Globals : None */ |
189 | | /* */ |
190 | | /* Processing : Closing other threads is supported only in windows. So, */ |
191 | | /* only windows platform supports this API. */ |
192 | | /* */ |
193 | | /* Outputs : Status of thread close */ |
194 | | /* */ |
195 | | /* Returns : On SUCCESS - 0 */ |
196 | | /* On FAILURE - -1 */ |
197 | | /* */ |
198 | | /* Issues : None */ |
199 | | /* */ |
200 | | /* Revision History: */ |
201 | | /* */ |
202 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
203 | | /* 06 03 2006 Ittiam Draft */ |
204 | | /* */ |
205 | | /*****************************************************************************/ |
206 | | |
207 | | WORD32 osal_thread_destroy(IN void *thread_handle) |
208 | 35.6k | { |
209 | | /* If thread handle is not valid, return error */ |
210 | 35.6k | if(0 == thread_handle) |
211 | 0 | return OSAL_ERROR; |
212 | | |
213 | 35.6k | { |
214 | 35.6k | thread_handle_t *hdl = (thread_handle_t *)thread_handle; |
215 | | |
216 | | /* Free memory allocated for Thread handle */ |
217 | 35.6k | ((osal_t *)hdl->hdl)->free(hdl->mmr_handle, hdl); |
218 | | |
219 | 35.6k | return OSAL_SUCCESS; |
220 | 35.6k | } |
221 | 35.6k | } |
222 | | |
223 | | /*****************************************************************************/ |
224 | | /* */ |
225 | | /* Function Name : osal_func */ |
226 | | /* */ |
227 | | /* Description : This function calls the registered threads calling */ |
228 | | /* function */ |
229 | | /* */ |
230 | | /* Inputs : Thread Handle */ |
231 | | /* */ |
232 | | /* Globals : None */ |
233 | | /* */ |
234 | | /* Processing : Calls each registered thread function */ |
235 | | /* */ |
236 | | /* Outputs : None */ |
237 | | /* Returns : None */ |
238 | | /* */ |
239 | | /* Issues : None */ |
240 | | /* */ |
241 | | /* Revision History: */ |
242 | | /* */ |
243 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
244 | | /* 10 05 2006 Ittiam Draft */ |
245 | | /* */ |
246 | | /*****************************************************************************/ |
247 | | |
248 | | void osal_func(IN void *param) |
249 | 35.6k | { |
250 | 35.6k | thread_handle_t *hdl = (thread_handle_t *)param; |
251 | | |
252 | 35.6k | while(1) |
253 | 35.6k | { |
254 | | /* Untill thread returns exit code, invoke the thread function */ |
255 | 35.6k | if(hdl->exit_code == hdl->thread_func(hdl->thread_param)) |
256 | 35.6k | break; |
257 | 35.6k | } |
258 | | |
259 | | /* On Linux platforms call pthread_exit() to release all the resources */ |
260 | | /* allocated. */ |
261 | 35.6k | pthread_exit(NULL); |
262 | 35.6k | } |
263 | | |
264 | | /*****************************************************************************/ |
265 | | /* */ |
266 | | /* Function Name : osal_thread_sleep */ |
267 | | /* */ |
268 | | /* Description : This function calls OS specific API and makes thread */ |
269 | | /* sleep for specified number of milli seconds. */ |
270 | | /* */ |
271 | | /* Inputs : Initialized thread handle */ |
272 | | /* Time to sleep in millisceonds */ |
273 | | /* */ |
274 | | /* Globals : None */ |
275 | | /* */ |
276 | | /* Processing : Calls API to sleep for specified number of milli seconds */ |
277 | | /* */ |
278 | | /* Outputs : Status of sleep */ |
279 | | /* */ |
280 | | /* Returns : On SUCCESS - 0 */ |
281 | | /* On FAILURE - -1 */ |
282 | | /* */ |
283 | | /* Issues : None */ |
284 | | /* */ |
285 | | /* Revision History: */ |
286 | | /* */ |
287 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
288 | | /* 06 03 2006 Ittiam Draft */ |
289 | | /* */ |
290 | | /*****************************************************************************/ |
291 | | |
292 | | WORD32 osal_thread_sleep(IN UWORD32 milli_seconds) |
293 | 0 | { |
294 | 0 | { |
295 | 0 | struct timespec timer; |
296 | | |
297 | | /* Convert time in milliseconds into seconds and nano seconds */ |
298 | 0 | timer.tv_sec = milli_seconds / 1000; |
299 | 0 | milli_seconds -= (timer.tv_sec * 1000); |
300 | 0 | timer.tv_nsec = milli_seconds * MEGA_CONST; |
301 | | #ifdef DARWIN |
302 | | if(0 == nanosleep(&timer, NULL)) |
303 | | { |
304 | | return OSAL_SUCCESS; |
305 | | } |
306 | | #else |
307 | | /* Using Monotonic clock to sleep, also flag is set to 0 for relative */ |
308 | | /* time to current clock time */ |
309 | 0 | if(0 == clock_nanosleep(CLOCK_MONOTONIC, 0, &timer, NULL)) |
310 | 0 | { |
311 | 0 | return OSAL_SUCCESS; |
312 | 0 | } |
313 | 0 | #endif |
314 | 0 | return OSAL_ERROR; |
315 | 0 | } |
316 | 0 | } |
317 | | |
318 | | /*****************************************************************************/ |
319 | | /* */ |
320 | | /* Function Name : osal_thread_yield */ |
321 | | /* */ |
322 | | /* Description : This function causes the yield its execution. */ |
323 | | /* */ |
324 | | /* Inputs : Thread Handle */ |
325 | | /* */ |
326 | | /* Globals : None */ |
327 | | /* */ |
328 | | /* Processing : Calls OS specific yield calls. */ |
329 | | /* */ |
330 | | /* Outputs : Status of Thread Yield */ |
331 | | /* */ |
332 | | /* Returns : On SUCCESS - 0 */ |
333 | | /* On FAILURE - -1 */ |
334 | | /* */ |
335 | | /* Issues : Yield in WIN32 (whihc is a 16 - bit API) is still present*/ |
336 | | /* only to maintian backward compatibility. Can get */ |
337 | | /* deprecated in future. */ |
338 | | /* */ |
339 | | /* Revision History: */ |
340 | | /* */ |
341 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
342 | | /* 06 03 2006 Ittiam Draft */ |
343 | | /* */ |
344 | | /*****************************************************************************/ |
345 | | |
346 | | WORD32 osal_thread_yield() |
347 | 0 | { |
348 | 0 | if(0 == sched_yield()) |
349 | 0 | return OSAL_SUCCESS; |
350 | | |
351 | 0 | return OSAL_ERROR; |
352 | 0 | } |
353 | | |
354 | | /*****************************************************************************/ |
355 | | /* */ |
356 | | /* Function Name : osal_thread_suspend */ |
357 | | /* */ |
358 | | /* Description : This function causes the suspension its execution. */ |
359 | | /* */ |
360 | | /* Inputs : Thread Handle */ |
361 | | /* */ |
362 | | /* Globals : None */ |
363 | | /* */ |
364 | | /* Processing : Calls OS specific suspend calls. */ |
365 | | /* */ |
366 | | /* Outputs : Status of Thread Suspend */ |
367 | | /* */ |
368 | | /* Returns : On SUCCESS - 0 */ |
369 | | /* On FAILURE - -1 */ |
370 | | /* */ |
371 | | /* Issues : API not supported in Redhat Linux. Refer Redhat */ |
372 | | /* documentation in: */ |
373 | | /* http://www.redhat.com/docs/wp/solaris_port/c1347.html */ |
374 | | /* */ |
375 | | /* Revision History: */ |
376 | | /* */ |
377 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
378 | | /* 30 03 2006 Ittiam Draft */ |
379 | | /* */ |
380 | | /*****************************************************************************/ |
381 | | |
382 | | WORD32 osal_thread_suspend(IN void *thread_handle) |
383 | 0 | { |
384 | | /* If thread handle is not valid, return error */ |
385 | 0 | if(0 == thread_handle) |
386 | 0 | return OSAL_ERROR; |
387 | | |
388 | 0 | { |
389 | | /* Thread suspend are not supported in Redhat Linux. Refer link */ |
390 | | /* http://www.redhat.com/docs/wp/solaris_port/c1347.html */ |
391 | |
|
392 | 0 | return OSAL_NOT_SUPPORTED; |
393 | 0 | } |
394 | 0 | } |
395 | | |
396 | | /*****************************************************************************/ |
397 | | /* */ |
398 | | /* Function Name : osal_thread_resume */ |
399 | | /* */ |
400 | | /* Description : This function causes the resumption its execution. */ |
401 | | /* */ |
402 | | /* Inputs : Thread Handle */ |
403 | | /* */ |
404 | | /* Globals : None */ |
405 | | /* */ |
406 | | /* Processing : Calls OS specific resume calls. */ |
407 | | /* */ |
408 | | /* Outputs : Status of Thread Suspend */ |
409 | | /* */ |
410 | | /* Returns : On SUCCESS - 0 */ |
411 | | /* On FAILURE - -1 */ |
412 | | /* */ |
413 | | /* Issues : API not supported in Redhat Linux. Refer Redhat */ |
414 | | /* documentation in: */ |
415 | | /* http://www.redhat.com/docs/wp/solaris_port/c1347.html */ |
416 | | /* */ |
417 | | /* Revision History: */ |
418 | | /* */ |
419 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
420 | | /* 30 03 2006 Ittiam Draft */ |
421 | | /* */ |
422 | | /*****************************************************************************/ |
423 | | |
424 | | WORD32 osal_thread_resume(IN void *thread_handle) |
425 | 0 | { |
426 | | /* If thread handle is not valid, return error */ |
427 | 0 | if(0 == thread_handle) |
428 | 0 | return OSAL_ERROR; |
429 | | |
430 | 0 | { |
431 | | /* Thread suspend are not supported in Redhat Linux. Refer link */ |
432 | | /* http://www.redhat.com/docs/wp/solaris_port/c1347.html */ |
433 | |
|
434 | 0 | return OSAL_NOT_SUPPORTED; |
435 | 0 | } |
436 | 0 | } |
437 | | |
438 | | /*****************************************************************************/ |
439 | | /* */ |
440 | | /* Function Name : osal_thread_wait */ |
441 | | /* */ |
442 | | /* Description : This function causes the wait untill called thread */ |
443 | | /* finishes execution */ |
444 | | /* */ |
445 | | /* Inputs : Thread Handle */ |
446 | | /* */ |
447 | | /* Globals : None */ |
448 | | /* */ |
449 | | /* Processing : Calls OS specific wait call for wait on another thread */ |
450 | | /* */ |
451 | | /* Outputs : Status of Thread wait */ |
452 | | /* */ |
453 | | /* Returns : On SUCCESS - 0 */ |
454 | | /* On FAILURE - -1 */ |
455 | | /* */ |
456 | | /* Issues : None */ |
457 | | /* */ |
458 | | /* Revision History: */ |
459 | | /* */ |
460 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
461 | | /* 30 03 2006 Ittiam Draft */ |
462 | | /* */ |
463 | | /*****************************************************************************/ |
464 | | |
465 | | WORD32 osal_thread_wait(IN void *thread_handle) |
466 | 35.6k | { |
467 | 35.6k | if(0 == thread_handle) |
468 | 0 | return OSAL_ERROR; |
469 | | |
470 | 35.6k | { |
471 | 35.6k | WORD32 result = 0; |
472 | 35.6k | void *status = 0; |
473 | | |
474 | 35.6k | thread_handle_t *hdl = (thread_handle_t *)thread_handle; |
475 | | |
476 | | /* Join the thread to wait for thread to complete execution */ |
477 | 35.6k | result = pthread_join(hdl->thread_handle, (void **)&status); |
478 | | |
479 | 35.6k | return result; |
480 | 35.6k | } |
481 | 35.6k | } |
482 | | |
483 | | /*****************************************************************************/ |
484 | | /* */ |
485 | | /* Function Name : osal_get_thread_handle */ |
486 | | /* */ |
487 | | /* Description : This function gets current thread handle. Currently not */ |
488 | | /* supported */ |
489 | | /* */ |
490 | | /* Inputs : OSAL handle. */ |
491 | | /* */ |
492 | | /* Globals : None */ |
493 | | /* */ |
494 | | /* Processing : Gets all the thread properities and constructs a new */ |
495 | | /* thread handle . */ |
496 | | /* */ |
497 | | /* Outputs : Thread handle to current thread. */ |
498 | | /* */ |
499 | | /* Returns : On SUCCESS - Current thread handle */ |
500 | | /* On FAILURE - NULL */ |
501 | | /* */ |
502 | | /* Issues : Not supported on Linux and BIOS platforms. */ |
503 | | /* */ |
504 | | /* Revision History: */ |
505 | | /* */ |
506 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
507 | | /* 10 05 2006 Ittiam Draft */ |
508 | | /* */ |
509 | | /*****************************************************************************/ |
510 | | |
511 | | void *osal_get_thread_handle(IN void *osal_handle) |
512 | 0 | { |
513 | 0 | osal_t *handle = (osal_t *)osal_handle; |
514 | |
|
515 | 0 | if(0 == osal_handle) |
516 | 0 | return 0; |
517 | | |
518 | 0 | { |
519 | 0 | thread_handle_t *hdl = handle->alloc(handle->mmr_handle, sizeof(thread_handle_t)); |
520 | 0 | WORD32 schedpolicy; |
521 | 0 | struct sched_param schedparam; |
522 | |
|
523 | 0 | if(0 == hdl) |
524 | 0 | return 0; |
525 | | |
526 | 0 | hdl->mmr_handle = handle->mmr_handle; |
527 | 0 | hdl->hdl = handle; |
528 | 0 | hdl->exit_code = 0; |
529 | 0 | hdl->thread_func = 0; |
530 | 0 | hdl->thread_param = 0; |
531 | 0 | hdl->thread_handle = pthread_self(); |
532 | 0 | hdl->thread_id = 0; |
533 | 0 | hdl->priority = schedparam.sched_priority; |
534 | | |
535 | | /* Get thread priority from scheduling parameters */ |
536 | 0 | if(0 != pthread_getschedparam(hdl->thread_handle, &schedpolicy, &schedparam)) |
537 | 0 | { |
538 | 0 | return 0; |
539 | 0 | } |
540 | | |
541 | 0 | return hdl; |
542 | 0 | } |
543 | 0 | } |
544 | | |
545 | | /*****************************************************************************/ |
546 | | /* */ |
547 | | /* Function Name : osal_get_time */ |
548 | | /* */ |
549 | | /* Description : This function returns absolute time in milli seconds */ |
550 | | /* */ |
551 | | /* Inputs : None */ |
552 | | /* Globals : None */ |
553 | | /* */ |
554 | | /* Processing : Gets the absolute time by calling OS specific API's. */ |
555 | | /* */ |
556 | | /* Outputs : Absolute time in milli seconds. */ |
557 | | /* */ |
558 | | /* Returns : +ve 32 bit value */ |
559 | | /* */ |
560 | | /* Issues : None */ |
561 | | /* */ |
562 | | /* Revision History: */ |
563 | | /* */ |
564 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
565 | | /* 06 03 2006 Ittiam Draft */ |
566 | | /* */ |
567 | | /*****************************************************************************/ |
568 | | |
569 | | UWORD32 osal_get_time() |
570 | 0 | { |
571 | 0 | { |
572 | 0 | struct timespec time_val; |
573 | 0 | int cur_time; |
574 | | |
575 | | /* Get the Monotonic time */ |
576 | 0 | clock_gettime(CLOCK_MONOTONIC, &time_val); |
577 | | |
578 | | /* Convert time in seconds and micro seconds into milliseconds time */ |
579 | 0 | cur_time = time_val.tv_sec * 1000 + time_val.tv_nsec / 1000000; |
580 | 0 | return cur_time; |
581 | 0 | } |
582 | 0 | } |
583 | | |
584 | | /*****************************************************************************/ |
585 | | /* */ |
586 | | /* Function Name : osal_get_time_usec */ |
587 | | /* */ |
588 | | /* Description : This function returns absolute time in micro seconds */ |
589 | | /* */ |
590 | | /* Inputs : None */ |
591 | | /* Globals : None */ |
592 | | /* */ |
593 | | /* Processing : Gets the absolute time by calling OS specific API's. */ |
594 | | /* */ |
595 | | /* Outputs : Absolute time in micro seconds. */ |
596 | | /* */ |
597 | | /* Returns : +ve 32 bit value */ |
598 | | /* */ |
599 | | /* Issues : None */ |
600 | | /* */ |
601 | | /* Revision History: */ |
602 | | /* */ |
603 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
604 | | /* 06 03 2009 Ittiam Draft */ |
605 | | /* */ |
606 | | /*****************************************************************************/ |
607 | | |
608 | | WORD32 osal_get_time_usec(UWORD32 *sec, UWORD32 *usec) |
609 | 0 | { |
610 | 0 | if((0 == sec) || (0 == usec)) |
611 | 0 | return OSAL_ERROR; |
612 | | |
613 | 0 | { |
614 | 0 | struct timespec time_val; |
615 | | |
616 | | /* Get the Monotonic time */ |
617 | 0 | clock_gettime(CLOCK_MONOTONIC, &time_val); |
618 | | |
619 | | /* Convert time in seconds and micro seconds into milliseconds time */ |
620 | 0 | *sec = time_val.tv_sec; |
621 | 0 | *usec = time_val.tv_nsec / 1000; |
622 | |
|
623 | 0 | return OSAL_SUCCESS; |
624 | 0 | } |
625 | 0 | } |
626 | | |
627 | | /*****************************************************************************/ |
628 | | /* */ |
629 | | /* Function Name : osal_get_last_error */ |
630 | | /* */ |
631 | | /* Description : This function gets the last error code. */ |
632 | | /* */ |
633 | | /* Inputs : None */ |
634 | | /* Globals : None */ |
635 | | /* */ |
636 | | /* Processing : Gets the last occured error code by calling OS specific */ |
637 | | /* API call. */ |
638 | | /* */ |
639 | | /* Outputs : Error Number */ |
640 | | /* */ |
641 | | /* Returns : If no error - 0 */ |
642 | | /* Else - +ve number */ |
643 | | /* */ |
644 | | /* Issues : None */ |
645 | | /* */ |
646 | | /* Revision History: */ |
647 | | /* */ |
648 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
649 | | /* 06 03 2006 Ittiam Draft */ |
650 | | /* */ |
651 | | /*****************************************************************************/ |
652 | | |
653 | | UWORD32 osal_get_last_error() |
654 | 0 | { |
655 | 0 | UWORD32 get_linux_error(void); |
656 | 0 | return get_linux_error(); |
657 | 0 | } |
658 | | |
659 | | /*****************************************************************************/ |
660 | | /* */ |
661 | | /* Function Name : osal_print_last_error */ |
662 | | /* */ |
663 | | /* Description : This function prints the last error message. */ |
664 | | /* */ |
665 | | /* Inputs : None */ |
666 | | /* Globals : None */ |
667 | | /* */ |
668 | | /* Processing : Gets the last occured error code by calling OS specific */ |
669 | | /* API call. It prints argument string (if not NULL), */ |
670 | | /* followed by ': ' then the error_string and <new_line>. */ |
671 | | /* */ |
672 | | /* Outputs : None */ |
673 | | /* */ |
674 | | /* Returns : None */ |
675 | | /* */ |
676 | | /* Issues : None */ |
677 | | /* */ |
678 | | /* Revision History: */ |
679 | | /* */ |
680 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
681 | | /* 10 03 2006 Ittiam Draft */ |
682 | | /* */ |
683 | | /*****************************************************************************/ |
684 | | |
685 | | void osal_print_last_error(IN const STRWORD8 *string) |
686 | 0 | { |
687 | 0 | perror(string); |
688 | 0 | } |
689 | | |
690 | | /*****************************************************************************/ |
691 | | /* */ |
692 | | /* Function Name : osal_get_current_tid */ |
693 | | /* */ |
694 | | /* Description : Gets the tid of the thread in whose context this call */ |
695 | | /* was made */ |
696 | | /* */ |
697 | | /* Inputs : None */ |
698 | | /* Globals : None */ |
699 | | /* Processing : None */ |
700 | | /* Outputs : None */ |
701 | | /* Returns : Thread ID, as a WORD32 */ |
702 | | /* Issues : None */ |
703 | | /* */ |
704 | | /* Revision History: */ |
705 | | /* */ |
706 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
707 | | /* 07 05 2015 Ittiam Draft */ |
708 | | /* */ |
709 | | /*****************************************************************************/ |
710 | | |
711 | | WORD32 osal_get_current_tid(void) |
712 | 0 | { |
713 | | #ifdef DARWIN |
714 | | uint64_t tid; |
715 | | pthread_threadid_np(NULL, &tid); |
716 | | return tid; |
717 | | #else |
718 | 0 | return syscall(__NR_gettid); |
719 | 0 | #endif |
720 | 0 | } |