Skip to content

Commit 2af8d2d

Browse files
committed
Updates
1 parent 5aae2ef commit 2af8d2d

5 files changed

Lines changed: 77 additions & 49 deletions

File tree

features/features_cpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ retro_time_t cpu_features_get_time_usec(void)
225225

226226
if (!QueryPerformanceCounter(&count))
227227
return 0;
228-
return count.QuadPart * 1000000 / freq.QuadPart;
228+
return (count.QuadPart / freq.QuadPart * 1000000) + (count.QuadPart % freq.QuadPart * 1000000 / freq.QuadPart);
229229
#elif defined(__CELLOS_LV2__)
230230
return sys_time_get_system_time();
231231
#elif defined(GEKKO)

hash/rhash.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,22 @@ uint32_t crc32_calculate(const uint8_t *data, size_t length)
307307
/* Define the circular shift macro */
308308
#define SHA1CircularShift(bits,word) ((((word) << (bits)) & 0xFFFFFFFF) | ((word) >> (32-(bits))))
309309

310-
static void SHA1Reset(SHA1Context *context)
310+
struct sha1_context
311+
{
312+
unsigned Message_Digest[5]; /* Message Digest (output) */
313+
314+
unsigned Length_Low; /* Message length in bits */
315+
unsigned Length_High; /* Message length in bits */
316+
317+
unsigned char Message_Block[64]; /* 512-bit message blocks */
318+
int Message_Block_Index; /* Index into message block array */
319+
320+
int Computed; /* Is the digest computed? */
321+
int Corrupted; /* Is the message digest corruped? */
322+
};
323+
324+
325+
static void SHA1Reset(struct sha1_context *context)
311326
{
312327
if (!context)
313328
return;
@@ -326,7 +341,7 @@ static void SHA1Reset(SHA1Context *context)
326341
context->Corrupted = 0;
327342
}
328343

