TinySTM  1.0.5
stm.h
Go to the documentation of this file.
1 /*
2  * File:
3  * stm.h
4  * Author(s):
5  * Pascal Felber <pascal.felber@unine.ch>
6  * Patrick Marlier <patrick.marlier@unine.ch>
7  * Description:
8  * STM functions.
9  *
10  * Copyright (c) 2007-2014.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation, version 2
15  * of the License.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * This program has a dual license and can also be distributed
23  * under the terms of the MIT license.
24  */
25 
75 #ifndef _STM_H_
76 # define _STM_H_
77 
78 # include <setjmp.h>
79 # include <stdint.h>
80 # include <stdio.h>
81 # include <stdlib.h>
82 
86 # define STM_VERSION "1.0.5"
87 
90 # define STM_VERSION_NB 105
91 
95 # ifdef __i386__
96 /* The fastcall calling convention improves performance on old ia32
97  * architecture that does not implement store forwarding.
98  * regparm(3) does not improve significantly the performance. */
99 # define _CALLCONV __attribute__((fastcall))
100 # else
101 # define _CALLCONV
102 # endif /* __i386__ */
103 
104 # ifdef __cplusplus
105 extern "C" {
106 # endif
107 
108 struct stm_tx;
118 struct stm_tx *stm_current_tx(void) _CALLCONV;
119 
120 /* ################################################################### *
121  * TYPES
122  * ################################################################### */
123 
128 typedef uintptr_t stm_word_t;
129 
133 typedef union stm_tx_attr {
134  struct {
142  unsigned int id : 16;
151  unsigned int read_only : 1;
160  unsigned int visible_reads : 1;
166  unsigned int no_retry : 1;
171  unsigned int no_extend : 1;
178  /* unsigned int irrevocable : 2; */
179  };
184  int32_t attrs;
185 } stm_tx_attr_t;
186 
191 enum {
204  STM_ABORT_EXPLICIT = (1 << 5),
208  STM_ABORT_NO_RETRY = (1 << 5) | (0x01 << 8),
212  STM_ABORT_IMPLICIT = (1 << 6),
217  STM_ABORT_RR_CONFLICT = (1 << 6) | (0x01 << 8),
222  STM_ABORT_RW_CONFLICT = (1 << 6) | (0x02 << 8),
227  STM_ABORT_WR_CONFLICT = (1 << 6) | (0x03 << 8),
232  STM_ABORT_WW_CONFLICT = (1 << 6) | (0x04 << 8),
236  STM_ABORT_VAL_READ = (1 << 6) | (0x05 << 8),
240  STM_ABORT_VAL_WRITE = (1 << 6) | (0x06 << 8),
244  STM_ABORT_VALIDATE = (1 << 6) | (0x07 << 8),
248  STM_ABORT_IRREVOCABLE = (1 << 6) | (0x09 << 8),
252  STM_ABORT_KILLED = (1 << 6) | (0x0A << 8),
256  STM_ABORT_SIGNAL = (1 << 6) | (0x0B << 8),
260  STM_ABORT_EXTEND_WS = (1 << 6) | (0x0C << 8),
264  STM_ABORT_OTHER = (1 << 6) | (0x0F << 8)
265 };
266 
267 /* ################################################################### *
268  * FUNCTIONS
269  * ################################################################### */
270 
276 void stm_init(void) _CALLCONV;
277 
282 void stm_exit(void) _CALLCONV;
283 
289 struct stm_tx *stm_init_thread(void) _CALLCONV;
290 
292 
296 void stm_exit_thread(void) _CALLCONV;
297 void stm_exit_thread_tx(struct stm_tx *tx) _CALLCONV;
299 
301 
316 sigjmp_buf *stm_start(stm_tx_attr_t attr) _CALLCONV;
317 sigjmp_buf *stm_start_tx(struct stm_tx *tx, stm_tx_attr_t attr) _CALLCONV;
319 
321 
330 int stm_commit(void) _CALLCONV;
331 int stm_commit_tx(struct stm_tx *tx) _CALLCONV;
333 
335 
344 void stm_abort(int abort_reason) _CALLCONV;
345 void stm_abort_tx(struct stm_tx *tx, int abort_reason) _CALLCONV;
347 
349 
361 stm_word_t stm_load(volatile stm_word_t *addr) _CALLCONV;
362 stm_word_t stm_load_tx(struct stm_tx *tx, volatile stm_word_t *addr) _CALLCONV;
364 
366 
377 void stm_store(volatile stm_word_t *addr, stm_word_t value) _CALLCONV;
378 void stm_store_tx(struct stm_tx *tx, volatile stm_word_t *addr, stm_word_t value) _CALLCONV;
380 
382 
397 void stm_store2(volatile stm_word_t *addr, stm_word_t value, stm_word_t mask) _CALLCONV;
398 void stm_store2_tx(struct stm_tx *tx, volatile stm_word_t *addr, stm_word_t value, stm_word_t mask) _CALLCONV;
400 
402 
408 int stm_active(void) _CALLCONV;
409 int stm_active_tx(struct stm_tx *tx) _CALLCONV;
411 
413 
419 int stm_aborted(void) _CALLCONV;
420 int stm_aborted_tx(struct stm_tx *tx) _CALLCONV;
422 
424 
432 int stm_irrevocable(void) _CALLCONV;
433 int stm_irrevocable_tx(struct stm_tx *tx) _CALLCONV;
435 
437 
443 int stm_killed(void) _CALLCONV;
444 int stm_killed_tx(struct stm_tx *tx) _CALLCONV;
446 
448 
460 sigjmp_buf *stm_get_env(void) _CALLCONV;
461 sigjmp_buf *stm_get_env_tx(struct stm_tx *tx) _CALLCONV;
463 
465 
473 stm_tx_attr_t stm_get_attributes(void) _CALLCONV;
474 stm_tx_attr_t stm_get_attributes_tx(struct stm_tx *tx) _CALLCONV;
476 
478 
490 int stm_get_stats(const char *name, void *val) _CALLCONV;
491 int stm_get_stats_tx(struct stm_tx *tx, const char *name, void *val) _CALLCONV;
493 
506 int stm_get_parameter(const char *name, void *val) _CALLCONV;
507 
519 int stm_set_parameter(const char *name, void *val) _CALLCONV;
520 
529 int stm_create_specific(void) _CALLCONV;
530 
532 
541 void *stm_get_specific(int key) _CALLCONV;
542 void *stm_get_specific_tx(struct stm_tx *tx, int key) _CALLCONV;
544 
546 
555 void stm_set_specific(int key, void *data) _CALLCONV;
556 void stm_set_specific_tx(struct stm_tx *tx, int key, void *data) _CALLCONV;
558 
580 int stm_register(void (*on_thread_init)(void *arg),
581  void (*on_thread_exit)(void *arg),
582  void (*on_start)(void *arg),
583  void (*on_precommit)(void *arg),
584  void (*on_commit)(void *arg),
585  void (*on_abort)(void *arg),
586  void *arg) _CALLCONV;
587 
602 stm_word_t stm_unit_load(volatile stm_word_t *addr, stm_word_t *timestamp) _CALLCONV;
603 
625 int stm_unit_store(volatile stm_word_t *addr, stm_word_t value, stm_word_t *timestamp) _CALLCONV;
626 
652 int stm_unit_store2(volatile stm_word_t *addr, stm_word_t value, stm_word_t mask, stm_word_t *timestamp) _CALLCONV;
653 
655 
669 void stm_set_extension(int enable, stm_word_t *timestamp) _CALLCONV;
670 void stm_set_extension_tx(struct stm_tx *tx, int enable, stm_word_t *timestamp) _CALLCONV;
672 
680 stm_word_t stm_get_clock(void) _CALLCONV;
681 
683 
696 int stm_set_irrevocable(int serial) _CALLCONV;
697 int stm_set_irrevocable_tx(struct stm_tx *tx, int serial) _CALLCONV;
699 
700 #ifdef HYBRID_ASF
701 
702 /* FIXME */
703 # error Hybrid is temporary disabled for code refactoring
704 
705 # ifdef EXPLICIT_TX_PARAMETER
706 # define TXTYPE struct stm_tx *
707 # define TXPARAM struct stm_tx *tx
708 # define TXPARAMS struct stm_tx *tx,
709 # define TXARG (struct stm_tx *)tx
710 # define TXARGS (struct stm_tx *)tx,
711 # else /* ! EXPLICIT_TX_PARAMETER */
712 # define TXTYPE void
713 # define TXPARAM /* Nothing */
714 # define TXPARAMS /* Nothing */
715 # define TXARG /* Nothing */
716 # define TXARGS /* Nothing */
717 #endif /* ! EXPLICIT_TX_PARAMETER */
718 
734 sigjmp_buf *hytm_start(TXPARAMS stm_tx_attr_t attr);
735 
742 int hytm_commit(TXPARAM);
743 
750 void hytm_abort(TXPARAMS int abort_reason);
751 
760 stm_word_t hytm_load(TXPARAMS volatile stm_word_t *addr);
761 
770 void hytm_store(TXPARAMS volatile stm_word_t *addr, stm_word_t value);
771 
782 void hytm_store2(TXPARAMS volatile stm_word_t *addr, stm_word_t value, stm_word_t mask);
783 
799 sigjmp_buf *tm_start(TXPARAMS stm_tx_attr_t attr);
800 
807 int tm_commit(TXPARAM);
808 
815 void tm_abort(TXPARAMS int abort_reason);
816 
825 stm_word_t tm_load(TXPARAMS volatile stm_word_t *addr);
826 
835 void tm_store(TXPARAMS volatile stm_word_t *addr, stm_word_t value);
836 
847 void tm_store2(TXPARAMS volatile stm_word_t *addr, stm_word_t value, stm_word_t mask);
848 
855 int tm_hybrid(TXPARAM);
856 
861 void tm_restart_software(TXPARAM);
862 #endif /* HYBRID_ASF */
863 
864 #ifdef __cplusplus
865 }
866 #endif
867 
868 #endif /* _STM_H_ */