1 // Copyright 2010-2021 Espressif Systems (Shanghai) CO LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <pthread.h>
16 #include <time.h>
17 #include <assert.h>
18 #include <stdint.h>
19 #include "esp_log_private.h"
20 
21 static pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
22 
esp_log_impl_lock(void)23 void esp_log_impl_lock(void)
24 {
25     assert(pthread_mutex_lock(&mutex1) == 0);
26 }
27 
esp_log_impl_lock_timeout(void)28 bool esp_log_impl_lock_timeout(void)
29 {
30     esp_log_impl_lock();
31     return true;
32 }
33 
esp_log_impl_unlock(void)34 void esp_log_impl_unlock(void)
35 {
36     assert(pthread_mutex_unlock(&mutex1) == 0);
37 }
38 
esp_log_timestamp(void)39 uint32_t esp_log_timestamp(void)
40 {
41     struct timespec current_time;
42     int result = clock_gettime(CLOCK_MONOTONIC, &current_time);
43     assert(result == 0);
44     uint32_t milliseconds = current_time.tv_sec * 1000 + current_time.tv_nsec / 1000000;
45     return milliseconds;
46 }
47