This commit is contained in:
twinaphex 2019-07-17 23:16:25 +02:00
parent ff2f2222e5
commit 4c276feb4a
3 changed files with 31 additions and 4 deletions

View File

@ -131,6 +131,15 @@ void slock_free(slock_t *lock);
**/
void slock_lock(slock_t *lock);
/**
* slock_try_lock:
* @lock : pointer to mutex object
*
* Attempts to lock a mutex. If a mutex is already locked by
* another thread, return false. If the lock is acquired, return true.
**/
bool slock_try_lock(slock_t *lock);
/**
* slock_unlock:
* @lock : pointer to mutex object

View File

@ -385,6 +385,24 @@ void slock_lock(slock_t *lock)
#endif
}
/**
* slock_try_lock:
* @lock : pointer to mutex object
*
* Attempts to lock a mutex. If a mutex is already locked by
* another thread, return false. If the lock is acquired, return true.
**/
bool slock_try_lock(slock_t *lock)
{
if (!lock)
return false;
#ifdef USE_WIN32_THREADS
return TryEnterCriticalSection(&lock->lock);
#else
return pthread_mutex_trylock(&lock->lock)==0;
#endif
}
/**
* slock_unlock:
* @lock : pointer to mutex object

View File

@ -204,9 +204,9 @@ int filestream_getc(RFILE *stream)
{
char c = 0;
if (!stream)
return 0;
if(filestream_read(stream, &c, 1) == 1)
return (int)c;
return EOF;
if (filestream_read(stream, &c, 1) == 1)
return (int)(unsigned char)c;
return EOF;
}
@ -427,7 +427,7 @@ int filestream_putc(RFILE *stream, int c)
char c_char = (char)c;
if (!stream)
return EOF;
return filestream_write(stream, &c_char, 1)==1 ? c : EOF;
return filestream_write(stream, &c_char, 1)==1 ? (int)(unsigned char)c : EOF;
}
int filestream_vprintf(RFILE *stream, const char* format, va_list args)