329-
static void SHA1ProcessMessageBlock(SHA1Context *context)
344+
static void SHA1ProcessMessageBlock(struct sha1_context *context)
330345
{
331346
const unsigned K[] = /* Constants defined in SHA-1 */
332347
{
@@ -418,7 +433,7 @@ static void SHA1ProcessMessageBlock(SHA1Context *context)
418433
context->Message_Block_Index = 0;
419434
}
420435

421-
static void SHA1PadMessage(SHA1Context *context)
436+
static void SHA1PadMessage(struct sha1_context *context)
422437
{
423438
if (!context)
424439
return;
@@ -455,7 +470,7 @@ static void SHA1PadMessage(SHA1Context *context)
455470
SHA1ProcessMessageBlock(context);
456471
}
457472

458-
static int SHA1Result(SHA1Context *context)
473+
static int SHA1Result(struct sha1_context *context)
459474
{
460475
if (context->Corrupted)
461476
return 0;
@@ -469,7 +484,7 @@ static int SHA1Result(SHA1Context *context)
469484
return 1;
470485
}
471486

472-
static void SHA1Input(SHA1Context *context,
487+
static void SHA1Input(struct sha1_context *context,
473488
const unsigned char *message_array,
474489
unsigned length)
475490
{
@@ -508,7 +523,7 @@ static void SHA1Input(SHA1Context *context,
508523

509524
int sha1_calculate(const char *path, char *result)
510525
{
511-
SHA1Context sha;
526+
struct sha1_context sha;
512527
unsigned char buff[4096];
513528
int rv = 1;
514529
RFILE *fd = filestream_open(path,

include/queues/task_queue.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <retro_common.h>
3131
#include <retro_common_api.h>
3232

33+
#include <libretro.h>
34+
3335
RETRO_BEGIN_DECLS
3436

3537
enum task_type
@@ -125,6 +127,9 @@ struct retro_task
125127

126128
/* don't touch this. */
127129
retro_task_t *next;
130+
131+
/* when the task should run (0 for as soon as possible) */
132+
retro_time_t when;
128133
};
129134

130135
typedef struct task_finder_data

include/rhash.h

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,8 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121
*/
2222

23-
/*
24-
* sha1.h
25-
*
26-
* Copyright (C) 1998, 2009
27-
* Paul E. Jones <[email protected]>
28-
* All Rights Reserved
29-
*
30-
*****************************************************************************
31-
* $Id: sha1.h 12 2009-06-22 19:34:25Z paulej $
32-
*****************************************************************************
33-
*
34-
* Description:
35-
* This class implements the Secure Hashing Standard as defined
36-
* in FIPS PUB 180-1 published April 17, 1995.
37-
*
38-
* Many of the variable names in the SHA1Context, especially the
39-
* single character names, were used because those were the names
40-
* used in the publication.
41-
*
42-
* Please read the file sha1.c for more information.
43-
*
44-
*/
45-
46-
#ifndef __RARCH_HASH_H
47-
#define __RARCH_HASH_H
23+
#ifndef __LIBRETRO_SDK_HASH_H
24+
#define __LIBRETRO_SDK_HASH_H
4825

4926
#include <stdint.h>
5027
#include <stddef.h>
@@ -70,20 +47,6 @@ RETRO_BEGIN_DECLS
7047
**/
7148
void sha256_hash(char *out, const uint8_t *in, size_t size);
7249

73-
typedef struct SHA1Context
74-
{
75-
unsigned Message_Digest[5]; /* Message Digest (output) */
76-
77-
unsigned Length_Low; /* Message length in bits */
78-
unsigned Length_High; /* Message length in bits */
79-
80-
unsigned char Message_Block[64]; /* 512-bit message blocks */
81-
int Message_Block_Index; /* Index into message block array */
82-
83-
int Computed; /* Is the digest computed? */
84-
int Corrupted; /* Is the message digest corruped? */
85-
} SHA1Context;
86-
8750
int sha1_calculate(const char *path, char *result);
8851

8952
uint32_t djb2_calculate(const char *str);

queues/task_queue.c

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include <queues/task_queue.h>
2828

29+
#include <features/features_cpu.h>
30+
2931
#ifdef HAVE_THREADS
3032
#include <rthreads/rthreads.h>
3133
#define SLOCK_LOCK(x) slock_lock(x)
@@ -112,7 +114,24 @@ static void task_queue_put(task_queue_t *queue, retro_task_t *task)
112114
task->next = NULL;
113115

114116
if (queue->front)
117+
{
118+
/* Make sure to insert in order - the queue is sorted by 'when' so items that aren't scheduled
119+
* to run immediately are at the back of the queue. Items with the same 'when' are inserted after
120+
* all the other items with the same 'when'. This primarily affects items with a 'when' of 0.
121+
*/
122+
if (queue->back->when > task->when)
123+
{
124+
retro_task_t** prev = &queue->front;
125+
while (*prev && (*prev)->when <= task->when)
126+
prev = &((*prev)->next);
127+
128+
task->next = *prev;
129+
*prev = task;
130+
return;
131+
}
132+
115133
queue->back->next = task;
134+
}
116135
else
117136
queue->front = task;
118137

@@ -181,9 +200,13 @@ static void retro_task_regular_gather(void)
181200
for (task = queue; task; task = next)
182201
{
183202
next = task->next;
184-
task->handler(task);
185203

186-
task_queue_push_progress(task);
204+
if (!task->when || task->when < cpu_features_get_time_usec())
205+
{
206+
task->handler(task);
207+
208+
task_queue_push_progress(task);
209+
}
187210

188211
if (task->finished)
189212
task_queue_put(&tasks_finished, task);
@@ -304,9 +327,10 @@ static void task_queue_remove(task_queue_t *queue, retro_task_t *task)
304327
{
305328
slock_lock(queue_lock);
306329
queue->front = task->next;
330+
if (queue->back == task) /* if only element, also update back */
331+
queue->back = NULL;
307332
slock_unlock(queue_lock);
308333
task->next = NULL;
309-
310334
return;
311335
}
312336

@@ -320,6 +344,15 @@ static void task_queue_remove(task_queue_t *queue, retro_task_t *task)
320344
{
321345
t->next = task->next;
322346
task->next = NULL;
347+
348+
/* When removing the tail of the queue, update the tail pointer */
349+
if (queue->back == task)
350+
{
351+
slock_lock(queue_lock);
352+
if (queue->back == task)
353+
queue->back = t;
354+
slock_unlock(queue_lock);
355+
}
323356
break;
324357
}
325358

@@ -453,6 +486,18 @@ static void threaded_worker(void *userdata)
453486
continue;
454487
}
455488

489+
if (task->when)
490+
{
491+
retro_time_t now = cpu_features_get_time_usec();
492+
retro_time_t delay = task->when - now - 500; /* allow half a millisecond for context switching */
493+
if (delay > 0)
494+
{
495+
scond_wait_timeout(worker_cond, running_lock, delay);
496+
slock_unlock(running_lock);
497+
continue;
498+
}
499+
}
500+
456501
slock_unlock(running_lock);
457502

458503
task->handler(task);

0 commit comments

Comments
 (0)